Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ msgstr ""
msgctxt "#32009"
msgid "Enable Switchback context menu items?"
msgstr ""

msgctxt "#32010"
msgid "Automatically filter watched items out of the Switchback list?"
msgstr ""

msgctxt "#32011"
msgid "(After a switchback playback) force browse to episode in library?"
msgstr ""
39 changes: 33 additions & 6 deletions resources/lib/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import xbmcvfs

# noinspection PyPackages
from bossanova808.utilities import clean_art_url, send_kodi_json
from bossanova808.utilities import clean_art_url, send_kodi_json, get_resume_point, get_playcount
# noinspection PyPackages
from bossanova808.logger import Logger
# noinspection PyUnresolvedReferences
from infotagger.listitem import ListItemInfoTag


@dataclass
class Playback:
"""
Expand All @@ -23,8 +22,6 @@ class Playback:
file: Optional[str] = None
path: Optional[str] = None
type: Optional[str] = None # episode, movie, video (per Kodi types) - song is the other type, but Switchback supports video only
# Seems to be a newer version of the above, but unclear how/when to use, and what about music??
# mediatype: str | None = None # mediatype: string - "video", "movie", "tvshow", "season", "episode" or "musicvideo"
source: Optional[str] = None # kodi_library, pvr_live, pvr_recording, addon, file
dbid: Optional[int] = None
tvshowdbid: Optional[int] = None
Expand Down Expand Up @@ -345,6 +342,7 @@ class PlaybackList:
"""
list: List[Playback]
file: str
remove_watched_playbacks: bool = False

def toJson(self) -> str:
"""
Expand Down Expand Up @@ -386,8 +384,37 @@ def load_or_init(self) -> None:
except json.JSONDecodeError:
Logger.error(f"JSONDecodeError - Unable to parse PlaybackList file [{self.file}] - creating empty PlaybackList & file")
self.init()
# Let unexpected exceptions propagate
# Logger.info("PlaybackList is:", self.list)

list_needs_save = False

# If the user wants to filter out watched items from the list
if self.remove_watched_playbacks:
paths_to_remove = []
for item in list(self.list):
if item.dbid:
# Is it marked as watched in the DB?
playcount = get_playcount(item.type, item.dbid)
if playcount and playcount > 0:
list_needs_save = True
Logger.debug(f"Filtering watched playback from the list: [{item.pluginlabel}]")
paths_to_remove.append(item.path)

if paths_to_remove:
list_needs_save = True
for path in paths_to_remove:
self.remove_playbacks_of_path(path)

# Update resume points with current data from the Kodi library (consider e.g. shared library scenarios)
for item in self.list:
if item.dbid:
library_resume_point = get_resume_point(item.type, item.dbid)
if library_resume_point != item.resumetime:
Logger.debug(f"Retrieved library resume point: {library_resume_point} != existing list resume point {item.resumetime} - updating playback list")
list_needs_save = True
item.resumetime = library_resume_point

if list_needs_save:
self.save_to_file()

def save_to_file(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def onPlaybackFinished():

# If we Switchbacked to a library episode, force Kodi to browse to the Show/Season
# (NB it is not possible to force Kodi to go to movies and focus a specific movie as far as I can determine)
if switchback_playback:
if Store.episode_force_browse and switchback_playback:
if Store.current_playback.type == "episode" and Store.current_playback.source == "kodi_library":
Logger.info("Force browsing to tvshow/season of just finished playback")
Logger.debug(f'flatten tvshows {Store.flatten_tvshows} totalseasons {Store.current_playback.totalseasons} dbid {Store.current_playback.dbid} tvshowdbid {Store.current_playback.tvshowdbid}')
Expand Down
11 changes: 10 additions & 1 deletion resources/lib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Store:
kodi_event_monitor = None
kodi_player = None
# Holds our playlist of things played back, in first is the latest order
switchback = PlaybackList([], xbmcvfs.translatePath(os.path.join(PROFILE, "switchback.json")))
switchback = None
# When something is being played back, store the details
current_playback = None
# Playbacks are of these possible types
Expand All @@ -28,6 +28,9 @@ class Store:
save_across_sessions = ADDON.getSettingBool('save_across_sessions')
maximum_list_length = ADDON.getSettingInt('maximum_list_length')
enable_context_menu = ADDON.getSettingBool('enable_context_menu')
episode_force_browse = ADDON.getSettingBool('episode_force_browse')
remove_watched_playbacks = ADDON.getSettingBool('remove_watched_playbacks')

# GUI Settings - to work out how to force browse to a show after a switchback initiated playback
flatten_tvshows = None

Expand All @@ -38,9 +41,11 @@ def __init__(self):
"""
Store.load_config_from_settings()
Store.load_config_from_kodi_settings()
Store.switchback = PlaybackList([], xbmcvfs.translatePath(os.path.join(PROFILE, "switchback.json")), Store.remove_watched_playbacks)
Store.switchback.load_or_init()
Store.update_switchback_context_menu()


@staticmethod
def load_config_from_settings():
"""
Expand All @@ -54,6 +59,10 @@ def load_config_from_settings():
Logger.info(f"Save across sessions is: {Store.save_across_sessions}")
Store.enable_context_menu = ADDON.getSettingBool('enable_context_menu')
Logger.info(f"Enable context menu is: {Store.enable_context_menu}")
Store.remove_watched_playbacks = ADDON.getSettingBool('remove_watched_playbacks')
Logger.info(f"Remove watched playbacks is: {Store.remove_watched_playbacks}")
Store.episode_force_browse = ADDON.getSettingBool('episode_force_browse')
Logger.info(f"Episode force browse is: {Store.episode_force_browse}")

@staticmethod
def load_config_from_kodi_settings():
Expand Down
10 changes: 10 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
<default>true</default>
<control type="toggle"/>
</setting>
<setting id="remove_watched_playbacks" type="boolean" label="32010" help="">
<level>0</level>
<default>true</default>
<control type="toggle"/>
</setting>
<setting id="episode_force_browse" type="boolean" label="32011" help="">
<level>0</level>
<default>false</default>
<control type="toggle"/>
</setting>
</group>
</category>
</section>
Expand Down