From: Flavio Tordini Date: Tue, 7 Apr 2015 19:51:28 +0000 (+0200) Subject: YT api v3 support X-Git-Tag: 2.4~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=184009df6b3bb84d1e428e027b6667d739b41e03;p=minitube YT api v3 support --- 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