#include "http.h"
#include "httputils.h"
-#include "videoapi.h"
#include "ivchannelsource.h"
+#include "videoapi.h"
+#include "ytjschannelsource.h"
ChannelAggregator::ChannelAggregator(QObject *parent)
: QObject(parent), unwatchedCount(-1), running(false), stopped(false), currentChannel(0) {
updatedChannels.clear();
updatedChannels.squeeze();
- if (!Database::instance().getConnection().transaction())
- qWarning() << "Transaction failed" << __PRETTY_FUNCTION__;
-
processNextChannel();
}
void ChannelAggregator::checkWebPage(YTChannel *channel) {
currentChannel = channel;
- QString url = "https://www.youtube.com/channel/" + channel->getChannelId() + "/videos";
+
+ QString channelId = channel->getChannelId();
+ QString url;
+ if (channelId.startsWith("UC") && !channelId.contains(' ')) {
+ url = "https://www.youtube.com/channel/" + channelId + "/videos";
+ } else {
+ url = "https://www.youtube.com/user/" + channelId + "/videos";
+ }
+
QObject *reply = HttpUtils::yt().get(url);
connect(reply, SIGNAL(data(QByteArray)), SLOT(parseWebPage(QByteArray)));
} else {
currentChannel->updateChecked();
currentChannel = 0;
- processNextChannel();
+ QTimer::singleShot(5000, this, &ChannelAggregator::processNextChannel);
}
}
connect(videoSource, SIGNAL(gotVideos(QVector<Video *>)),
SLOT(videosLoaded(QVector<Video *>)));
videoSource->loadVideos(50, 1);
+ } else if (VideoAPI::impl() == VideoAPI::JS) {
+ auto *videoSource = new YTJSChannelSource(params);
+ connect(videoSource, SIGNAL(gotVideos(QVector<Video *>)),
+ SLOT(videosLoaded(QVector<Video *>)));
+ videoSource->loadVideos(50, 1);
}
channel->updateChecked();
void ChannelAggregator::finish() {
currentChannel = 0;
- QSqlDatabase db = Database::instance().getConnection();
- if (!db.commit()) qWarning() << "Commit failed" << __PRETTY_FUNCTION__;
-
#ifdef Q_OS_MAC
if (newVideoCount > 0 && unwatchedCount > 0 && mac::canNotify()) {
QString channelNames;
if (!videos.isEmpty()) {
YTChannel *channel = YTChannel::forId(videos.at(0)->getChannelId());
- channel->updateNotifyCount();
- emit channelChanged(channel);
+ if (channel) {
+ channel->updateNotifyCount();
+ emit channelChanged(channel);
+ }
updateUnwatchedCount();
for (Video *video : videos)
video->deleteLater();
query.bindValue(7, video->getChannelId());
query.bindValue(8, video->getDescription());
query.bindValue(9, video->getWebpage());
- query.bindValue(10, video->getThumbnailUrl());
+
+ QJsonDocument thumbsDoc;
+ auto thumbsArray = thumbsDoc.array();
+ for (const auto &t : video->getThumbs()) {
+ thumbsArray.append(QJsonObject{
+ {"url", t.getUrl()},
+ {"width", t.getWidth()},
+ {"height", t.getHeight()},
+ });
+ }
+ thumbsDoc.setArray(thumbsArray);
+ query.bindValue(10, thumbsDoc.toJson(QJsonDocument::Compact));
query.bindValue(11, video->getViewCount());
query.bindValue(12, video->getDuration());
success = query.exec();
if (!success) qWarning() << query.lastQuery() << query.lastError().text();
if (query.numRowsAffected() > 0) {
YTChannel *channel = YTChannel::forId(video->getChannelId());
- channel->updateNotifyCount();
+ if (channel) channel->updateNotifyCount();
}
}