Fetch the stream info via a network request if no duration is found when attempting to mark as watched.

This commit is contained in:
Nathan Schulzke 2021-07-27 15:20:43 -06:00
parent f451bdbfa4
commit 4c632810ec
1 changed files with 14 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.util.ExtractorHelper;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -91,16 +92,27 @@ public class HistoryRecordManager {
return Maybe.fromCallable(() -> database.runInTransaction(() -> { return Maybe.fromCallable(() -> database.runInTransaction(() -> {
final long streamId = streamTable.upsert(new StreamEntity(info)); 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<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);
} }