Skip to content

Commit 4c63281

Browse files
committed
Fetch the stream info via a network request if no duration is found when attempting to mark as watched.
1 parent f451bdb commit 4c63281

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.schabi.newpipe.extractor.stream.StreamInfo;
4545
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
4646
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
47+
import org.schabi.newpipe.util.ExtractorHelper;
4748

4849
import java.time.OffsetDateTime;
4950
import java.time.ZoneOffset;
@@ -91,16 +92,27 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
9192
return Maybe.fromCallable(() -> database.runInTransaction(() -> {
9293
final long streamId = streamTable.upsert(new StreamEntity(info));
9394

95+
long duration = info.getDuration();
96+
if (duration < 0) {
97+
duration = ExtractorHelper.getStreamInfo(
98+
info.getServiceId(),
99+
info.getUrl(),
100+
false)
101+
.subscribeOn(Schedulers.io())
102+
.blockingGet()
103+
.getDuration();
104+
}
105+
94106
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
95107
.blockingFirst();
96108
if (!states.isEmpty()) {
97109
final StreamStateEntity entity = states.get(0);
98-
entity.setProgressMillis(info.getDuration() * 1000);
110+
entity.setProgressMillis(duration * 1000);
99111
streamStateTable.update(entity);
100112
} else {
101113
final StreamStateEntity entity = new StreamStateEntity(
102114
streamId,
103-
info.getDuration() * 1000
115+
duration * 1000
104116
);
105117
streamStateTable.insert(entity);
106118
}

0 commit comments

Comments
 (0)