]> git.sur5r.net Git - minitube/blobdiff - src/ytchannel.cpp
Imported Upstream version 2.5.1
[minitube] / src / ytchannel.cpp
index ad652415b297258c6295598d7197675a96d59f8b..a80879af1736c586325db3bbf898cd6542aefafe 100644 (file)
@@ -27,6 +27,9 @@ $END_LICENSE */
 #include "yt3.h"
 #include <QtScript>
 #endif
+#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
+#include "iconutils.h"
 
 namespace The {
 NetworkAccess* http();
@@ -72,6 +75,7 @@ YTChannel* YTChannel::forId(const QString &channelId) {
         channel->checked = query.value(6).toUInt();
         channel->loaded = query.value(7).toUInt();
         channel->thumbnail = QPixmap(channel->getThumbnailLocation());
+        channel->thumbnail.setDevicePixelRatio(IconUtils::maxSupportedPixelRatio());
         channel->maybeLoadfromAPI();
         cache.insert(channelId, channel);
     }
@@ -92,31 +96,19 @@ void YTChannel::maybeLoadfromAPI() {
 #ifdef APP_YT3
 
     QUrl url = YT3::instance().method("channels");
-#if QT_VERSION >= 0x050000
     {
-        QUrl &u = url;
-        QUrlQuery url;
-#endif
-        url.addQueryItem("id", channelId);
-        url.addQueryItem("part", "snippet");
-#if QT_VERSION >= 0x050000
-        u.setQuery(url);
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("id", channelId);
+        urlHelper.addQueryItem("part", "snippet");
     }
-#endif
 
 #else
 
     QUrl url("http://gdata.youtube.com/feeds/api/users/" + channelId);
-#if QT_VERSION >= 0x050000
     {
-        QUrl &u = url;
-        QUrlQuery url;
-#endif
-        url.addQueryItem("v", "2");
-#if QT_VERSION >= 0x050000
-        u.setQuery(url);
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("v", "2");
     }
-#endif
 
 #endif
 
@@ -142,7 +134,7 @@ void YTChannel::parseResponse(const QByteArray &bytes) {
                 displayName = snippet.property("title").toString();
                 description = snippet.property("description").toString();
                 QScriptValue thumbnails = snippet.property("thumbnails");
-                thumbnailUrl = thumbnails.property("default").property("url").toString();
+                thumbnailUrl = thumbnails.property("medium").property("url").toString();
                 qDebug() << displayName << description << thumbnailUrl;
             }
         }
@@ -190,10 +182,6 @@ void YTChannel::loadThumbnail() {
     if (thumbnailUrl.isEmpty()) return;
     loadingThumbnail = true;
 
-#ifdef Q_OS_WIN
-    thumbnailUrl.replace(QLatin1String("https://"), QLatin1String("http://"));
-#endif
-
     QUrl url(thumbnailUrl);
     QObject *reply = The::http()->get(url);
     connect(reply, SIGNAL(data(QByteArray)), SLOT(storeThumbnail(QByteArray)));
@@ -201,13 +189,7 @@ void YTChannel::loadThumbnail() {
 }
 
 const QString & YTChannel::getThumbnailDir() {
-    static const QString thumbDir =
-        #if QT_VERSION >= 0x050000
-            QStandardPaths::writableLocation(QStandardPaths::DataLocation)
-        #else
-            QDesktopServices::storageLocation(QDesktopServices::DataLocation)
-        #endif
-            + "/channels/";
+    static const QString thumbDir = Paths::getCacheLocation() + "/channels/";
     return thumbDir;
 }
 
@@ -215,19 +197,33 @@ QString YTChannel::getThumbnailLocation() {
     return getThumbnailDir() + channelId;
 }
 
+QString YTChannel::latestVideoId() {
+    QSqlDatabase db = Database::instance().getConnection();
+    QSqlQuery query(db);
+    query.prepare("select video_id from subscriptions_videos where user_id=? order by published desc limit 1");
+    query.bindValue(0, channelId);
+    bool success = query.exec();
+    if (!success) qWarning() << query.lastQuery() << query.lastError().text();
+    if (!query.next()) return QString();
+    return query.value(0).toString();
+}
+
 void YTChannel::unsubscribe() {
     YTChannel::unsubscribe(channelId);
 }
 
 void YTChannel::storeThumbnail(const QByteArray &bytes) {
     thumbnail.loadFromData(bytes);
-    static const int maxWidth = 88;
+    qreal maxRatio = IconUtils::maxSupportedPixelRatio();
+    thumbnail.setDevicePixelRatio(maxRatio);
+    const int maxWidth = 88 * maxRatio;
 
     QDir dir;
     dir.mkpath(getThumbnailDir());
 
     if (thumbnail.width() > maxWidth) {
         thumbnail = thumbnail.scaledToWidth(maxWidth, Qt::SmoothTransformation);
+        thumbnail.setDevicePixelRatio(maxRatio);
         thumbnail.save(getThumbnailLocation(), "JPG");
     } else {
         QFile file(getThumbnailLocation());