From: Flavio Date: Fri, 10 Dec 2010 10:05:36 +0000 (+0100) Subject: Fixed after YouTube changes X-Git-Tag: 1.3~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d87c7a197ada8c94ba8c7d94233acde76706f0bf;p=minitube Fixed after YouTube changes --- diff --git a/src/video.cpp b/src/video.cpp index 35e8371..7b7a803 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -102,6 +102,8 @@ void Video::getVideoInfo() { void Video::gotVideoInfo(QByteArray data) { QString videoInfo = QString::fromUtf8(data); + // qDebug() << "videoInfo" << videoInfo; + // get video token QRegExp re = QRegExp("^.*&token=([^&]+).*$"); bool match = re.exactMatch(videoInfo); @@ -118,7 +120,6 @@ void Video::gotVideoInfo(QByteArray data) { // qDebug() << "videoToken" << videoToken; this->videoToken = videoToken; - /* // get fmt_url_map re = QRegExp("^.*&fmt_url_map=([^&]+).*$"); match = re.exactMatch(videoInfo); @@ -129,32 +130,54 @@ void Video::gotVideoInfo(QByteArray data) { getVideoInfo(); return; } + QString fmtUrlMap = re.cap(1); + fmtUrlMap = QByteArray::fromPercentEncoding(fmtUrlMap.toUtf8()); - while (fmtUrlMap.contains('%')) - fmtUrlMap = QByteArray::fromPercentEncoding(fmtUrlMap.toAscii()); + QSettings settings; + QString definitionName = settings.value("definition").toString(); + int definitionCode = VideoDefinition::getDefinitionCode(definitionName); - qDebug() << "fmtUrlMap" << fmtUrlMap; + // qDebug() << "fmtUrlMap" << fmtUrlMap; QStringList formatUrls = fmtUrlMap.split(",", QString::SkipEmptyParts); + QHash urlMap; foreach(QString formatUrl, formatUrls) { int separator = formatUrl.indexOf("|"); if (separator == -1) continue; int format = formatUrl.left(separator).toInt(); QString url = formatUrl.mid(separator + 1); - qDebug() << format << url; + + if (format == definitionCode) { + QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode); + m_streamUrl = videoUrl; + emit gotStreamUrl(videoUrl); + loadingStreamUrl = false; + return; + } + + urlMap.insert(format, url); } - */ - QSettings settings; - QString definitionName = settings.value("definition").toString(); - int definitionCode = VideoDefinition::getDefinitionCode(definitionName); - if (definitionCode == 18) { - // This is assumed always available - foundVideoUrl(videoToken, 18); - } else { - findVideoUrl(definitionCode); + QList definitionCodes = VideoDefinition::getDefinitionCodes(); + int currentIndex = definitionCodes.indexOf(definitionCode); + int previousIndex = 0; + while (currentIndex >= 0) { + previousIndex = currentIndex - 1; + int definitionCode = definitionCodes.at(previousIndex); + if (urlMap.contains(definitionCode)) { + qDebug() << "Found format" << definitionCode; + QString url = urlMap.value(definitionCode); + QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode); + m_streamUrl = videoUrl; + emit gotStreamUrl(videoUrl); + loadingStreamUrl = false; + return; + } + currentIndex--; } + emit errorStreamUrl(tr("Cannot get video stream for %1").arg(m_webpage.toString())); + } void Video::foundVideoUrl(QString videoToken, int definitionCode) {