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 "networkaccess.h"
25 #include "ytfeedreader.h"
28 NetworkAccess* http();
31 YTSingleVideoSource::YTSingleVideoSource(QObject *parent) : VideoSource(parent) {
36 void YTSingleVideoSource::loadVideos(int max, int skip) {
42 if (skip == 1) s = "http://gdata.youtube.com/feeds/api/videos/" + videoId;
43 else s = QString("http://gdata.youtube.com/feeds/api/videos/%1/related").arg(videoId);
45 url.addQueryItem("v", "2");
48 url.addQueryItem("max-results", QString::number(max));
49 url.addQueryItem("start-index", QString::number(skip-1));
52 QObject *reply = The::http()->get(url);
53 connect(reply, SIGNAL(data(QByteArray)), SLOT(parse(QByteArray)));
54 connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*)));
57 void YTSingleVideoSource::abort() {
61 const QStringList & YTSingleVideoSource::getSuggestions() {
62 QStringList *l = new QStringList();
66 QString YTSingleVideoSource::getName() {
70 void YTSingleVideoSource::parse(QByteArray data) {
73 YTFeedReader reader(data);
74 QList<Video*> videos = reader.getVideos();
76 if (name.isEmpty() && !videos.isEmpty() && skip == 1) {
77 name = videos.first()->title();
78 emit nameChanged(name);
81 emit gotVideos(videos);
83 if (skip == 1) loadVideos(max - 1, 2);
84 else if (skip == 2) emit finished(videos.size() + 1);
85 else emit finished(videos.size());
88 void YTSingleVideoSource::requestError(QNetworkReply *reply) {
89 emit error(reply->errorString());