From 4c632810ec8e21544885cf3e564889782ef06b5b Mon Sep 17 00:00:00 2001 From: Nathan Schulzke Date: Tue, 27 Jul 2021 15:20:43 -0600 Subject: [PATCH] Fetch the stream info via a network request if no duration is found when attempting to mark as watched. --- .../local/history/HistoryRecordManager.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java index ad1b695cb..417492005 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java @@ -44,6 +44,7 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.player.playqueue.PlayQueueItem; +import org.schabi.newpipe.util.ExtractorHelper; import java.time.OffsetDateTime; import java.time.ZoneOffset; @@ -91,16 +92,27 @@ public class HistoryRecordManager { return Maybe.fromCallable(() -> database.runInTransaction(() -> { final long streamId = streamTable.upsert(new StreamEntity(info)); + long duration = info.getDuration(); + if (duration < 0) { + duration = ExtractorHelper.getStreamInfo( + info.getServiceId(), + info.getUrl(), + false) + .subscribeOn(Schedulers.io()) + .blockingGet() + .getDuration(); + } + final List states = streamStateTable.getState(streamId) .blockingFirst(); if (!states.isEmpty()) { final StreamStateEntity entity = states.get(0); - entity.setProgressMillis(info.getDuration() * 1000); + entity.setProgressMillis(duration * 1000); streamStateTable.update(entity); } else { final StreamStateEntity entity = new StreamStateEntity( streamId, - info.getDuration() * 1000 + duration * 1000 ); streamStateTable.insert(entity); }