Remove items from watchlater if 70% watched

This commit is contained in:
Kelvin 2024-11-12 22:02:08 +01:00
parent 3a99f5dfaa
commit 70cbc77381
4 changed files with 38 additions and 1 deletions

View file

@ -505,6 +505,9 @@ class Settings : FragmentedStorageFileJson() {
@FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 21)
var autoplay: Boolean = false;
@FormField(R.string.delete_watchlist_on_finish, FieldForm.TOGGLE, R.string.delete_watchlist_on_finish_description, 22)
var deleteFromWatchLaterAuto: Boolean = true;
}
@FormField(R.string.comments, "group", R.string.comments_description, 6)

View file

@ -735,6 +735,7 @@ class VideoDetailView : ConstraintLayout {
};
onClose.subscribe {
checkAndRemoveWatchLater();
_lastVideoSource = null;
_lastAudioSource = null;
_lastSubtitleSource = null;
@ -1834,6 +1835,8 @@ class VideoDetailView : ConstraintLayout {
fun prevVideo(withoutRemoval: Boolean = false) {
Logger.i(TAG, "prevVideo")
checkAndRemoveWatchLater();
val next = StatePlayer.instance.prevQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9);
if(next != null) {
setVideoOverview(next, true, 0, true);
@ -1842,6 +1845,8 @@ class VideoDetailView : ConstraintLayout {
fun nextVideo(forceLoop: Boolean = false, withoutRemoval: Boolean = false, bypassVideoLoop: Boolean = false): Boolean {
Logger.i(TAG, "nextVideo")
checkAndRemoveWatchLater();
var next = StatePlayer.instance.nextQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9, bypassVideoLoop);
val autoplayVideo = _autoplayVideo
if (next == null && autoplayVideo != null && StatePlayer.instance.autoplay) {
@ -1850,7 +1855,8 @@ class VideoDetailView : ConstraintLayout {
next = autoplayVideo
}
_autoplayVideo = null
Logger.i(TAG, "Autoplay video cleared (nextVideo)")
Logger.i(TAG, "Autoplay video cleared (nextVideo)");
if(next == null && forceLoop)
next = StatePlayer.instance.restartQueue();
if(next != null) {
@ -1862,6 +1868,20 @@ class VideoDetailView : ConstraintLayout {
return false;
}
fun checkAndRemoveWatchLater(){
val watchCurrent = video ?: videoLocal ?: _searchVideo;
if(Settings.instance.playback.deleteFromWatchLaterAuto) {
if(watchCurrent?.duration != null &&
watchCurrent.duration > 0 &&
(lastPositionMilliseconds / 1000) > watchCurrent.duration * 0.7) {
if(!watchCurrent.url.isNullOrEmpty()) {
StatePlaylists.instance.removeFromWatchLater(watchCurrent.url);
}
}
}
}
//Quality Selector data
private fun updateQualityFormatsOverlay(liveStreamVideoFormats : List<Format>?, liveStreamAudioFormats : List<Format>?) {
val v = video ?: return;

View file

@ -90,6 +90,18 @@ class StatePlaylists {
StateDownloads.instance.checkForOutdatedPlaylistVideos(VideoDownload.GROUP_WATCHLATER);
}
}
fun getWatchLaterFromUrl(url: String): SerializedPlatformVideo?{
synchronized(_watchlistStore) {
val order = _watchlistOrderStore.getAllValues();
return _watchlistStore.getItems().firstOrNull { it.url == url };
}
}
fun removeFromWatchLater(url: String) {
val item = getWatchLaterFromUrl(url);
if(item != null){
removeFromWatchLater(item);
}
}
fun removeFromWatchLater(video: SerializedPlatformVideo) {
synchronized(_watchlistStore) {
_watchlistStore.delete(video);

View file

@ -399,6 +399,8 @@
<string name="allow_under_cutout_description">Allow video to go underneath the screen cutout in full-screen.\nMay require restart</string>
<string name="autoplay">Enable autoplay by default</string>
<string name="autoplay_description">Autoplay will be enabled by default whenever you watch a video</string>
<string name="delete_watchlist_on_finish">Delete from WatchLater when watched</string>
<string name="delete_watchlist_on_finish_description">After you leave a video that you mostly watched, it will be removed from watch later.</string>
<string name="allow_full_screen_portrait">Allow fullscreen portrait</string>
<string name="background_switch_audio">Switch to Audio in Background</string>
<string name="background_switch_audio_description">Optimize bandwidth usage by switching to audio-only stream in background if available, may cause stutter</string>