X-Git-Url: https://git.sur5r.net/?p=minitube;a=blobdiff_plain;f=src%2Fytjs%2Fytjschannelsource.cpp;h=c8e2d57791f111f3afa2e96492398614a1b4835b;hp=f0862ef567760db71936f11ee5498361f584551b;hb=be5ee6ccd9b29c9d5ca59e4a3d4adf53bac6bc8d;hpb=92723c9ba6a5553e1b136692d99f3bf76b9d5d1c diff --git a/src/ytjs/ytjschannelsource.cpp b/src/ytjs/ytjschannelsource.cpp index f0862ef..c8e2d57 100644 --- a/src/ytjs/ytjschannelsource.cpp +++ b/src/ytjs/ytjschannelsource.cpp @@ -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) {