]> git.sur5r.net Git - minitube/blobdiff - src/ytjs/ytjschannelsource.cpp
New upstream version 3.6.1
[minitube] / src / ytjs / ytjschannelsource.cpp
index f0862ef567760db71936f11ee5498361f584551b..c8e2d57791f111f3afa2e96492398614a1b4835b 100644 (file)
@@ -20,21 +20,26 @@ QString parseChannelId(const QString &channelUrl) {
     return QString();
 }
 
-quint64 parsePublishedText(const QString &s) {
-    int pos = s.indexOf(' ');
-    if (pos <= 0) return 0;
-    auto num = s.leftRef(pos);
-    auto now = QDateTime::currentSecsSinceEpoch();
+QDateTime parsePublishedText(const QString &s) {
+    int num = 0;
+    const auto parts = s.splitRef(' ');
+    for (const auto &part : parts) {
+        num = part.toInt();
+        if (num > 0) break;
+    }
+    if (num == 0) return QDateTime();
+
+    auto now = QDateTime::currentDateTimeUtc();
     if (s.contains("day")) {
-        return now - num.toInt() * 86400;
+        return now.addDays(-num);
     } else if (s.contains("week")) {
-        return now - num.toInt() * 86400 * 7;
+        return now.addDays(-num * 7);
     } else if (s.contains("month")) {
-        return now - num.toInt() * 86400 * 30;
+        return now.addMonths(-num);
     } else if (s.contains("year")) {
-        return now - num.toInt() * 86400 * 365;
+        return now.addDays(-num * 365);
     }
-    return 0;
+    return QDateTime();
 }
 
 } // namespace
@@ -123,8 +128,8 @@ void YTJSChannelSource::loadVideos(int max, int startIndex) {
             int duration = i["lengthSeconds"].toInt();
             video->setDuration(duration);
 
-            int published = parsePublishedText(i["publishedText"].toString());
-            if (published) video->setPublished(QDateTime::fromSecsSinceEpoch(published));
+            auto published = parsePublishedText(i["publishedText"].toString());
+            if (published.isValid()) video->setPublished(published);
 
             QString channelName = i["author"].toString();
             if (channelName != name) {