Skip to content

Commit bee210f

Browse files
authored
Merge pull request #5 from bossanova808/tweaks-before-release
Filter watched and update resume points on list load
2 parents 5d00d15 + 60b4c63 commit bee210f

5 files changed

Lines changed: 62 additions & 8 deletions

File tree

resources/language/resource.language.en_gb/strings.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ msgstr ""
4444
msgctxt "#32009"
4545
msgid "Enable Switchback context menu items?"
4646
msgstr ""
47+
48+
msgctxt "#32010"
49+
msgid "Automatically filter watched items out of the Switchback list?"
50+
msgstr ""
51+
52+
msgctxt "#32011"
53+
msgid "(After a switchback playback) force browse to episode in library?"
54+
msgstr ""

resources/lib/playback.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import 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
1313
from bossanova808.logger import Logger
1414
# noinspection PyUnresolvedReferences
1515
from infotagger.listitem import ListItemInfoTag
1616

17-
1817
@dataclass
1918
class 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
"""

resources/lib/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def onPlaybackFinished():
8484

8585
# If we Switchbacked to a library episode, force Kodi to browse to the Show/Season
8686
# (NB it is not possible to force Kodi to go to movies and focus a specific movie as far as I can determine)
87-
if switchback_playback:
87+
if Store.episode_force_browse and switchback_playback:
8888
if Store.current_playback.type == "episode" and Store.current_playback.source == "kodi_library":
8989
Logger.info("Force browsing to tvshow/season of just finished playback")
9090
Logger.debug(f'flatten tvshows {Store.flatten_tvshows} totalseasons {Store.current_playback.totalseasons} dbid {Store.current_playback.dbid} tvshowdbid {Store.current_playback.tvshowdbid}')

resources/lib/store.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Store:
1818
kodi_event_monitor = None
1919
kodi_player = None
2020
# Holds our playlist of things played back, in first is the latest order
21-
switchback = PlaybackList([], xbmcvfs.translatePath(os.path.join(PROFILE, "switchback.json")))
21+
switchback = None
2222
# When something is being played back, store the details
2323
current_playback = None
2424
# Playbacks are of these possible types
@@ -28,6 +28,9 @@ class Store:
2828
save_across_sessions = ADDON.getSettingBool('save_across_sessions')
2929
maximum_list_length = ADDON.getSettingInt('maximum_list_length')
3030
enable_context_menu = ADDON.getSettingBool('enable_context_menu')
31+
episode_force_browse = ADDON.getSettingBool('episode_force_browse')
32+
remove_watched_playbacks = ADDON.getSettingBool('remove_watched_playbacks')
33+
3134
# GUI Settings - to work out how to force browse to a show after a switchback initiated playback
3235
flatten_tvshows = None
3336

@@ -38,9 +41,11 @@ def __init__(self):
3841
"""
3942
Store.load_config_from_settings()
4043
Store.load_config_from_kodi_settings()
44+
Store.switchback = PlaybackList([], xbmcvfs.translatePath(os.path.join(PROFILE, "switchback.json")), Store.remove_watched_playbacks)
4145
Store.switchback.load_or_init()
4246
Store.update_switchback_context_menu()
4347

48+
4449
@staticmethod
4550
def load_config_from_settings():
4651
"""
@@ -54,6 +59,10 @@ def load_config_from_settings():
5459
Logger.info(f"Save across sessions is: {Store.save_across_sessions}")
5560
Store.enable_context_menu = ADDON.getSettingBool('enable_context_menu')
5661
Logger.info(f"Enable context menu is: {Store.enable_context_menu}")
62+
Store.remove_watched_playbacks = ADDON.getSettingBool('remove_watched_playbacks')
63+
Logger.info(f"Remove watched playbacks is: {Store.remove_watched_playbacks}")
64+
Store.episode_force_browse = ADDON.getSettingBool('episode_force_browse')
65+
Logger.info(f"Episode force browse is: {Store.episode_force_browse}")
5766

5867
@staticmethod
5968
def load_config_from_kodi_settings():

resources/settings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
<default>true</default>
2121
<control type="toggle"/>
2222
</setting>
23+
<setting id="remove_watched_playbacks" type="boolean" label="32010" help="">
24+
<level>0</level>
25+
<default>true</default>
26+
<control type="toggle"/>
27+
</setting>
28+
<setting id="episode_force_browse" type="boolean" label="32011" help="">
29+
<level>0</level>
30+
<default>false</default>
31+
<control type="toggle"/>
32+
</setting>
2333
</group>
2434
</category>
2535
</section>

0 commit comments

Comments
 (0)