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,31 @@ 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+ for item in self .list :
393+ if item .dbid :
394+ # Is it marked as watched in the DB?
395+ playcount = get_playcount (item .type , item .dbid )
396+ if playcount and playcount > 0 :
397+ list_needs_save = True
398+ Logger .debug (f"Filtering watched playback from the list: [{ item .pluginlabel } ]" )
399+ self .remove_playbacks_of_path (item .path )
400+
401+ # Update resume points with current data from the Kodi library (consider e.g. shared library scenarios)
402+ for item in self .list :
403+ if item .dbid :
404+ library_resume_point = get_resume_point (item .type , item .dbid )
405+ if library_resume_point != item .resumetime :
406+ Logger .debug (f"Retrieved library resume point: { library_resume_point } != existing list resume point { item .resumetime } - updating playback list" )
407+ list_needs_save = True
408+ item .resumetime = library_resume_point
409+
410+ if list_needs_save :
411+ self .save_to_file ()
391412
392413 def save_to_file (self ) -> None :
393414 """
0 commit comments