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 "ytsinglevideosource.h"
23 #include "httputils.h"
27 #include "yt3listparser.h"
29 YTSingleVideoSource::YTSingleVideoSource(QObject *parent) : PaginatedVideoSource(parent),
34 void YTSingleVideoSource::loadVideos(int max, int startIndex) {
36 this->startIndex = startIndex;
41 if (startIndex == 1) {
44 QVector<Video*> videos;
45 videos << video->clone();
47 name = videos.at(0)->getTitle();
48 qDebug() << "Emitting name changed" << name;
49 emit nameChanged(name);
51 emit gotVideos(videos);
52 loadVideos(max - 1, 2);
56 url = YT3::instance().method("videos");
58 q.addQueryItem("part", "snippet");
59 q.addQueryItem("id", videoId);
63 url = YT3::instance().method("search");
65 q.addQueryItem("part", "snippet");
66 q.addQueryItem("type", "video");
67 q.addQueryItem("relatedToVideoId", videoId);
68 q.addQueryItem("maxResults", QString::number(max));
70 if (maybeReloadToken(max, startIndex)) return;
71 q.addQueryItem("pageToken", nextPageToken);
78 QObject *reply = HttpUtils::yt().get(url);
79 connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
80 connect(reply, SIGNAL(error(QString)), SLOT(requestError(QString)));
83 void YTSingleVideoSource::parseResults(QByteArray data) {
86 YT3ListParser parser(data);
87 const QVector<Video*> &videos = parser.getVideos();
89 bool tryingWithNewToken = setPageToken(parser.getNextPageToken());
90 if (tryingWithNewToken) return;
93 emit gotVideos(videos);
94 if (startIndex == 2) emit finished(videos.size() + 1);
95 else emit finished(videos.size());
97 loadVideoDetails(videos);
100 void YTSingleVideoSource::abort() {
104 QString YTSingleVideoSource::getName() {
108 void YTSingleVideoSource::setVideo(Video *video) {
110 videoId = video->getId();
113 void YTSingleVideoSource::requestError(const QString &message) {