diff --git a/resources/lib/playback.py b/resources/lib/playback.py index f501948..b1a14db 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -8,9 +8,10 @@ class Playback: Stores whatever data we can grab about a Kodi Playback so that we can display it nicely in the Switchback list """ file:str = None - type:str = None - source:str = None + type:str = None # episode, movie, video, song + source:str = None # kodi_library, pvr_live, media_file dbid:int = None + tvshowdbid: int = None title:str = None thumbnail:str = None fanart:str = None diff --git a/resources/lib/player.py b/resources/lib/player.py index c8f3712..29a0c72 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -60,6 +60,7 @@ def onAVStarted(self): "id": "XBMC.GetInfoLabels", "method": "XBMC.GetInfoLabels", "params": {"labels": [ + "Player.Folderpath", "Player.Art(thumb)", "Player.Art(poster)", "Player.Art(fanart)", @@ -71,6 +72,7 @@ def onAVStarted(self): "VideoPlayer.Title", "VideoPlayer.Year", "VideoPlayer.TVShowTitle", + "VideoPlayer.TvShowDBID", "VideoPlayer.Season", "VideoPlayer.Episode", # PVR @@ -94,12 +96,12 @@ def onAVStarted(self): # WHAT IS THE SOURCE - Kodi Library (...get DBID), PVR, or Non-Library Media? Store.current_playback.dbid = int(properties.get(f'{stub}Player.DBID')) if properties.get(f'{stub}Player.DBID') else None if Store.current_playback.dbid: - Store.current_playback.source = "Kodi Library" + Store.current_playback.source = "kodi_library" elif properties['VideoPlayer.ChannelName']: - Store.current_playback.source = "PVR" + Store.current_playback.source = "pvr_live" else: # Logger.info("Not from Kodi library, not PVR, not an http source - must be a non library media file") - Store.current_playback.source = "Media File" + Store.current_playback.source = "file" # TITLE Store.current_playback.title = properties.get(f'{stub}Player.Title', "") @@ -122,17 +124,18 @@ def onAVStarted(self): Store.current_playback.thumbnail = unquote(properties['Player.Art(fanart)']).replace("image://", "").rstrip("/") # DETERMINE THE MEDIA TYPE - not 100% on the logic here... - if properties['Player.Art(tvshow.poster)']: + if properties['VideoPlayer.TVShowTitle']: Store.current_playback.type = "episode" + Store.current_playback.tvshowdbid = int(properties['VideoPlayer.TvShowDBID']) if properties.get('VideoPlayer.TvShowDBID') else None elif properties['VideoPlayer.ChannelName']: Store.current_playback.type = "video" if 'channels' in Store.current_playback.file: Store.current_playback.source = "pvr.live" elif 'recordings' in Store.current_playback.file: Store.current_playback.source = "pvr.recording" - elif properties['Player.Art(poster)']: + elif stub == 'Video' and Store.current_playback.dbid: Store.current_playback.type = "movie" - elif stub == 'Video': + elif stub == "Video": Store.current_playback.type = "video" else: Store.current_playback.type = "song" @@ -163,12 +166,40 @@ def onPlaybackFinished(): """ Playback has finished, so update our Switchback List """ - Logger.debug("onPlaybackFinished") + Logger.debug("onPlaybackFinished with Store.current_playback:") if not Store.current_playback or not Store.current_playback.file: Logger.error("No current playback details available...not recording this playback") return + Logger.debug(Store.current_playback) + + switchback_playback = HOME_WINDOW.getProperty('Switchback') + HOME_WINDOW.clearProperty('Switchback') + if switchback_playback == 'true': + if Store.current_playback.type == "episode": + command = json.dumps({ + "jsonrpc": "2.0", + "id": 1, + "method": "GUI.ActivateWindow", + "params": { + "window": "videos", + "parameters": [f'videodb://tvshows/titles/{Store.current_playback.dbid}'], + } + }) + send_kodi_json(f'Browse to episode of {Store.current_playback.showtitle}', command) + elif Store.current_playback.type == "movie": + command = json.dumps({ + "jsonrpc": "2.0", + "id": 1, + "method": "GUI.ActivateWindow", + "params": { + "window": "videos", + "parameters": [f'videodb://movies/titles/{Store.current_playback.dbid}'], + } + }) + send_kodi_json(f'Browse to movie {Store.current_playback.title}', command) + Logger.debug(Store.switchback_list) # This approach keeps all the details from the original playback @@ -195,3 +226,5 @@ def onPlaybackFinished(): # Finally, Save the playback list to file Store.save_switchback_list() + + diff --git a/resources/lib/switchback_plugin.py b/resources/lib/switchback_plugin.py index 0a693b4..51fb7d5 100644 --- a/resources/lib/switchback_plugin.py +++ b/resources/lib/switchback_plugin.py @@ -2,11 +2,11 @@ import xbmc import xbmcplugin - +import json from bossanova808.constants import * from bossanova808.logger import Logger from bossanova808.notify import Notify -from bossanova808.utilities import footprints +from bossanova808.utilities import * # noinspection PyPackages from .store import Store from infotagger.listitem import ListItemInfoTag @@ -38,7 +38,8 @@ def create_kodi_list_item_from_playback(playback, index=None, offscreen=False): tag = ListItemInfoTag(list_item, 'video') infolabels = { 'mediatype': playback.type, - 'dbid': playback.dbid, + 'dbid': playback.tvshowdbid, + 'tvshowdbid': playback.tvshowdbid, 'title': playback.title, 'year': playback.year, 'tvshowtitle': playback.showtitle, @@ -86,9 +87,14 @@ def run(args): # Switchback mode - easily swap between switchback_list[0] and switchback_list[1] if mode and mode[0] == "switchback": try: - Logger.info(f"Playing previous file (Store.switchback_list[1]) {Store.switchback_list[1].file}") - list_item = create_kodi_list_item_from_playback(Store.switchback_list[1], offscreen=True) + switchback = Store.switchback_list[1] + Logger.info(f"Playing previous file (Store.switchback_list[1]) {switchback.file}") + list_item = create_kodi_list_item_from_playback(switchback, offscreen=True) Notify.kodi_notification(f"{list_item.getLabel()}", 3000, ADDON_ICON) + + # Set a property so we can force browse later at the end of playback + HOME_WINDOW.setProperty('Switchback', 'true') + xbmcplugin.setResolvedUrl(plugin_instance, True, list_item) except IndexError: Notify.error("No previous item found to play")