]> git.sur5r.net Git - minitube/commitdiff
When a video token cannot be obtained from the getInfo YT service,
authorFlavio Tordini <flavio.tordini@gmail.com>
Sun, 11 Oct 2009 20:50:36 +0000 (22:50 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Sun, 11 Oct 2009 20:50:36 +0000 (22:50 +0200)
fallback to scraping the webpage.

src/video.cpp
src/video.h

index 0fb30b3cbb6b4d65ee22a39b94c5e7f3b3efb767..3345445fb8f4f1f1b67438e477566de8e2abc0be 100644 (file)
@@ -65,6 +65,17 @@ void  Video::gotVideoInfo(QByteArray data) {
 
     // on regexp failure, stop and report error
     if (!match || re.numCaptures() < 1) {
+
+        // Don't panic! We have a plan B.
+
+        // get the youtube video webpage
+        QObject *reply = The::http()->get(webpage().toString());
+        connect(reply, SIGNAL(data(QByteArray)), SLOT(scrapWebPage(QByteArray)));
+        connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*)));
+
+        // see you in scrapWebPage(QByteArray)
+
+        /*
         qDebug() << videoInfo;
         re = QRegExp("^.*&reason=([^&]+).*$");
         match = re.exactMatch(videoInfo);
@@ -78,8 +89,11 @@ void  Video::gotVideoInfo(QByteArray data) {
             }
             if (mainWindow) mainWindow->statusBar()->showMessage(errorMessage);
             emit errorStreamUrl(errorMessage);
+
         } else
             emit errorStreamUrl("Error parsing video info");
+        */
+
         return;
     }
 
@@ -101,3 +115,31 @@ void  Video::gotVideoInfo(QByteArray data) {
 void Video::errorVideoInfo(QNetworkReply *reply) {
     emit errorStreamUrl(tr("Network error: %1 for %2").arg(reply->errorString(), reply->url().toString()));
 }
+
+void Video::scrapWebPage(QByteArray data) {
+
+    QString videoHTML = QString::fromUtf8(data);
+    QRegExp re(".*, \"t\": \"([^\"]+)\".*");
+    bool match = re.exactMatch(videoHTML);
+
+    // on regexp failure, stop and report error
+    if (!match || re.numCaptures() < 1) {
+        emit errorStreamUrl("Error parsing video page");
+        return;
+    }
+
+    QString videoToken = re.cap(1);
+    // FIXME proper decode
+    videoToken = videoToken.replace("%3D", "=");
+    qDebug() << "token" << videoToken;
+
+    QUrl videoUrl = QUrl(QString("http://www.youtube.com/get_video?video_id=")
+                         .append(videoId)
+                         .append("&t=").append(videoToken)
+                         .append("&eurl=&el=detailpage&ps=default&fmt=18"));
+
+    m_streamUrl = videoUrl;
+
+    emit gotStreamUrl(videoUrl);
+
+}
index 974f49bead06f07789414ba90bb28940183da49b..bdd555eafde382795556459fd62240df6a913a80 100644 (file)
@@ -57,6 +57,7 @@ signals:
 private slots:
     void gotVideoInfo(QByteArray);
     void errorVideoInfo(QNetworkReply*);
+    void scrapWebPage(QByteArray);
 
 private:
     void scrapeStreamUrl();