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"
23 #include "httputils.h"
27 #include "yt3listparser.h"
29 YTStandardFeed::YTStandardFeed(QObject *parent)
30 : PaginatedVideoSource(parent),
33 void YTStandardFeed::loadVideos(int max, int startIndex) {
36 QUrl url = YT3::instance().method("videos");
40 if (maybeReloadToken(max, startIndex)) return;
41 q.addQueryItem("pageToken", nextPageToken);
44 q.addQueryItem("part", "snippet,contentDetails,statistics");
45 q.addQueryItem("chart", "mostPopular");
47 if (!category.isEmpty())
48 q.addQueryItem("videoCategoryId", category);
50 if (!regionId.isEmpty())
51 q.addQueryItem("regionCode", regionId);
53 q.addQueryItem("maxResults", QString::number(max));
57 QObject *reply = HttpUtils::yt().get(url);
59 connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
60 connect(reply, SIGNAL(error(QString)), SLOT(requestError(QString)));
63 void YTStandardFeed::parseResults(QByteArray data) {
66 YT3ListParser parser(data);
67 const QVector<Video*> &videos = parser.getVideos();
69 bool tryingWithNewToken = setPageToken(parser.getNextPageToken());
70 if (tryingWithNewToken) return;
73 reloadingToken = false;
74 loadVideos(currentMax, currentStartIndex);
75 currentMax = currentStartIndex = 0;
79 emit gotVideos(videos);
80 emit finished(videos.size());
83 void YTStandardFeed::abort() {
87 void YTStandardFeed::requestError(const QString &message) {