From: Flavio Tordini Date: Thu, 23 Jul 2009 23:13:20 +0000 (+0200) Subject: new error signal when stream url cannot be determined X-Git-Tag: 0.5~19 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b1aa2329390ae3e7eed84ee210be5d1a76d30a8b;p=minitube new error signal when stream url cannot be determined This makes the playlist skip to the next video --- diff --git a/src/MediaView.cpp b/src/MediaView.cpp index bd3eb7a..45282b8 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -194,6 +194,8 @@ void MediaView::activeRowChanged(int row) { // mediaObject->pause(); connect(video, SIGNAL(gotStreamUrl(QUrl)), SLOT(gotStreamUrl(QUrl))); + // TODO handle signal in a proper slot and impl item error status + connect(video, SIGNAL(errorStreamUrl()), SLOT(skip())); video->loadStreamUrl(); // reset the timer flag diff --git a/src/MediaView.h b/src/MediaView.h index 0419cb8..a4a8996 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -53,12 +53,12 @@ private slots: void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected); void activeRowChanged(int); void selectVideos(QList videos); + void gotStreamUrl(QUrl streamUrl); // phonon void stateChanged(Phonon::State newState, Phonon::State oldState); void aboutToFinish(); void currentSourceChanged(const Phonon::MediaSource source); void showVideoContextMenu(QPoint point); - void gotStreamUrl(QUrl streamUrl); // bar void searchMostRelevant(); void searchMostRecent(); diff --git a/src/video.cpp b/src/video.cpp index 0e8d860..1ac9871 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -38,7 +38,10 @@ void Video::scrapeStreamUrl() { // QRegExp re("^((?:http://)?(?:\\w+\\.)?youtube\\.com/(?:(?:v/)|(?:(?:watch(?:\\.php)?)?\\?(?:.+&)?v=)))?([0-9A-Za-z_-]+)(?(1).+)?$"); QRegExp re("^http://www\\.youtube\\.com/watch\\?v=([0-9A-Za-z_-]+)$"); bool match = re.exactMatch(webpage.toString()); - // if (!match || re.numCaptures() < 1) return false; + if (!match || re.numCaptures() < 1) { + emit errorStreamUrl(); + return; + } videoId = re.cap(1); // if (!videoId) return false; // qDebug() << videoId; @@ -55,10 +58,29 @@ void Video::scrapeStreamUrl() { void Video::gotVideoInfo(QByteArray data) { QString videoInfo = QString::fromUtf8(data); - // qDebug() << videoInfo; + QRegExp re = QRegExp("^.*&token=([^&]+).*$"); bool match = re.exactMatch(videoInfo); - if (!match || re.numCaptures() < 1) return; + + // on regexp failure, stop and report error + if (!match || re.numCaptures() < 1) { + qDebug() << videoInfo; + re = QRegExp("^.*&reason=([^&]+).*$"); + match = re.exactMatch(videoInfo); + if (match) { + // report the error in the status bar + QMainWindow* mainWindow = dynamic_cast(qApp->topLevelWidgets().first()); + QString errorMessage = QUrl::fromEncoded(re.cap(1).toUtf8()).toString().replace("+", " "); + int indexOfTag = errorMessage.indexOf("<"); + if (indexOfTag != -1) { + errorMessage = errorMessage.left(indexOfTag); + } + if (mainWindow) mainWindow->statusBar()->showMessage(errorMessage); + } + emit errorStreamUrl(); + return; + } + QString videoToken = re.cap(1); // FIXME proper decode videoToken = videoToken.replace("%3D", "="); diff --git a/src/video.h b/src/video.h index 81e0734..f7d9198 100644 --- a/src/video.h +++ b/src/video.h @@ -52,6 +52,7 @@ public slots: signals: void gotThumbnail(); void gotStreamUrl(QUrl streamUrl); + void errorStreamUrl(); private slots: void gotVideoInfo(QByteArray);