88import xbmcvfs
99
1010# noinspection PyPackages
11- from bossanova808 .utilities import clean_art_url , send_kodi_json
11+ from bossanova808 .utilities import clean_art_url , send_kodi_json , get_resume_point , get_playcount
1212# noinspection PyPackages
1313from bossanova808 .logger import Logger
1414# noinspection PyUnresolvedReferences
1515from infotagger .listitem import ListItemInfoTag
1616
17-
1817@dataclass
1918class Playback :
2019 """
@@ -23,8 +22,6 @@ class Playback:
2322 file : Optional [str ] = None
2423 path : Optional [str ] = None
2524 type : Optional [str ] = None # episode, movie, video (per Kodi types) - song is the other type, but Switchback supports video only
26- # Seems to be a newer version of the above, but unclear how/when to use, and what about music??
27- # mediatype: str | None = None # mediatype: string - "video", "movie", "tvshow", "season", "episode" or "musicvideo"
2825 source : Optional [str ] = None # kodi_library, pvr_live, pvr_recording, addon, file
2926 dbid : Optional [int ] = None
3027 tvshowdbid : Optional [int ] = None
@@ -345,6 +342,7 @@ class PlaybackList:
345342 """
346343 list : List [Playback ]
347344 file : str
345+ remove_watched_playbacks : bool = False
348346
349347 def toJson (self ) -> str :
350348 """
@@ -386,8 +384,37 @@ def load_or_init(self) -> None:
386384 except json .JSONDecodeError :
387385 Logger .error (f"JSONDecodeError - Unable to parse PlaybackList file [{ self .file } ] - creating empty PlaybackList & file" )
388386 self .init ()
389- # Let unexpected exceptions propagate
390- # Logger.info("PlaybackList is:", self.list)
387+
388+ list_needs_save = False
389+
390+ # If the user wants to filter out watched items from the list
391+ if self .remove_watched_playbacks :
392+ paths_to_remove = []
393+ for item in list (self .list ):
394+ if item .dbid :
395+ # Is it marked as watched in the DB?
396+ playcount = get_playcount (item .type , item .dbid )
397+ if playcount and playcount > 0 :
398+ list_needs_save = True
399+ Logger .debug (f"Filtering watched playback from the list: [{ item .pluginlabel } ]" )
400+ paths_to_remove .append (item .path )
401+
402+ if paths_to_remove :
403+ list_needs_save = True
404+ for path in paths_to_remove :
405+ self .remove_playbacks_of_path (path )
406+
407+ # Update resume points with current data from the Kodi library (consider e.g. shared library scenarios)
408+ for item in self .list :
409+ if item .dbid :
410+ library_resume_point = get_resume_point (item .type , item .dbid )
411+ if library_resume_point != item .resumetime :
412+ Logger .debug (f"Retrieved library resume point: { library_resume_point } != existing list resume point { item .resumetime } - updating playback list" )
413+ list_needs_save = True
414+ item .resumetime = library_resume_point
415+
416+ if list_needs_save :
417+ self .save_to_file ()
391418
392419 def save_to_file (self ) -> None :
393420 """
0 commit comments