Skip to content

Commit 6b6d6ff

Browse files
committed
Fix removing unwatched streams from playlist when using "remove watched"
The bug is caused by a wanted but forgotten inconsistency in the database. A stream can be listed in the watch history (StreamHistoryEntity) while having no corresponding playback state (StreamStateEntity) containing the matching playback position. This is caused by the fact that NewPipe does not consider a watch time of less than five seconds to be worthy to be put into the StreamStateEntity because the video was most likely played by error. Those videos are, however, counted and stored in the watch history.
1 parent 3c0e6ad commit 6b6d6ff

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -448,39 +448,28 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {
448448
.getIsPlaylistThumbnailPermanent(playlistId);
449449
boolean thumbnailVideoRemoved = false;
450450

451-
if (removePartiallyWatched) {
452-
for (final var playlistItem : playlist) {
453-
final int indexInHistory = Collections.binarySearch(historyStreamIds,
454-
playlistItem.getStreamId());
455-
456-
if (indexInHistory < 0) {
457-
itemsToKeep.add(playlistItem);
458-
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
459-
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
460-
== playlistItem.getStreamEntity().getUid()) {
461-
thumbnailVideoRemoved = true;
462-
}
463-
}
464-
} else {
465-
final var streamStates = recordManager
466-
.loadLocalStreamStateBatch(playlist).blockingGet();
467-
468-
for (int i = 0; i < playlist.size(); i++) {
469-
final var playlistItem = playlist.get(i);
470-
final var streamStateEntity = streamStates.get(i);
471-
472-
final int indexInHistory = Collections.binarySearch(historyStreamIds,
473-
playlistItem.getStreamId());
474-
final long duration = playlistItem.toStreamInfoItem().getDuration();
475-
476-
if (indexInHistory < 0 || (streamStateEntity != null
477-
&& !streamStateEntity.isFinished(duration))) {
478-
itemsToKeep.add(playlistItem);
479-
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
480-
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
481-
== playlistItem.getStreamEntity().getUid()) {
482-
thumbnailVideoRemoved = true;
483-
}
451+
final var streamStates = recordManager
452+
.loadLocalStreamStateBatch(playlist).blockingGet();
453+
454+
for (int i = 0; i < playlist.size(); i++) {
455+
final var playlistItem = playlist.get(i);
456+
final var streamStateEntity = streamStates.get(i);
457+
final int indexInHistory = Collections.binarySearch(historyStreamIds,
458+
playlistItem.getStreamId());
459+
final long duration = playlistItem.toStreamInfoItem().getDuration();
460+
461+
if (indexInHistory < 0 // stream is not in history
462+
// stream is in history but the streamStateEntity is null
463+
// if the stream was played for less than 5 seconds, see
464+
// StreamStateEntity#PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS
465+
|| streamStateEntity == null
466+
|| (!streamStateEntity.isFinished(duration)
467+
&& !removePartiallyWatched)) {
468+
itemsToKeep.add(playlistItem);
469+
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
470+
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
471+
== playlistItem.getStreamEntity().getUid()) {
472+
thumbnailVideoRemoved = true;
484473
}
485474
}
486475

0 commit comments

Comments
 (0)