#include "yt3.h"
#include <QtScript>
#endif
+#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
+#include "iconutils.h"
namespace The {
NetworkAccess* http();
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);
}
#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
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;
}
}
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)));
}
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;
}
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());