]> git.sur5r.net Git - minitube/commitdiff
2.1.2 stuff 2.1.2
authorFlavio <flavio@odisseo.local>
Fri, 23 Aug 2013 15:02:12 +0000 (17:02 +0200)
committerFlavio <flavio@odisseo.local>
Fri, 23 Aug 2013 15:02:12 +0000 (17:02 +0200)
CHANGES
minitube.pro
src/jsfunctions.cpp
src/jsfunctions.h
src/mainwindow.cpp
src/mediaview.cpp
src/networkaccess.cpp
src/video.cpp
src/video.h
src/ytfeedreader.cpp

diff --git a/CHANGES b/CHANGES
index f0f85805ea25704328b646a6a779495f6be6ea95..8d9e12856dc99e130f2daaf7501504755e40de2b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+2.1.2
+- Downloads only enabled on Creative Commons licensed videos
+- Fixed playback of some videos
+
 2.1.1
 - Fixed VEVO videos playback
 - Fixed Ubuntu skin not being used
index d0be3cc6d4bc8e7ca24a51f2ab9fe20f23012028..532c28a5cbb02b93697b5a2b398f069802b8960d 100644 (file)
@@ -1,6 +1,6 @@
 CONFIG += release
 TEMPLATE = app
-VERSION = 2.1.1
+VERSION = 2.1.2
 DEFINES += APP_VERSION="$$VERSION"
 
 APP_NAME = Minitube
