Skip to content

Commit

Permalink
Force browse to media after Switchback playback
Browse files Browse the repository at this point in the history
  • Loading branch information
bossanova808 committed Nov 4, 2024
1 parent ea7e980 commit 20687ae
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.switchback" name="Switchback" version="0.0.1" provider-name="bossanova808">
<addon id="plugin.switchback" name="Switchback" version="1.0.0" provider-name="bossanova808">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.bossanova808" version="1.0.0"/>
Expand Down
5 changes: 3 additions & 2 deletions resources/lib/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 44 additions & 7 deletions resources/lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -71,6 +72,7 @@ def onAVStarted(self):
"VideoPlayer.Title",
"VideoPlayer.Year",
"VideoPlayer.TVShowTitle",
"VideoPlayer.TvShowDBID",
"VideoPlayer.Season",
"VideoPlayer.Episode",
# PVR
Expand All @@ -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', "")
Expand All @@ -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"
Expand Down Expand Up @@ -163,12 +166,44 @@ 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':
Logger.debug("Force browsing to library location of just finished playback")
if Store.current_playback.type == "episode":
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}', 'return'],
}
})
send_kodi_json(f'Browse to episode of {Store.current_playback.showtitle}', command)
elif Store.current_playback.type == "movie":
Logger.debug("%%% HERE!")
command = json.dumps({
"jsonrpc": "2.0",
"id": 1,
"method": "GUI.ActivateWindow",
"params": {
"window": "videos",
"parameters": [f'videodb://movies/titles/{Store.current_playback.dbid}', '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
Expand All @@ -195,3 +230,5 @@ def onPlaybackFinished():

# Finally, Save the playback list to file
Store.save_switchback_list()


16 changes: 11 additions & 5 deletions resources/lib/switchback_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 20687ae

Please sign in to comment.