1 #include "ytfeedreader.h"
4 YTFeedReader::YTFeedReader(const QByteArray &bytes) : QXmlStreamReader(bytes) {
7 if (isStartElement() && name() == "entry") {
9 } else if (name() == "link"
10 && attributes().value("rel").toString()
11 == "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() == "entry") break;
31 if (isStartElement()) {
34 && attributes().value("rel").toString() == "alternate"
35 && attributes().value("type").toString() == "text/html"
37 QString webpage = attributes().value("href").toString();
38 webpage.remove("&feature=youtube_gdata");
39 video->setWebpage(QUrl(webpage));
40 } else if (name() == "author") {
41 while(readNextStartElement())
42 if (name() == "name") {
43 QString author = readElementText();
44 video->setAuthor(author);
45 } else if (name() == "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() == "published") {
52 video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
53 } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007"
54 && name() == "statistics") {
55 QString viewCount = attributes().value("viewCount").toString();
56 video->setViewCount(viewCount.toInt());
58 else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") {
63 if (isEndElement() && name() == "group") break;
64 if (isStartElement()) {
65 if (name() == "thumbnail") {
66 // qDebug() << "Thumb: " << attributes().value("url").toString();
67 QStringRef name = attributes().value("yt:name");
68 if (name == "default")
69 video->setThumbnailUrl(
70 attributes().value("url").toString());
71 else if (name == "hqdefault")
72 video->setMediumThumbnailUrl(
73 attributes().value("url").toString());
75 else if (name() == "title") {
76 QString title = readElementText();
77 // qDebug() << "Title: " << title;
78 video->setTitle(title);
80 else if (name() == "description") {
81 QString desc = readElementText();
82 // qDebug() << "Description: " << desc;
83 video->setDescription(desc);
85 else if (name() == "duration") {
86 QString duration = attributes().value("seconds").toString();
87 // qDebug() << "Duration: " << duration;
88 video->setDuration(duration.toInt());
100 const QList<Video *> &YTFeedReader::getVideos() {
104 const QStringList & YTFeedReader::getSuggestions() const {