Skip to content

Commit 0e12cde

Browse files
committed
Save the fetched duration to the database so that it can render the view correctly.
1 parent bdd16e0 commit 0e12cde

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,31 @@ 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 = streamTable.upsert(new StreamEntity(info));
105-
106-
long duration = info.getDuration();
107104
// Duration will not exist if the item was loaded with fast mode, so fetch it if empty
108-
if (duration < 0) {
109-
duration = ExtractorHelper.getStreamInfo(
105+
if (info.getDuration() < 0) {
106+
final long duration = ExtractorHelper.getStreamInfo(
110107
info.getServiceId(),
111108
info.getUrl(),
112109
false)
113110
.subscribeOn(Schedulers.io())
114111
.blockingGet()
115112
.getDuration();
113+
info.setDuration(duration);
116114
}
115+
// Upsert to get a stream ID and update durations if we fetched one
116+
final long streamId = streamTable.upsert(new StreamEntity(info));
117117

118118
// Update the stream progress to the full duration of the video
119119
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
120120
.blockingFirst();
121121
if (!states.isEmpty()) {
122122
final StreamStateEntity entity = states.get(0);
123-
entity.setProgressMillis(duration * 1000);
123+
entity.setProgressMillis(info.getDuration() * 1000);
124124
streamStateTable.update(entity);
125125
} else {
126126
final StreamStateEntity entity = new StreamStateEntity(
127127
streamId,
128-
duration * 1000
128+
info.getDuration() * 1000
129129
);
130130
streamStateTable.insert(entity);
131131
}

0 commit comments

Comments
 (0)