diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index b4f841d7..a96639f2 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1916,7 +1916,7 @@ class API(): def getExtras(self): """ - Returns a list of trailer and extras from PMS XML. Returns None if + Returns a list of trailer and extras from PMS XML. Returns [] if no extras are found. Extratypes: '1': Trailer @@ -1932,9 +1932,9 @@ class API(): 'year': """ extras = self.item[0].find('Extras') - if not extras: - return None elements = [] + if not extras: + return elements for extra in extras: # Trailer: key = extra.attrib['key'] diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 0edf1a96..dd76b2db 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -327,8 +327,8 @@ class DownloadUtils(): self.logMsg("Received an XML response for: %s" % url, 2) return r except: - self.logMsg("Unable to convert the response for: %s" % url, 1) - self.logMsg("Content-type was: %s" % r.headers['content-type'], 1) + self.logMsg("Unable to convert the response for: %s" % url, 2) + self.logMsg("Content-type was: %s" % r.headers['content-type'], 2) else: r.raise_for_status() diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 49836010..5c3cdd61 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -352,14 +352,13 @@ class Movies(Items): # Find one trailer trailer = None extras = API.getExtras() - if extras: - for item in extras: - # Only get 1st trailer element - if item['extraType'] == '1': - trailer = item['key'] - trailer = "plugin://plugin.video.plexkodiconnect/trailer/?id=%s&mode=play" % trailer - self.logMsg("Trailer for %s: %s" % (itemid, trailer), 2) - break + for item in extras: + # Only get 1st trailer element + if item['extraType'] == '1': + trailer = item['key'] + trailer = "plugin://plugin.video.plexkodiconnect/trailer/?id=%s&mode=play" % trailer + self.logMsg("Trailer for %s: %s" % (itemid, trailer), 2) + break ##### GET THE FILE AND PATH ##### playurl = API.getFilePath() diff --git a/resources/lib/player.py b/resources/lib/player.py index b6d25e19..a9a5ef7e 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -13,6 +13,8 @@ import downloadutils import kodidb_functions as kodidb import websocket_client as wsc +from urllib import urlencode + ################################################################################################# @@ -260,6 +262,7 @@ class Player(xbmc.Player): playTime = data['currentPosition'] playMethod = data['playmethod'] paused = data.get('paused', False) + duration = data.get('runtime', '') # Get playback volume @@ -281,17 +284,29 @@ class Player(xbmc.Player): muted = result.get('muted') # Postdata for the websocketclient report - postdata = { + # postdata = { - 'QueueableMediaTypes': "Video", - 'CanSeek': True, - 'ItemId': itemId, - 'MediaSourceId': itemId, - 'PlayMethod': playMethod, - 'PositionTicks': int(playTime * 10000000), - 'IsPaused': paused, - 'VolumeLevel': volume, - 'IsMuted': muted + # 'QueueableMediaTypes': "Video", + # 'CanSeek': True, + # 'ItemId': itemId, + # 'MediaSourceId': itemId, + # 'PlayMethod': playMethod, + # 'PositionTicks': int(playTime * 10000000), + # 'IsPaused': paused, + # 'VolumeLevel': volume, + # 'IsMuted': muted + # } + if paused == 'stopped': + state = 'stopped' + elif paused == 'True': + state = 'paused' + else: + state = 'playing' + postdata = { + 'ratingKey': itemId, + 'state': state, # 'stopped', 'paused', 'buffering', 'playing' + 'time': int(playTime) * 1000, + 'duration': int(duration) * 1000 } if playMethod == "Transcode": @@ -362,9 +377,11 @@ class Player(xbmc.Player): data['SubtitleStreamIndex'], postdata['SubtitleStreamIndex'] = [""] * 2 # Report progress via websocketclient - postdata = json.dumps(postdata) + # postdata = json.dumps(postdata) self.logMsg("Report: %s" % postdata, 2) - self.ws.sendProgressUpdate(postdata) + # self.ws.sendProgressUpdate(postdata) + url = "{server}/:/timeline?" + urlencode(postdata) + self.doUtils.downloadUrl(url, type="GET") def onPlayBackPaused( self ): @@ -399,7 +416,12 @@ class Player(xbmc.Player): def onPlayBackStopped( self ): # Will be called when user stops xbmc playing a file + currentFile = self.currentFile self.logMsg("ONPLAYBACK_STOPPED", 2) + if self.played_info.get(currentFile): + self.played_info[currentFile]['paused'] = 'stopped' + self.reportPlayback() + xbmcgui.Window(10101).clearProperties() self.logMsg("Clear playlist properties.") self.stopAll()