Add debug to stream fetching

This commit is contained in:
craig.p.drummond
2013-07-07 19:46:19 +00:00
committed by craig.p.drummond
parent a4f010bfe9
commit 8ee84a88f2
4 changed files with 32 additions and 1 deletions

1
README
View File

@@ -466,6 +466,7 @@ The following debug values may be used:
Context widget 64
Context backdrop 128
Dynamic 256
Stream Fetching 512
These values may be combined to enable multipe output. e.g. to enable MPD and
covers logging:

View File

@@ -50,6 +50,7 @@
#include "coverwidget.h"
#include "backdropcreator.h"
#include "dynamic.h"
#include "streamfetcher.h"
#ifndef ENABLE_KDE_SUPPORT
// Taken from Clementine!
@@ -104,7 +105,8 @@ enum Debug {
Dbg_Context_Meta = 0x0020,
Dbg_Context_Widget = 0x0040,
Dbg_Context_Backdrop = 0x0080,
Dbg_Dynamic = 0x0100
Dbg_Dynamic = 0x0100,
Dbg_StreamFetching = 0x0200
};
int main(int argc, char *argv[])
@@ -139,6 +141,9 @@ int main(int argc, char *argv[])
if (dbg&Dbg_Dynamic) {
Dynamic::enableDebug();
}
if (dbg&Dbg_StreamFetching) {
StreamFetcher::enableDebug();
}
}
#ifdef ENABLE_KDE_SUPPORT

View File

@@ -31,6 +31,14 @@
#include <QUrl>
#include <QXmlStreamReader>
#include <QDebug>
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << "StreamFetcher" << __FUNCTION__
void StreamFetcher::enableDebug()
{
debugEnabled=true;
}
static const int constMaxRedirects = 3;
static const int constMaxData = 1024;
static const int constTimeout = 3*1000;
@@ -123,21 +131,28 @@ static QString parse(const QByteArray &data)
{
QSet<QString> handlers=MPDConnection::self()->urlHandlers();
if (data.length()>10 && !strncasecmp(data.constData(), "[playlist]", 10)) {
DBUG << "playlist";
return parsePlaylist(data, QLatin1String("File"), handlers);
} else if (data.length()>7 && (!strncasecmp(data.constData(), "#EXTM3U", 7) || !strncasecmp(data.constData(), "http://", 7))) {
DBUG << "ext3mu";
return parseExt3Mu(data, handlers);
} else if (data.length()>5 && !strncasecmp(data.constData(), "<asx ", 5)) {
DBUG << "asx";
return parseAsx(data, handlers);
} else if (data.length()>11 && !strncasecmp(data.constData(), "[reference]", 11)) {
DBUG << "playlist/ref";
return parsePlaylist(data, QLatin1String("Ref"), handlers);
} else if (data.length()>5 && !strncasecmp(data.constData(), "<?xml", 5)) {
DBUG << "xml";
return parseXml(data, handlers);
} else if ( (-1==data.indexOf("<html") && -1!=data.indexOf("http:/")) || // flat list?
(-1!=data.indexOf("#EXTM3U")) ) { // m3u with comments?
DBUG << "ext3mu/2";
return parseExt3Mu(data, handlers);
} else if (data.startsWith("http://")) {
QStringList lines=QString(data).split(QRegExp(QLatin1String("(\r\n|\n|\r)")), QString::SkipEmptyParts);
if (!lines.isEmpty()) {
DBUG << "http";
return lines.first();
}
}
@@ -161,6 +176,7 @@ void StreamFetcher::get(const QStringList &items, int insertRow, bool replace, q
return;
}
DBUG << "get" << items;
cancel();
todo=items;
done.clear();
@@ -187,10 +203,12 @@ void StreamFetcher::doNext()
data.clear();
u.setScheme("http");
job=NetworkAccessManager::self()->get(u, constTimeout);
DBUG << "Check" << u.toString();
connect(job, SIGNAL(readyRead()), this, SLOT(dataReady()));
connect(job, SIGNAL(finished()), this, SLOT(jobFinished()));
return;
} else {
DBUG << "use orig" << current;
done.append(MPDParseUtils::addStreamName(current, currentName));
}
}
@@ -250,6 +268,7 @@ void StreamFetcher::jobFinished(QNetworkReply *reply)
QVariant redirect = reply->header(QNetworkRequest::LocationHeader);
if (redirect.isValid() && ++redirects<constMaxRedirects) {
current=redirect.toString();
DBUG << "real redirect" << current;
data.clear();
job=NetworkAccessManager::self()->get(current, constTimeout);
connect(job, SIGNAL(readyRead()), this, SLOT(dataReady()));
@@ -258,20 +277,24 @@ void StreamFetcher::jobFinished(QNetworkReply *reply)
} else {
QString u=parse(data);
if (u.isEmpty() || u==current) {
DBUG << "use (empty/current)" << current;
done.append(MPDParseUtils::addStreamName(current.startsWith(StreamsModel::constPrefix) ? current.mid(StreamsModel::constPrefix.length()) : current, currentName));
} else if (u.startsWith(QLatin1String("http://")) && ++redirects<constMaxRedirects) {
// Redirect...
current=u;
DBUG << "semi-redirect" << current;
data.clear();
job=NetworkAccessManager::self()->get(u, constTimeout);
connect(job, SIGNAL(readyRead()), this, SLOT(dataReady()));
connect(job, SIGNAL(finished()), this, SLOT(jobFinished()));
redirected=true;
} else {
DBUG << "use" << u;
done.append(MPDParseUtils::addStreamName(u, currentName));
}
}
} else {
DBUG << "error " << reply->errorString() << " - use" << current;
done.append(MPDParseUtils::addStreamName(current.startsWith(StreamsModel::constPrefix) ? current.mid(StreamsModel::constPrefix.length()) : current, currentName));
}

View File

@@ -36,6 +36,8 @@ class StreamFetcher : public QObject
Q_OBJECT
public:
static void enableDebug();
StreamFetcher(QObject *p);
virtual ~StreamFetcher();