From 184009df6b3bb84d1e428e027b6667d739b41e03 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Tue, 7 Apr 2015 21:51:28 +0200 Subject: [PATCH] YT api v3 support --- minitube.pro | 23 ++- src/aggregatevideosource.cpp | 17 +- src/aggregatevideosource.h | 4 +- src/channelaggregator.cpp | 108 ++++++----- src/channelaggregator.h | 12 +- src/channelitemdelegate.cpp | 16 +- src/channelmodel.cpp | 36 ++-- src/channelmodel.h | 8 +- src/channelsitemdelegate.cpp | 152 ++++++++++++++++ src/channelsitemdelegate.h | 24 +++ src/channelsmodel.cpp | 90 ++++++++++ src/channelsmodel.h | 45 +++++ src/channelsuggest.cpp | 11 +- src/channelsview.cpp | 275 ++++++++++++++++++++++++++++ src/channelsview.h | 64 +++++++ src/channelview.cpp | 28 +-- src/channelwidget.cpp | 85 +++++++++ src/channelwidget.h | 35 ++++ src/database.cpp | 48 +++-- src/database.h | 2 + src/datautils.cpp | 57 ++++++ src/datautils.h | 3 + src/diskcache.cpp | 17 +- src/diskcache.h | 1 + src/main.cpp | 63 +++---- src/mainwindow.cpp | 64 ++++--- src/mediaview.cpp | 54 +++--- src/networkaccess.cpp | 2 +- src/paginatedvideosource.cpp | 170 ++++++++++++++++++ src/paginatedvideosource.h | 59 ++++++ src/playlistitemdelegate.cpp | 9 +- src/playlistmodel.cpp | 80 +++++---- src/playlistmodel.h | 10 +- src/playlistview.cpp | 3 +- src/searchparams.cpp | 1 + src/searchparams.h | 14 +- src/searchview.cpp | 27 +-- src/searchview.h | 2 +- src/standardfeedsview.cpp | 10 +- src/suggester.h | 6 +- src/video.cpp | 93 +++++----- src/video.h | 28 +-- src/videosource.h | 3 +- src/yt3.cpp | 119 ++++++++++++ src/yt3.h | 32 ++++ src/yt3listparser.cpp | 76 ++++++++ src/yt3listparser.h | 25 +++ src/ytcategories.cpp | 69 ++++++- src/{ytuser.cpp => ytchannel.cpp} | 179 +++++++++++------- src/{ytuser.h => ytchannel.h} | 34 ++-- src/ytfeedreader.cpp | 6 +- src/ytfeedreader.h | 2 +- src/ytsearch.cpp | 289 ++++++++++++++++++++++-------- src/ytsearch.h | 17 +- src/ytsinglevideosource.cpp | 157 ++++++++++++---- src/ytsinglevideosource.h | 12 +- src/ytstandardfeed.cpp | 115 +++++++++--- src/ytstandardfeed.h | 8 +- src/ytsuggester.cpp | 9 +- 59 files changed, 2449 insertions(+), 559 deletions(-) create mode 100644 src/channelsitemdelegate.cpp create mode 100644 src/channelsitemdelegate.h create mode 100644 src/channelsmodel.cpp create mode 100644 src/channelsmodel.h create mode 100644 src/channelsview.cpp create mode 100644 src/channelsview.h create mode 100644 src/channelwidget.cpp create mode 100644 src/channelwidget.h create mode 100644 src/paginatedvideosource.cpp create mode 100644 src/paginatedvideosource.h create mode 100644 src/yt3.cpp create mode 100644 src/yt3.h create mode 100644 src/yt3listparser.cpp create mode 100644 src/yt3listparser.h rename src/{ytuser.cpp => ytchannel.cpp} (67%) rename src/{ytuser.h => ytchannel.h} (75%) diff --git a/minitube.pro b/minitube.pro index effa02e..2f029bf 100644 --- a/minitube.pro +++ b/minitube.pro @@ -1,6 +1,6 @@ CONFIG += release TEMPLATE = app -VERSION = 2.3 +VERSION = 2.4 DEFINES += APP_VERSION="$$VERSION" APP_NAME = Minitube @@ -12,14 +12,19 @@ DEFINES += APP_UNIX_NAME="$$APP_UNIX_NAME" DEFINES += APP_PHONON DEFINES += APP_PHONON_SEEK DEFINES += APP_SNAPSHOT +DEFINES += APP_YT3 DEFINES *= QT_NO_DEBUG_OUTPUT DEFINES *= QT_USE_QSTRINGBUILDER DEFINES *= QT_STRICT_ITERATORS +!contains(DEFINES, APP_GOOGLE_API_KEY) { + warning("You need to specify a Google API Key, refer to the README.md file for details") +} + TARGET = $${APP_UNIX_NAME} -QT += network xml sql script +QT += network sql script qt:greaterThan(QT_MAJOR_VERSION, 4) { contains(QT, gui): QT *= widgets } @@ -83,7 +88,6 @@ HEADERS += src/video.h \ src/gridwidget.h \ src/painterutils.h \ src/database.h \ - src/ytuser.h \ src/channelaggregator.h \ src/channelmodel.h \ src/aggregatevideosource.h \ @@ -93,7 +97,11 @@ HEADERS += src/video.h \ src/seekslider.h \ src/snapshotsettings.h \ src/snapshotpreview.h \ - src/datautils.h + src/datautils.h \ + src/yt3listparser.h \ + src/ytchannel.h \ + src/yt3.h \ + src/paginatedvideosource.h SOURCES += src/main.cpp \ src/searchlineedit.cpp \ src/urllineedit.cpp \ @@ -149,7 +157,6 @@ SOURCES += src/main.cpp \ src/gridwidget.cpp \ src/painterutils.cpp \ src/database.cpp \ - src/ytuser.cpp \ src/channelaggregator.cpp \ src/channelmodel.cpp \ src/aggregatevideosource.cpp \ @@ -159,7 +166,11 @@ SOURCES += src/main.cpp \ src/seekslider.cpp \ src/snapshotsettings.cpp \ src/snapshotpreview.cpp \ - src/datautils.cpp + src/datautils.cpp \ + src/yt3listparser.cpp \ + src/ytchannel.cpp \ + src/yt3.cpp \ + src/paginatedvideosource.cpp RESOURCES += resources.qrc DESTDIR = build/target/ OBJECTS_DIR = build/obj/ diff --git a/src/aggregatevideosource.cpp b/src/aggregatevideosource.cpp index 55e72dc..2c5f330 100644 --- a/src/aggregatevideosource.cpp +++ b/src/aggregatevideosource.cpp @@ -25,9 +25,9 @@ $END_LICENSE */ AggregateVideoSource::AggregateVideoSource(QObject *parent) : VideoSource(parent), - unwatched(false) { } + unwatched(false), hasMore(true) { } -void AggregateVideoSource::loadVideos(int max, int skip) { +void AggregateVideoSource::loadVideos(int max, int startIndex) { QSqlDatabase db = Database::instance().getConnection(); QSqlQuery query(db); QString sql = "select v.video_id," @@ -48,7 +48,7 @@ void AggregateVideoSource::loadVideos(int max, int skip) { sql += " from subscriptions_videos v order by published desc "; sql += "limit ?,?"; query.prepare(sql); - query.bindValue(0, skip - 1); + query.bindValue(0, startIndex - 1); query.bindValue(1, max); bool success = query.exec(); if (!success) qWarning() << query.lastQuery() << query.lastError().text(); @@ -58,8 +58,8 @@ void AggregateVideoSource::loadVideos(int max, int skip) { video->setId(query.value(0).toString()); video->setPublished(QDateTime::fromTime_t(query.value(1).toUInt())); video->setTitle(query.value(2).toString()); - video->setAuthor(query.value(3).toString()); - video->setUserId(query.value(4).toString()); + video->setChannelTitle(query.value(3).toString()); + video->setChannelId(query.value(4).toString()); video->setDescription(query.value(5).toString()); video->setWebpage(query.value(6).toString()); video->setThumbnailUrl(query.value(7).toString()); @@ -67,10 +67,17 @@ void AggregateVideoSource::loadVideos(int max, int skip) { video->setDuration(query.value(9).toInt()); videos << video; } + + hasMore = videos.size() >= max; + emit gotVideos(videos); emit finished(videos.size()); } +bool AggregateVideoSource::hasMoreVideos() { + return hasMore; +} + const QStringList & AggregateVideoSource::getSuggestions() { QStringList *l = new QStringList(); return *l; diff --git a/src/aggregatevideosource.h b/src/aggregatevideosource.h index 49de4a0..55aa730 100644 --- a/src/aggregatevideosource.h +++ b/src/aggregatevideosource.h @@ -30,7 +30,8 @@ class AggregateVideoSource : public VideoSource { public: AggregateVideoSource(QObject *parent = 0); - void loadVideos(int max, int skip); + void loadVideos(int max, int startIndex); + bool hasMoreVideos(); virtual void abort(); virtual const QStringList & getSuggestions(); QString getName() { return name; } @@ -40,6 +41,7 @@ public: private: QString name; bool unwatched; + bool hasMore; }; diff --git a/src/channelaggregator.cpp b/src/channelaggregator.cpp index 092a993..a7eb055 100644 --- a/src/channelaggregator.cpp +++ b/src/channelaggregator.cpp @@ -19,7 +19,7 @@ along with Minitube. If not, see . $END_LICENSE */ #include "channelaggregator.h" -#include "ytuser.h" +#include "ytchannel.h" #include "ytsearch.h" #include "searchparams.h" #include "database.h" @@ -32,8 +32,7 @@ ChannelAggregator::ChannelAggregator(QObject *parent) : QObject(parent), unwatchedCount(-1), running(false), stopped(false) { - QSettings settings; - checkInterval = settings.value("subscriptionsCheckInterval", 1800).toUInt(); + checkInterval = 3600; timer = new QTimer(this); timer->setInterval(60000 * 5); @@ -46,9 +45,10 @@ ChannelAggregator* ChannelAggregator::instance() { } void ChannelAggregator::start() { + stopped = false; updateUnwatchedCount(); QTimer::singleShot(0, this, SLOT(run())); - timer->start(); + if (!timer->isActive()) timer->start(); } void ChannelAggregator::stop() { @@ -56,59 +56,65 @@ void ChannelAggregator::stop() { stopped = true; } -YTUser* ChannelAggregator::getChannelToCheck() { +YTChannel* ChannelAggregator::getChannelToCheck() { if (stopped) return 0; QSqlDatabase db = Database::instance().getConnection(); QSqlQuery query(db); query.prepare("select user_id from subscriptions where checkedprocessEvents(); - YTUser* user = getChannelToCheck(); - if (user) { + YTChannel* channel = getChannelToCheck(); + if (channel) { SearchParams *params = new SearchParams(); - params->setAuthor(user->getUserId()); + params->setChannelId(channel->getChannelId()); params->setSortBy(SearchParams::SortByNewest); params->setTransient(true); + params->setPublishedAfter(channel->getChecked()); YTSearch *videoSource = new YTSearch(params, this); - connect(videoSource, SIGNAL(gotVideos(QList)), - SLOT(videosLoaded(QList))); - videoSource->loadVideos(10, 1); - user->updateChecked(); + connect(videoSource, SIGNAL(gotVideos(QList)), SLOT(videosLoaded(QList))); + videoSource->loadVideos(50, 1); + channel->updateChecked(); } else finish(); } void ChannelAggregator::finish() { - foreach (YTUser *user, updatedChannels) - if (user->updateNotifyCount()) - emit channelChanged(user); - + /* + foreach (YTChannel *channel, updatedChannels) + if (channel->updateNotifyCount()) + emit channelChanged(channel); updateUnwatchedCount(); + */ QSqlDatabase db = Database::instance().getConnection(); if (!db.commit()) qWarning() << "Commit failed" << __PRETTY_FUNCTION__; + /* QByteArray b = db.databaseName().right(20).toLocal8Bit(); const char* s = b.constData(); @@ -124,8 +130,8 @@ void ChannelAggregator::finish() { QString channelNames; const int total = updatedChannels.size(); for (int i = 0; i < total; ++i) { - YTUser *user = updatedChannels.at(i); - channelNames += user->getDisplayName(); + YTChannel *channel = updatedChannels.at(i); + channelNames += channel->getDisplayName(); if (i < total-1) channelNames.append(", "); } channelNames = tr("By %1").arg(channelNames); @@ -138,14 +144,23 @@ void ChannelAggregator::finish() { running = false; } -void ChannelAggregator::videosLoaded(QList