Skip to content

Commit d1f6337

Browse files
TobiGrStypox
authored andcommitted
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 d7dffb7 commit d1f6337

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
@@ -447,39 +447,28 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {
447447
.getIsPlaylistThumbnailPermanent(playlistId);
448448
boolean thumbnailVideoRemoved = false;
449449

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

0 commit comments

Comments
 (0)