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.
This commit is contained in:
tobigr 2025-12-21 17:08:51 +01:00 committed by Stypox
parent 03abf7a950
commit ec87d3e0bc

View file

@ -447,39 +447,28 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
.getIsPlaylistThumbnailPermanent(playlistId); .getIsPlaylistThumbnailPermanent(playlistId);
boolean thumbnailVideoRemoved = false; boolean thumbnailVideoRemoved = false;
if (removePartiallyWatched) { final var streamStates = recordManager
for (final var playlistItem : playlist) { .loadLocalStreamStateBatch(playlist).blockingGet();
final int indexInHistory = Collections.binarySearch(historyStreamIds,
playlistItem.getStreamId());
if (indexInHistory < 0) { for (int i = 0; i < playlist.size(); i++) {
itemsToKeep.add(playlistItem); final var playlistItem = playlist.get(i);
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved final var streamStateEntity = streamStates.get(i);
&& playlistManager.getPlaylistThumbnailStreamId(playlistId) final int indexInHistory = Collections.binarySearch(historyStreamIds,
== playlistItem.getStreamEntity().getUid()) { playlistItem.getStreamId());
thumbnailVideoRemoved = true; final long duration = playlistItem.toStreamInfoItem().getDuration();
}
}
} else {
final var streamStates = recordManager
.loadLocalStreamStateBatch(playlist).blockingGet();
for (int i = 0; i < playlist.size(); i++) { if (indexInHistory < 0 // stream is not in history
final var playlistItem = playlist.get(i); // stream is in history but the streamStateEntity is null
final var streamStateEntity = streamStates.get(i); // if the stream was played for less than 5 seconds, see
// StreamStateEntity#PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS
final int indexInHistory = Collections.binarySearch(historyStreamIds, || streamStateEntity == null
playlistItem.getStreamId()); || (!streamStateEntity.isFinished(duration)
final long duration = playlistItem.toStreamInfoItem().getDuration(); && !removePartiallyWatched)) {
itemsToKeep.add(playlistItem);
if (indexInHistory < 0 || (streamStateEntity != null } else if (!isThumbnailPermanent && !thumbnailVideoRemoved
&& !streamStateEntity.isFinished(duration))) { && playlistManager.getPlaylistThumbnailStreamId(playlistId)
itemsToKeep.add(playlistItem); == playlistItem.getStreamEntity().getUid()) {
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved thumbnailVideoRemoved = true;
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
== playlistItem.getStreamEntity().getUid()) {
thumbnailVideoRemoved = true;
}
} }
} }