// 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
void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected);
void activeRowChanged(int);
void selectVideos(QList<Video*> 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();
// 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;
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<QMainWindow*>(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", "=");