static const QStringList elTypes = QStringList() << "&el=embedded" << "&el=vevo" << "&el=detailpage" << "";
if (elIndex > elTypes.size() - 1) {
+ 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();
connect(reply, SIGNAL(data(QByteArray)), SLOT(scrapeWebPage(QByteArray)));
connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*)));
// see you in scrapWebPage(QByteArray)
+ */
return;
}
this->videoToken = videoToken;
// get fmt_url_map
- re = QRegExp("^.*&fmt_url_map=([^&]+).*$");
+ re = QRegExp("^.*&url_encoded_fmt_stream_map=([^&]+).*$");
match = re.exactMatch(videoInfo);
// handle regexp failure
if (!match || re.numCaptures() < 1) {
QStringList formatUrls = fmtUrlMap.split(",", QString::SkipEmptyParts);
QHash<int, QString> 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() << "formatUrl" << formatUrl;
+ QStringList urlParams = formatUrl.split("&", QString::SkipEmptyParts);
+ // qDebug() << "urlParams" << urlParams;
+
+ int format = -1;
+ QString url;
+ foreach(QString urlParam, urlParams) {
+ if (urlParam.startsWith("itag=")) {
+ int separator = urlParam.indexOf("=");
+ format = urlParam.mid(separator + 1).toInt();
+ } else if (urlParam.startsWith("url=")) {
+ int separator = urlParam.indexOf("=");
+ url = urlParam.mid(separator + 1);
+ url = QByteArray::fromPercentEncoding(url.toUtf8());
+ }
+ }
+ if (format == -1 || url.isNull()) continue;
if (format == definitionCode) {
+ qDebug() << "Found format" << definitionCode;
QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode);
m_streamUrl = videoUrl;
+ this->definitionCode = definitionCode;
emit gotStreamUrl(videoUrl);
loadingStreamUrl = false;
return;
int previousIndex = 0;
while (currentIndex >= 0) {
previousIndex = currentIndex - 1;
+ if (previousIndex < 0) previousIndex = 0;
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;
+ this->definitionCode = definitionCode;
emit gotStreamUrl(videoUrl);
loadingStreamUrl = false;
return;
).arg(videoId, videoToken, QString::number(definitionCode)));
m_streamUrl = videoUrl;
- emit gotStreamUrl(videoUrl);
loadingStreamUrl = false;
+ emit gotStreamUrl(videoUrl);
}
void Video::errorVideoInfo(QNetworkReply *reply) {
- emit errorStreamUrl(tr("Network error: %1 for %2").arg(reply->errorString(), reply->url().toString()));
loadingStreamUrl = false;
+ emit errorStreamUrl(tr("Network error: %1 for %2").arg(reply->errorString(), reply->url().toString()));
}
void Video::scrapeWebPage(QByteArray data) {