From 1fe4c71707136fcaa9e87b31f0a0b97bac63fa0c Mon Sep 17 00:00:00 2001 From: Flavio Date: Tue, 11 Dec 2012 09:56:11 +0100 Subject: [PATCH] Support YouTube author display names --- src/video.cpp | 1 + src/video.h | 4 ++++ src/youtubestreamreader.cpp | 23 ++++++++++++----------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 42c5efa..4b8e247 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -19,6 +19,7 @@ Video* Video::clone() { cloneVideo->m_title = m_title; cloneVideo->m_description = m_description; cloneVideo->m_author = m_author; + cloneVideo->m_authorUri = m_authorUri; cloneVideo->m_webpage = m_webpage; cloneVideo->m_streamUrl = m_streamUrl; cloneVideo->m_thumbnail = m_thumbnail; diff --git a/src/video.h b/src/video.h index c7b0165..d48a848 100644 --- a/src/video.h +++ b/src/video.h @@ -21,6 +21,9 @@ public: const QString author() const { return m_author; } void setAuthor( QString author ) { m_author = author; } + const QString authorUri() const { return m_authorUri; } + void setAuthorUri( QString authorUri ) { m_authorUri = authorUri; } + const QUrl webpage() const { return m_webpage; } void setWebpage( QUrl webpage ) { m_webpage = webpage; } @@ -70,6 +73,7 @@ private: QString m_title; QString m_description; QString m_author; + QString m_authorUri; QUrl m_webpage; QUrl m_streamUrl; QImage m_thumbnail; diff --git a/src/youtubestreamreader.cpp b/src/youtubestreamreader.cpp index 9869da7..78a9675 100644 --- a/src/youtubestreamreader.cpp +++ b/src/youtubestreamreader.cpp @@ -57,22 +57,23 @@ void YouTubeStreamReader::readEntry() { ) { QString webpage = attributes().value("href").toString(); webpage.remove("&feature=youtube_gdata"); - // qDebug() << "Webpage: " << webpage; video->setWebpage(QUrl(webpage)); - } else if (name() == "author") { - readNext(); - if (name() == "name") { - QString author = readElementText(); - // qDebug() << "Author: " << author; - video->setAuthor(author); - } + while(readNextStartElement()) + if (name() == "name") { + QString author = readElementText(); + video->setAuthor(author); + } else if (name() == "uri") { + QString uri = readElementText(); + int i = uri.lastIndexOf('/'); + if (i != -1) uri = uri.mid(i+1); + video->setAuthorUri(uri); + } else skipCurrentElement(); } else if (name() == "published") { video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate)); - } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" && name() == "statistics") { - + } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" + && name() == "statistics") { QString viewCount = attributes().value("viewCount").toString(); - // qDebug() << "viewCount: " << viewCount; video->setViewCount(viewCount.toInt()); } else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") { -- 2.39.5