1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Upsert the complete info if we fetch it for marking as watched

This commit is contained in:
Nathan Schulzke 2021-07-31 09:45:45 -06:00
parent 0e12cdea7c
commit dc0a28b93d

View File

@ -101,31 +101,35 @@ public class HistoryRecordManager {
final OffsetDateTime currentTime = OffsetDateTime.now(ZoneOffset.UTC); final OffsetDateTime currentTime = OffsetDateTime.now(ZoneOffset.UTC);
return Maybe.fromCallable(() -> database.runInTransaction(() -> { return Maybe.fromCallable(() -> database.runInTransaction(() -> {
final long streamId;
final long duration;
// Duration will not exist if the item was loaded with fast mode, so fetch it if empty // Duration will not exist if the item was loaded with fast mode, so fetch it if empty
if (info.getDuration() < 0) { if (info.getDuration() < 0) {
final long duration = ExtractorHelper.getStreamInfo( final StreamInfo completeInfo = ExtractorHelper.getStreamInfo(
info.getServiceId(), info.getServiceId(),
info.getUrl(), info.getUrl(),
false) false
)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.blockingGet() .blockingGet();
.getDuration(); duration = completeInfo.getDuration();
info.setDuration(duration); streamId = streamTable.upsert(new StreamEntity(completeInfo));
} else {
duration = info.getDuration();
streamId = streamTable.upsert(new StreamEntity(info));
} }
// Upsert to get a stream ID and update durations if we fetched one
final long streamId = streamTable.upsert(new StreamEntity(info));
// Update the stream progress to the full duration of the video // Update the stream progress to the full duration of the video
final List<StreamStateEntity> states = streamStateTable.getState(streamId) final List<StreamStateEntity> states = streamStateTable.getState(streamId)
.blockingFirst(); .blockingFirst();
if (!states.isEmpty()) { if (!states.isEmpty()) {
final StreamStateEntity entity = states.get(0); final StreamStateEntity entity = states.get(0);
entity.setProgressMillis(info.getDuration() * 1000); entity.setProgressMillis(duration * 1000);
streamStateTable.update(entity); streamStateTable.update(entity);
} else { } else {
final StreamStateEntity entity = new StreamStateEntity( final StreamStateEntity entity = new StreamStateEntity(
streamId, streamId,
info.getDuration() * 1000 duration * 1000
); );
streamStateTable.insert(entity); streamStateTable.insert(entity);
} }