]> git.sur5r.net Git - minitube/blob - src/ytstandardfeed.cpp
Imported Upstream version 2.1.3
[minitube] / src / ytstandardfeed.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
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.
10
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.
15
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/>.
18
19 $END_LICENSE */
20
21 #include "ytstandardfeed.h"
22 #include <QtXml>
23 #include "networkaccess.h"
24 #include "video.h"
25 #include "ytfeedreader.h"
26
27 namespace The {
28 NetworkAccess* http();
29 }
30
31 YTStandardFeed::YTStandardFeed(QObject *parent)
32     : VideoSource(parent),
33       aborted(false) { }
34
35 void YTStandardFeed::loadVideos(int max, int skip) {
36     aborted = false;
37
38     QString s = "http://gdata.youtube.com/feeds/api/standardfeeds/";
39     if (!regionId.isEmpty()) s += regionId + "/";
40     s += feedId;
41     if (!category.isEmpty()) s += "_" + category;
42
43     QUrl url(s);
44     url.addQueryItem("v", "2");
45
46     if (feedId != "most_shared" && feedId != "on_the_web") {
47         QString t = time;
48         if (t.isEmpty()) t = "today";
49         url.addQueryItem("time", t);
50     }
51
52     url.addQueryItem("max-results", QString::number(max));
53     url.addQueryItem("start-index", QString::number(skip));
54
55     QObject *reply = The::http()->get(url);
56     connect(reply, SIGNAL(data(QByteArray)), SLOT(parse(QByteArray)));
57     connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*)));
58 }
59
60 void YTStandardFeed::abort() {
61     aborted = true;
62 }
63
64 const QStringList & YTStandardFeed::getSuggestions() {
65     QStringList *l = new QStringList();
66     return *l;
67 }
68
69 void YTStandardFeed::parse(QByteArray data) {
70     if (aborted) return;
71
72     YTFeedReader reader(data);
73     QList<Video*> videos = reader.getVideos();
74
75     emit gotVideos(videos);
76     emit finished(videos.size());
77 }
78
79 void YTStandardFeed::requestError(QNetworkReply *reply) {
80     emit error(reply->errorString());
81 }