]> git.sur5r.net Git - minitube/blobdiff - src/channelaggregator.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / channelaggregator.cpp
index 2fcf42b5d0f8fdca1430e819e78535159477fc3a..8097af180e51fe03d44ed32383b50b61cc8e42f9 100644 (file)
@@ -81,9 +81,6 @@ void ChannelAggregator::run() {
     updatedChannels.clear();
     updatedChannels.squeeze();
 
-    if (!Database::instance().getConnection().transaction())
-        qWarning() << "Transaction failed" << __PRETTY_FUNCTION__;
-
     processNextChannel();
 }
 
@@ -135,7 +132,7 @@ void ChannelAggregator::parseWebPage(const QByteArray &bytes) {
     } else {
         currentChannel->updateChecked();
         currentChannel = 0;
-        processNextChannel();
+        QTimer::singleShot(5000, this, &ChannelAggregator::processNextChannel);
     }
 }
 
@@ -175,9 +172,6 @@ void ChannelAggregator::reallyProcessChannel(YTChannel *channel) {
 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;
@@ -207,8 +201,10 @@ void ChannelAggregator::videosLoaded(const QVector<Video *> &videos) {
 
     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();
@@ -277,7 +273,18 @@ void ChannelAggregator::addVideo(Video *video) {
     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();
@@ -324,7 +331,7 @@ void ChannelAggregator::videoWatched(Video *video) {
     if (!success) qWarning() << query.lastQuery() << query.lastError().text();
     if (query.numRowsAffected() > 0) {
         YTChannel *channel = YTChannel::forId(video->getChannelId());
-        channel->updateNotifyCount();
+        if (channel) channel->updateNotifyCount();
     }
 }