Skip to content

Commit dc0a28b

Browse files
committed
Upsert the complete info if we fetch it for marking as watched
1 parent 0e12cde commit dc0a28b

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,35 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
101101

102102
final OffsetDateTime currentTime = OffsetDateTime.now(ZoneOffset.UTC);
103103
return Maybe.fromCallable(() -> database.runInTransaction(() -> {
104+
final long streamId;
105+
final long duration;
104106
// Duration will not exist if the item was loaded with fast mode, so fetch it if empty
105107
if (info.getDuration() < 0) {
106-
final long duration = ExtractorHelper.getStreamInfo(
108+
final StreamInfo completeInfo = ExtractorHelper.getStreamInfo(
107109
info.getServiceId(),
108110
info.getUrl(),
109-
false)
111+
false
112+
)
110113
.subscribeOn(Schedulers.io())
111-
.blockingGet()
112-
.getDuration();
113-
info.setDuration(duration);
114+
.blockingGet();
115+
duration = completeInfo.getDuration();
116+
streamId = streamTable.upsert(new StreamEntity(completeInfo));
117+
} else {
118+
duration = info.getDuration();
119+
streamId = streamTable.upsert(new StreamEntity(info));
114120
}
115-
// Upsert to get a stream ID and update durations if we fetched one
116-
final long streamId = streamTable.upsert(new StreamEntity(info));
117121

118122
// Update the stream progress to the full duration of the video
119123
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
120124
.blockingFirst();
121125
if (!states.isEmpty()) {
122126
final StreamStateEntity entity = states.get(0);
123-
entity.setProgressMillis(info.getDuration() * 1000);
127+
entity.setProgressMillis(duration * 1000);
124128
streamStateTable.update(entity);
125129
} else {
126130
final StreamStateEntity entity = new StreamStateEntity(
127131
streamId,
128-
info.getDuration() * 1000
132+
duration * 1000
129133
);
130134
streamStateTable.insert(entity);
131135
}

0 commit comments

Comments
 (0)