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 video->setWebpage(QUrl(webpage));
61 } else if (name() == "author") {
62 while(readNextStartElement())
63 if (name() == "name") {
64 QString author = readElementText();
65 video->setAuthor(author);
66 } else if (name() == "uri") {
67 QString uri = readElementText();
68 int i = uri.lastIndexOf('/');
69 if (i != -1) uri = uri.mid(i+1);
70 video->setAuthorUri(uri);
71 } else skipCurrentElement();
72 } else if (name() == "published") {
73 video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
74 } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007"
75 && name() == "statistics") {
76 QString viewCount = attributes().value("viewCount").toString();
77 video->setViewCount(viewCount.toInt());
79 else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") {
84 if (isEndElement() && name() == "group") break;
85 if (isStartElement()) {
86 if (name() == "thumbnail") {
87 // qDebug() << "Thumb: " << attributes().value("url").toString();
88 // video->thumbnailUrls() << QUrl(attributes().value("url").toString());
89 video->addThumbnailUrl(QUrl(attributes().value("url").toString()));
91 else if (name() == "title") {
92 QString title = readElementText();
93 // qDebug() << "Title: " << title;
94 video->setTitle(title);
96 else if (name() == "description") {
97 QString desc = readElementText();
98 // qDebug() << "Description: " << desc;
99 video->setDescription(desc);
101 else if (name() == "duration") {
102 QString duration = attributes().value("seconds").toString();
103 // qDebug() << "Duration: " << duration;
104 video->setDuration(duration.toInt());
112 videos.append(video);
116 QList<Video*> YouTubeStreamReader::getVideos() {
120 const QStringList & YouTubeStreamReader::getSuggestions() const {