From e530575d91bdaf71d766e9fdf36835811bb22ee6 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 9 Jan 2018 21:03:32 -0600 Subject: [PATCH] Clear playlist if last item in list --- resources/lib/playbackutils.py | 8 ++++++++ resources/lib/player.py | 16 ++++++++-------- resources/lib/playlist.py | 8 ++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index ca434dde..94d95d0e 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -85,6 +85,14 @@ class PlaybackUtils(object): index = max(self.playlist.getposition(), 0) + 1 # Can return -1 force_play = False + ##### Track end of playlist + playlist_verify = playlist.Playlist().verify_playlist() + try: + if playlist_verify['result']['limits']['end'] >= index: + window('emby.playlist_end', value="true") + except Exception: + pass + # Stack: [(url, listitem), (url, ...), ...] self.stack[0][1].setPath(self.stack[0][0]) try: diff --git a/resources/lib/player.py b/resources/lib/player.py index 71af6671..dd3838c8 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -413,14 +413,6 @@ class Player(xbmc.Player): # Will be called when user stops xbmc playing a file log.debug("ONPLAYBACK_STOPPED") window('emby_customPlaylist.seektime', clear=True) - - if self.currentFile in self.played_info: - log.info("Clear playlist.") - if self.played_info[self.currentFile]['Type'] == "Audio": - xbmc.PlayList(xbmc.PLAYLIST_MUSIC).clear() - else: - xbmc.PlayList(xbmc.PLAYLIST_VIDEO).clear() - self.stopAll() @log_error() @@ -453,6 +445,14 @@ class Player(xbmc.Player): media_type = data['Type'] playMethod = data['playmethod'] + if window('emby.playlist_end', value="true"): + window('emby.playlist_end', clear=True) + + if media_type == "Audio": + xbmc.PlayList(xbmc.PLAYLIST_MUSIC).clear() + else: + xbmc.PlayList(xbmc.PLAYLIST_VIDEO).clear() + # Prevent manually mark as watched in Kodi monitor window('emby_skipWatched%s' % itemid, value="true") diff --git a/resources/lib/playlist.py b/resources/lib/playlist.py index 1c47bac2..71c95619 100644 --- a/resources/lib/playlist.py +++ b/resources/lib/playlist.py @@ -144,8 +144,12 @@ class Playlist(object): log.debug(JSONRPC('Playlist.Insert').execute(params)) @classmethod - def verify_playlist(cls): - log.info(JSONRPC('Playlist.GetItems').execute({'playlistid': 1})) + def verify_playlist(cls, playlist_id=1): + + result = JSONRPC('Playlist.GetItems').execute({'playlistid': playlist_id}) + log.info(result) + + return result @classmethod def remove_from_playlist(cls, position):