1 #include "youtubestreamreader.h"
5 YouTubeStreamReader::YouTubeStreamReader() {
9 bool YouTubeStreamReader::read(QByteArray data) {
14 if (isStartElement()) {
15 if (name() == "feed") {
18 if (isStartElement() && name() == "entry") {
20 } else if (name() == "link"
21 && attributes().value("rel").toString()
22 == "http://schemas.google.com/g/2006#spellcorrection") {
23 suggestions << attributes().value("title").toString();
33 void YouTubeStreamReader::readMediaGroup() {
37 void YouTubeStreamReader::readEntry() {
38 Video* video = new Video();
39 // qDebug(" *** ENTRY ***");
46 QXmlStreamAttribute attribute;
47 foreach (attribute, attributes())
48 qDebug() << attribute.name() << ":" << attribute.value();
51 if (isEndElement() && name() == "entry") break;
52 if (isStartElement()) {
55 && attributes().value("rel").toString() == "alternate"
56 && attributes().value("type").toString() == "text/html"
58 QString webpage = attributes().value("href").toString();
59 webpage.remove("&feature=youtube_gdata");
60 // qDebug() << "Webpage: " << webpage;
61 video->setWebpage(QUrl(webpage));
63 } else if (name() == "author") {
65 if (name() == "name") {
66 QString author = readElementText();
67 // qDebug() << "Author: " << author;
68 video->setAuthor(author);
70 } else if (name() == "published") {
71 video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
72 } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" && name() == "statistics") {
74 QString viewCount = attributes().value("viewCount").toString();
75 // qDebug() << "viewCount: " << viewCount;
76 video->setViewCount(viewCount.toInt());
78 else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") {
83 if (isEndElement() && name() == "group") break;
84 if (isStartElement()) {
85 if (name() == "thumbnail") {
86 // qDebug() << "Thumb: " << attributes().value("url").toString();
87 // video->thumbnailUrls() << QUrl(attributes().value("url").toString());
88 video->addThumbnailUrl(QUrl(attributes().value("url").toString()));
90 else if (name() == "title") {
91 QString title = readElementText();
92 // qDebug() << "Title: " << title;
93 video->setTitle(title);
95 else if (name() == "description") {
96 QString desc = readElementText();
97 // qDebug() << "Description: " << desc;
98 video->setDescription(desc);
100 else if (name() == "duration") {
101 QString duration = attributes().value("seconds").toString();
102 // qDebug() << "Duration: " << duration;
103 video->setDuration(duration.toInt());
111 videos.append(video);
115 QList<Video*> YouTubeStreamReader::getVideos() {
119 const QStringList & YouTubeStreamReader::getSuggestions() const {