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") {
29 void YouTubeStreamReader::readMediaGroup() {
33 void YouTubeStreamReader::readEntry() {
34 Video* video = new Video();
35 // qDebug(" *** ENTRY ***");
42 QXmlStreamAttribute attribute;
43 foreach (attribute, attributes())
44 qDebug() << attribute.name() << ":" << attribute.value();
47 if (isEndElement() && name() == "entry") break;
48 if (isStartElement()) {
51 && attributes().value("rel").toString() == "alternate"
52 && attributes().value("type").toString() == "text/html"
54 QString webpage = attributes().value("href").toString();
55 // qDebug() << "Webpage: " << webpage;
56 video->setWebpage(QUrl(webpage));
57 } else if (name() == "author") {
59 if (name() == "name") {
60 QString author = readElementText();
61 // qDebug() << "Author: " << author;
62 video->setAuthor(author);
64 } else if (name() == "published") {
65 video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
66 } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" && name() == "statistics") {
68 QString viewCount = attributes().value("viewCount").toString();
69 // qDebug() << "viewCount: " << viewCount;
70 video->setViewCount(viewCount.toInt());
72 else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") {
77 if (isEndElement() && name() == "group") break;
78 if (isStartElement()) {
79 if (name() == "thumbnail") {
80 // qDebug() << "Thumb: " << attributes().value("url").toString();
81 // video->thumbnailUrls() << QUrl(attributes().value("url").toString());
82 video->addThumbnailUrl(QUrl(attributes().value("url").toString()));
84 else if (name() == "title") {
85 QString title = readElementText();
86 // qDebug() << "Title: " << title;
87 video->setTitle(title);
89 else if (name() == "description") {
90 QString desc = readElementText();
91 // qDebug() << "Description: " << desc;
92 video->setDescription(desc);
94 else if (name() == "duration") {
95 QString duration = attributes().value("seconds").toString();
96 // qDebug() << "Duration: " << duration;
97 video->setDuration(duration.toInt());
105 videos.append(video);
109 QList<Video*> YouTubeStreamReader::getVideos() {