1
#include "ytfeedreader.h"
4
YTFeedReader::YTFeedReader(const QByteArray &bytes) : QXmlStreamReader(bytes) {
7
if (isStartElement() && name() == QLatin1String("entry")) {
9
} else if (name() == QLatin1String("link")
10
&& attributes().value("rel").toString()
11
== QLatin1String("http://schemas.google.com/g/2006#spellcorrection")) {
12
suggestions << attributes().value("title").toString();
17
void YTFeedReader::readEntry() {
18
Video* video = new Video();
25
QXmlStreamAttribute attribute;
26
foreach (attribute, attributes())
27
qDebug() << attribute.name() << ":" << attribute.value();
30
if (isEndElement() && name() == QLatin1String("entry")) break;
31
if (isStartElement()) {
33
if (name() == QLatin1String("link")
34
&& attributes().value("rel").toString() == QLatin1String("alternate")
35
&& attributes().value("type").toString() == QLatin1String("text/html")
37
QString webpage = attributes().value("href").toString();
38
webpage.remove("&feature=youtube_gdata");
39
video->setWebpage(QUrl(webpage));
40
} else if (name() == QLatin1String("author")) {
41
while(readNextStartElement())
42
if (name() == QLatin1String("name")) {
43
QString author = readElementText();
44
video->setAuthor(author);
45
} else if (name() == QLatin1String("uri")) {
46
QString uri = readElementText();
47
int i = uri.lastIndexOf('/');
48
if (i != -1) uri = uri.mid(i+1);
49
video->setAuthorUri(uri);
50
} else skipCurrentElement();
51
} else if (name() == QLatin1String("published")) {
52
video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
53
} else if (namespaceUri() == QLatin1String("http://gdata.youtube.com/schemas/2007")
54
&& name() == QLatin1String("statistics")) {
55
QString viewCount = attributes().value("viewCount").toString();
56
video->setViewCount(viewCount.toInt());
58
else if (namespaceUri() == QLatin1String("http://search.yahoo.com/mrss/")
59
&& name() == QLatin1String("group")) {
64
if (isEndElement() && name() == QLatin1String("group")) break;
65
if (isStartElement()) {
66
if (name() == QLatin1String("thumbnail")) {
67
// qDebug() << "Thumb: " << attributes().value("url").toString();
68
QStringRef name = attributes().value("yt:name");
69
if (name == QLatin1String("mqdefault"))
70
video->setThumbnailUrl(
71
attributes().value("url").toString());
72
else if (name == QLatin1String("hqdefault"))
73
video->setMediumThumbnailUrl(
74
attributes().value("url").toString());
76
else if (name() == QLatin1String("title")) {
77
QString title = readElementText();
78
// qDebug() << "Title: " << title;
79
video->setTitle(title);
81
else if (name() == QLatin1String("description")) {
82
QString desc = readElementText();
83
// qDebug() << "Description: " << desc;
84
video->setDescription(desc);
86
else if (name() == QLatin1String("duration")) {
87
QString duration = attributes().value("seconds").toString();
88
// qDebug() << "Duration: " << duration;
89
video->setDuration(duration.toInt());
101
const QList<Video *> &YTFeedReader::getVideos() {
105
const QStringList & YTFeedReader::getSuggestions() const {