3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "ytstandardfeed.h"
22 #include "networkaccess.h"
27 #include "yt3listparser.h"
29 #include "ytfeedreader.h"
33 NetworkAccess* http();
36 YTStandardFeed::YTStandardFeed(QObject *parent)
37 : PaginatedVideoSource(parent),
42 void YTStandardFeed::loadVideos(int max, int startIndex) {
45 QUrl url = YT3::instance().method("videos");
47 #if QT_VERSION >= 0x050000
54 if (maybeReloadToken(max, startIndex)) return;
55 url.addQueryItem("pageToken", nextPageToken);
58 url.addQueryItem("part", "snippet,contentDetails,statistics");
59 url.addQueryItem("chart", "mostPopular");
61 if (!category.isEmpty())
62 url.addQueryItem("videoCategoryId", category);
64 if (!regionId.isEmpty())
65 url.addQueryItem("regionCode", regionId);
67 url.addQueryItem("maxResults", QString::number(max));
69 #if QT_VERSION >= 0x050000
73 QObject *reply = The::http()->get(url);
74 connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
75 connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*)));
78 void YTStandardFeed::parseResults(QByteArray data) {
81 YT3ListParser parser(data);
82 QList<Video*> videos = parser.getVideos();
84 bool tryingWithNewToken = setPageToken(parser.getNextPageToken());
85 if (tryingWithNewToken) return;
88 reloadingToken = false;
89 loadVideos(currentMax, currentStartIndex);
90 currentMax = currentStartIndex = 0;
94 emit gotVideos(videos);
95 emit finished(videos.size());
100 void YTStandardFeed::loadVideos(int max, int startIndex) {
103 QString s = "http://gdata.youtube.com/feeds/api/standardfeeds/";
104 if (!regionId.isEmpty()) s += regionId + "/";
106 if (!category.isEmpty()) s += "_" + category;
109 #if QT_VERSION >= 0x050000
114 url.addQueryItem("v", "2");
116 if (feedId != "most_shared" && feedId != "on_the_web") {
118 if (t.isEmpty()) t = "today";
119 url.addQueryItem("time", t);
122 url.addQueryItem("max-results", QString::number(max));
123 url.addQueryItem("start-index", QString::number(startIndex));
125 #if QT_VERSION >= 0x050000
129 QObject *reply = The::http()->get(url);
130 connect(reply, SIGNAL(data(QByteArray)), SLOT(parse(QByteArray)));
131 connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*)));
134 void YTStandardFeed::parseResults(QByteArray data) {
137 YTFeedReader reader(data);
138 QList<Video*> videos = reader.getVideos();
140 emit gotVideos(videos);
141 emit finished(videos.size());
146 void YTStandardFeed::abort() {
150 const QStringList & YTStandardFeed::getSuggestions() {
151 QStringList *l = new QStringList();
155 void YTStandardFeed::requestError(QNetworkReply *reply) {
156 emit error(reply->errorString());