index 53742249e35ff03dbf0688ddaac7441ecdb0decf..45070f1e2497c466a42563c0213c1db2cafb0a04 100644 (file)
@@ -40,7 +40,7 @@ JsFunctions::JsFunctions(QObject *parent) : QObject(parent), engine(0) {
         else
             qWarning() << file.errorString() << file.fileName();
         QFileInfo info(file);
-        if (info.lastModified().toTime_t() < QDateTime::currentDateTime().toTime_t() - 86400)
+        if (info.lastModified().toTime_t() < QDateTime::currentDateTime().toTime_t() - 3600)
             loadJs();
     } else {
         QFile resFile(QLatin1String(":/") + jsFilename());
@@ -95,9 +95,16 @@ QString JsFunctions::evaluateFunction(const QString &function) {
     QScriptValue value = engine->evaluate(function);
     if (value.isUndefined())
         qWarning() << "Undefined result for" << function;
+    if (value.isError())
+        qWarning() << "Error in" << function << value.toString();
+
     return value.toString();
 }
 
 QString JsFunctions::decryptSignature(const QString &s) {
     return evaluateFunction("decryptSignature('" + s + "')");
 }
+
+QString JsFunctions::decryptAgeSignature(const QString &s) {
+    return evaluateFunction("decryptAgeSignature('" + s + "')");
+}
index 0f8ff21be335a908cb212fb73cf20407e7b61d92..31d7aac345e9cb1b03717608165c1e4ce20dbc3c 100644 (file)
@@ -32,6 +32,7 @@ class JsFunctions : public QObject {
 public:
     static JsFunctions* instance();
     QString decryptSignature(const QString &s);
+    QString decryptAgeSignature(const QString &s);
 
 private slots:
     void gotJs(QByteArray bytes);
index 913da2f06a747aff1ffbdb5dcb6d78e7a75c97ec..3ae36bd8c7e3236922837aa7e967506806c72daa 100644 (file)
@@ -467,11 +467,10 @@ void MainWindow::createActions() {
 
     action = new QAction(tr("&Download"), this);
     action->setStatusTip(tr("Download the current video"));
-#ifndef APP_NO_DOWNLOADS
     action->setShortcut(QKeySequence::Save);
-#endif
     action->setIcon(Utils::icon("document-save"));
     action->setEnabled(false);
+    action->setVisible(false);
     action->setPriority(QAction::LowPriority);
     connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo()));
     actions->insert("download", action);
@@ -628,11 +627,9 @@ void MainWindow::createMenus() {
     videoMenu->addAction(webPageAct);
     videoMenu->addSeparator();
     videoMenu->addAction(The::globalActions()->value("subscribe-channel"));
-#ifndef APP_NO_DOWNLOADS
     videoMenu->addSeparator();
     videoMenu->addAction(The::globalActions()->value("download"));
-    // videoMenu->addAction(copyLinkAct);
-#endif
+    videoMenu->addAction(copyLinkAct);
     // videoMenu->addAction(The::globalActions()->value("snapshot"));
 
     QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
@@ -683,9 +680,7 @@ void MainWindow::createToolBars() {
     mainToolBar->addAction(skipAct);
 
     mainToolBar->addAction(The::globalActions()->value("related-videos"));
-#ifndef APP_NO_DOWNLOADS
     mainToolBar->addAction(The::globalActions()->value("download"));
-#endif
 
     bool addFullScreenAct = true;
 #ifdef Q_WS_MAC
index 1217e3033cd19b9ba512632b619122b4930c3619..9f5aafa03c1184aeedfd6bc30b0a68fb961e6ade 100644 (file)
@@ -145,7 +145,7 @@ void MediaView::initialize() {
             << The::globalActions()->value("findVideoParts")
             << The::globalActions()->value("skip")
             << The::globalActions()->value("previous")
-            << The::globalActions()->value("download")
+            // << The::globalActions()->value("download")
             << The::globalActions()->value("stopafterthis")
             << The::globalActions()->value("related-videos")
             << The::globalActions()->value("refine-search")
@@ -342,6 +342,10 @@ void MediaView::stop() {
     foreach (QAction *action, currentVideoActions)
         action->setEnabled(false);
 
+    QAction *a = The::globalActions()->value("download");
+    a->setEnabled(false);
+    a->setVisible(false);
+
     mediaObject->stop();
     currentVideoId.clear();
 }
@@ -390,6 +394,20 @@ void MediaView::activeRowChanged(int row) {
     The::globalActions()->value("previous")->setEnabled(row > 0);
     The::globalActions()->value("stopafterthis")->setEnabled(true);
     The::globalActions()->value("related-videos")->setEnabled(true);
+
+#ifndef APP_NO_DOWNLOADS
+    bool enableDownload = video->license() == Video::LicenseCC;
+#ifdef APP_ACTIVATION
+    enableDownload = enableDownload || Activation::instance().isLegacy();
+#endif
+#ifdef APP_DOWNLOADS
+    enableDownload = true;
+#endif
+    QAction *a = The::globalActions()->value("download");
+    a->setEnabled(enableDownload);
+    a->setVisible(enableDownload);
+#endif
+
     updateSubscriptionAction(video, YTUser::isSubscribed(video->userId()));
 
     foreach (QAction *action, currentVideoActions)
@@ -400,6 +418,10 @@ void MediaView::activeRowChanged(int row) {
 
 void MediaView::gotStreamUrl(QUrl streamUrl) {
     if (stopped) return;
+    if (!streamUrl.isValid()) {
+        skip();
+        return;
+    }
 
     Video *video = static_cast<Video *>(sender());
     if (!video) {
index b7fc872e18fc70a308d7275964815f5396ce075d..96132c997b47c054b84297e03988cbe205cdf66c 100644 (file)
@@ -32,7 +32,7 @@ const QString USER_AGENT = QString(Constants::NAME)
                            + " (" + Constants::WEBSITE + ")";
 */
 
-const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31";
+const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36";
 
 NetworkReply::NetworkReply(QNetworkReply *networkReply) :
     QObject(networkReply),
index 027ee1ff53e04e4f84981fb005092466d8dc809c..8cb1f97e03b309b00d2d1817f7f95c04801ac0f1 100644 (file)
@@ -32,7 +32,10 @@ Video::Video() : m_duration(0),
     m_viewCount(-1),
     definitionCode(0),
     elIndex(0),
-    loadingStreamUrl(false)
+    ageGate(false),
+    m_license(LicenseYouTube),
+    loadingStreamUrl(false),
+    loadingThumbnail(false)
 { }
 
 Video* Video::clone() {
@@ -64,7 +67,7 @@ void Video::setWebpage(QUrl webpage) {
     QRegExp re("^https?://www\\.youtube\\.com/watch\\?v=([0-9A-Za-z_-]+).*");
     bool match = re.exactMatch(m_webpage.toString());
     if (!match || re.numCaptures() < 1) {
-        qDebug() << QString("Cannot get video id for %1").arg(m_webpage.toString());
+        qWarning() << QString("Cannot get video id for %1").arg(m_webpage.toString());
         // emit errorStreamUrl(QString("Cannot get video id for %1").arg(m_webpage.toString()));
         // loadingStreamUrl = false;
         return;
@@ -73,11 +76,14 @@ void Video::setWebpage(QUrl webpage) {
 }
 
 void Video::loadThumbnail() {
+    if (m_thumbnailUrl.isEmpty() || loadingThumbnail) return;
+    loadingThumbnail = true;
     QObject *reply = The::http()->get(m_thumbnailUrl);
     connect(reply, SIGNAL(data(QByteArray)), SLOT(setThumbnail(QByteArray)));
 }
 
 void Video::setThumbnail(QByteArray bytes) {
+    loadingThumbnail = false;
     m_thumbnail.loadFromData(bytes);
     if (m_thumbnail.width() > 160)
         m_thumbnail = m_thumbnail.scaledToWidth(160, Qt::SmoothTransformation);
@@ -97,6 +103,7 @@ void Video::loadStreamUrl() {
     }
     loadingStreamUrl = true;
     elIndex = 0;
+    ageGate = false;
 
     getVideoInfo();
 }
@@ -107,6 +114,7 @@ void  Video::getVideoInfo() {
     QUrl videoInfoUrl;
 
     if (elIndex == elTypes.size()) {
+        // qDebug() << "Trying special embedded el param";
         videoInfoUrl = QUrl("http://www.youtube.com/get_video_info");
         videoInfoUrl.addQueryItem("video_id", videoId);
         videoInfoUrl.addQueryItem("el", "embedded");
@@ -116,19 +124,12 @@ void  Video::getVideoInfo() {
         videoInfoUrl.addQueryItem("asv", "3");
         videoInfoUrl.addQueryItem("sts", "1588");
     } else if (elIndex > elTypes.size() - 1) {
+        qWarning() << "Cannot get video info";
         loadingStreamUrl = false;
         emit errorStreamUrl("Cannot get video info");
-        /*
-        // Don't panic! We have a plan B.
-        // get the youtube video webpage
-        qDebug() << "Scraping" << webpage().toString();
-        QObject *reply = The::http()->get(webpage().toString());
-        connect(reply, SIGNAL(data(QByteArray)), SLOT(scrapeWebPage(QByteArray)));
-        connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*)));
-        // see you in scrapWebPage(QByteArray)
-        */
         return;
     } else {
+        // qDebug() << "Trying el param:" << elTypes.at(elIndex) << elIndex;
         videoInfoUrl = QUrl(QString(
                                 "http://www.youtube.com/get_video_info?video_id=%1%2&ps=default&eurl=&gl=US&hl=en"
                                 ).arg(videoId, elTypes.at(elIndex)));
@@ -150,6 +151,7 @@ void  Video::gotVideoInfo(QByteArray data) {
     bool match = re.exactMatch(videoInfo);
     // handle regexp failure
     if (!match || re.numCaptures() < 1) {
+        // qDebug() << "Cannot get token. Trying next el param";
         // Don't panic! We're gonna try another magic "el" param
         elIndex++;
         getVideoInfo();
@@ -167,12 +169,15 @@ void  Video::gotVideoInfo(QByteArray data) {
     match = re.exactMatch(videoInfo);
     // handle regexp failure
     if (!match || re.numCaptures() < 1) {
+        // qDebug() << "Cannot get urlMap. Trying next el param";
         // Don't panic! We're gonna try another magic "el" param
         elIndex++;
         getVideoInfo();
         return;
     }
 
+    // qDebug() << "Got token and urlMap" << elIndex;
+
     QString fmtUrlMap = re.cap(1);
     fmtUrlMap = QByteArray::fromPercentEncoding(fmtUrlMap.toUtf8());
     parseFmtUrlMap(fmtUrlMap);
@@ -208,13 +213,22 @@ void Video::parseFmtUrlMap(QString fmtUrlMap, bool fromWebPage) {
                 sig = urlParam.mid(separator + 1);
                 sig = QByteArray::fromPercentEncoding(sig.toUtf8());
             } else if (urlParam.startsWith("s=")) {
-                if (fromWebPage || elIndex == 4) {
+                if (fromWebPage || ageGate) {
                     int separator = urlParam.indexOf("=");
                     sig = urlParam.mid(separator + 1);
                     sig = QByteArray::fromPercentEncoding(sig.toUtf8());
-                    sig = JsFunctions::instance()->decryptSignature(sig);
+                    if (ageGate)
+                        sig = JsFunctions::instance()->decryptAgeSignature(sig);
+                    else
+                        sig = JsFunctions::instance()->decryptSignature(sig);
                 } else {
-                    QObject *reply = The::http()->get(m_webpage);
+                    // qDebug() << "Loading webpage";
+                    QUrl url("http://www.youtube.com/watch");
+                    url.addQueryItem("v", videoId);
+                    url.addQueryItem("gl", "US");
+                    url.addQueryItem("hl", "en");
+                    url.addQueryItem("has_verified", "1");
+                    QObject *reply = The::http()->get(url);
                     connect(reply, SIGNAL(data(QByteArray)), SLOT(scrapeWebPage(QByteArray)));
                     connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*)));
                     // see you in scrapWebPage(QByteArray)
@@ -229,6 +243,8 @@ void Video::parseFmtUrlMap(QString fmtUrlMap, bool fromWebPage) {
         if (!url.contains("ratebypass"))
             url += "&ratebypass=yes";
 
+        // qWarning() << url;
+
         if (format == definitionCode) {
             // qDebug() << "Found format" << definitionCode;
             QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode);
@@ -284,9 +300,18 @@ void Video::errorVideoInfo(QNetworkReply *reply) {
 
 void Video::scrapeWebPage(QByteArray data) {
     QString html = QString::fromUtf8(data);
-    QRegExp re(".*\"url_encoded_fmt_stream_map\": \"([^\"]+)\".*");
-    bool match = re.exactMatch(html);
+    // qWarning() << html;
+
+    if (html.contains("player-age-gate-content\"")) {
+        // qDebug() << "Found ageGate";
+        ageGate = true;
+        elIndex = 4;
+        getVideoInfo();
+        return;
+    }
 
+    QRegExp re(".*\"url_encoded_fmt_stream_map\":\\s+\"([^\"]+)\".*");
+    bool match = re.exactMatch(html);
     // on regexp failure, stop and report error
     if (!match || re.numCaptures() < 1) {
         qWarning() << "Error parsing video page";
@@ -296,7 +321,6 @@ void Video::scrapeWebPage(QByteArray data) {
         getVideoInfo();
         return;
     }
-
     QString fmtUrlMap = re.cap(1);
     fmtUrlMap.replace("\\u0026", "&");
     parseFmtUrlMap(fmtUrlMap, true);
index 5e8580ae1408bba82d59fe818f560e99d7804f09..76a9f58798f2a8e7878afec3be6328f0625a5388 100644 (file)
@@ -32,6 +32,11 @@ public:
     Video();
     Video* clone();
 
+    enum License {
+        LicenseYouTube = 1,
+        LicenseCC
+    };
+
     const QString & title() const { return m_title; }
     void setTitle( QString title ) { m_title = title; }
 
@@ -75,6 +80,9 @@ public:
     void setId(QString id) { videoId = id; }
     const QString & id() const { return videoId; }
 
+    void setLicense(License license) { m_license = license; }
+    License license() const { return m_license; }
+
 signals:
     void gotThumbnail();
     void gotMediumThumbnail(QByteArray bytes);
@@ -106,7 +114,7 @@ private:
     int m_duration;
     QDateTime m_published;
     int m_viewCount;
-
+    License m_license;
     QString videoId;
     QString videoToken;
     int definitionCode;
@@ -114,8 +122,10 @@ private:
     // current index for the elTypes list
     // needed to iterate on elTypes
     int elIndex;
+    bool ageGate;
     
     bool loadingStreamUrl;
+    bool loadingThumbnail;
 };
 
 // This is required in order to use QPointer<Video> as a QVariant
index 975e327a569c4360f462be23af18372f4c517d27..9aaacf0a1d1209b678dec7d1270aa3d8b7430ac5 100644 (file)
@@ -106,6 +106,12 @@ void YTFeedReader::readEntry() {
                             // qDebug() << "Duration: " << duration;
                             video->setDuration(duration.toInt());
                         }
+                        else if (name() == QLatin1String("license")) {
+                            QString license = readElementText();
+                            // qDebug() << "License: " << license;
+                            if (license == QLatin1String("cc"))
+                                video->setLicense(Video::LicenseCC);
+                        }
                     }
                 }
             }