From ebf2f290975f1386f56e27cacca66b0fa75eba28 Mon Sep 17 00:00:00 2001 From: jdaalder Date: Mon, 11 Nov 2024 10:42:40 +1100 Subject: [PATCH] Target nexus due to infotagger dependency --- addon.xml | 2 +- resources/lib/playback.py | 5 +-- resources/lib/player.py | 53 ++++++++++++++++++++++++++---- resources/lib/switchback_plugin.py | 18 ++++++---- 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/addon.xml b/addon.xml index c11b532..fde27da 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + 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..48f6116 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,46 @@ 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": + Logger.debug("Force browsing to tvshow/season/ of just finished playback") + command = json.dumps({ + "jsonrpc": "2.0", + "id": 1, + "method": "GUI.ActivateWindow", + "params": { + "window": "videos", + # DBID is used here, not the expected TvShowDBID as I can't seem to get that infolabel set for a Switchback playback?? + # See switchback_plugin.py - 'dbid': playback.dbid if playback.type != 'episode' else playback.tvshowdbid, + "parameters": [f'videodb://tvshows/titles/{Store.current_playback.dbid}/{Store.current_playback.season}'], + } + }) + send_kodi_json(f'Browse to episode of {Store.current_playback.showtitle}', command) + # @TODO - is is possible to force Kodi to browse to a particular movie? + # (i.e. a particular movie focussed within the movies list) + # elif Store.current_playback.type == "movie": + # Logger.debug("Force browsing to movie of just finished playback") + # command = json.dumps({ + # "jsonrpc": "2.0", + # "id": 1, + # "method": "GUI.ActivateWindow", + # "params": { + # "window": "videos", + # "parameters": [f'videodb://movies/titles/', 'return'], + # } + # }) + # 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 +232,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..cc43305 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.dbid if playback.type != 'episode' else playback.tvshowdbid, + 'tvshowdbid': playback.tvshowdbid, 'title': playback.title, 'year': playback.year, 'tvshowtitle': playback.showtitle, @@ -64,7 +65,7 @@ def create_kodi_list_item_from_playback(playback, index=None, offscreen=False): # index can be zero, so in this case, must explicitly check against None! if index is not None: - list_item.addContextMenuItems([(LANGUAGE(32004), "RunPlugin(plugin://script.switchback?mode=delete&index=" + str(index) + ")")]) + list_item.addContextMenuItems([(LANGUAGE(32004), "RunPlugin(plugin://plugin.switchback?mode=delete&index=" + str(index) + ")")]) return list_item @@ -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")