From f6cd5c97444976385bf1ea9864c27d7b5768e037 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 2 May 2015 17:49:29 +0200 Subject: [PATCH] changed playback a bit --- default.py | 6 ++-- resources/lib/DownloadUtils.py | 14 +++++---- resources/lib/KodiMonitor.py | 53 ++++++++++++++++++++++++++++++++-- resources/lib/PlaybackUtils.py | 18 +----------- service.py | 14 +++++++-- 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/default.py b/default.py index cc912b84..fdecf1a4 100644 --- a/default.py +++ b/default.py @@ -27,10 +27,8 @@ except: id=None if mode != None and mode == "play": - pass - #PlaybackUtils().PLAY(id) - #WINDOW.setProperty('GUIPLAY', str(id)) # set window prop - #xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, None) + xbmcplugin.endOfDirectory(int(sys.argv[1]),True,False,True) + WINDOW.setProperty('GUIPLAY', str(id)) # set window prop elif sys.argv[1] == "reset": utils.reset() else: diff --git a/resources/lib/DownloadUtils.py b/resources/lib/DownloadUtils.py index 479da4d6..22165188 100644 --- a/resources/lib/DownloadUtils.py +++ b/resources/lib/DownloadUtils.py @@ -149,19 +149,23 @@ class DownloadUtils(): self.logMsg("=== ENTER downloadUrl ===", 2) - WINDOW = self.WINDOW + WINDOW = xbmcgui.Window( 10000 ) timeout = self.timeout default_link = "" + + username = WINDOW.getProperty('currUser') + userId = WINDOW.getProperty('userId%s' % username) + server = WINDOW.getProperty('server%s' % username) + url = url.replace("{server}", server, 1) + url = url.replace("{UserId}", userId, 1) + #url = "%s&api_key=%s" % (url, self.token) # If user is authenticated if (authenticate): # Get requests session s = self.s # Replace for the real values and append api_key - url = url.replace("{server}", self.server, 1) - url = url.replace("{UserId}", self.userId, 1) - #url = "%s&api_key=%s" % (url, self.token) - + self.logMsg("URL: %s" % url, 2) # Prepare request if type == "GET": diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index 7251e444..988bb1df 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -53,8 +53,57 @@ class Kodi_Monitor(xbmc.Monitor): url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % embyid result = downloadUtils.downloadUrl(url) - #launch playbackutils - PlaybackUtils().PLAY(result) + userData = result[u'UserData'] + + playurl = PlayUtils().getPlayUrl(server, embyid, result) + thumbPath = API().getArtwork(result, "Primary") + + watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, embyid) + positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, embyid) + deleteurl = "%s/mediabrowser/Items/%s" % (server, embyid) + + listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath) + self.setListItemProps(server, id, listItem, result) + + # Can not play virtual items + if (result.get("LocationType") == "Virtual"): + xbmcgui.Dialog().ok(self.language(30128), self.language(30129)) + + # set the current playing info + WINDOW.setProperty(playurl+"watchedurl", watchedurl) + WINDOW.setProperty(playurl+"positionurl", positionurl) + WINDOW.setProperty(playurl+"deleteurl", "") + WINDOW.setProperty(playurl+"deleteurl", deleteurl) + if result[u'Type']=="Episode": + WINDOW.setProperty(playurl+"refresh_id", result[u'SeriesId']) + else: + WINDOW.setProperty(playurl+"refresh_id", embyid) + + WINDOW.setProperty(playurl+"runtimeticks", str(result[u'RunTimeTicks'])) + WINDOW.setProperty(playurl+"type", result[u'Type']) + WINDOW.setProperty(playurl+"item_id", embyid) + + if PlayUtils().isDirectPlay(result) == True: + playMethod = "DirectPlay" + else: + playMethod = "Transcode" + + WINDOW.setProperty(playurl+"playmethod", playMethod) + + if result.get("Type")=="Episode": + WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) + else: + WINDOW.setProperty(playurl+"refresh_id", id) + + mediaSources = result[u'MediaSources'] + if(mediaSources != None): + if mediaSources[0].get('DefaultAudioStreamIndex') != None: + WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0][u'DefaultAudioStreamIndex'])) + if mediaSources[0].get('DefaultSubtitleStreamIndex') != None: + WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0][u'DefaultSubtitleStreamIndex'])) + + # start the playback + PlaybackUtils().PLAY(id) if method == "VideoLibrary.OnUpdate": jsondata = json.loads(data) diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py index 7dd15e18..6ebf465e 100644 --- a/resources/lib/PlaybackUtils.py +++ b/resources/lib/PlaybackUtils.py @@ -62,22 +62,8 @@ class PlaybackUtils(): # seekTime = int(round(kodiItem['resume'].get("position"))) playurl = PlayUtils().getPlayUrl(server, id, result) - - isStrmFile = False thumbPath = API().getArtwork(result, "Primary") - #workaround for when the file to play is a strm file itself - if playurl.endswith(".strm"): - isStrmFile = True - tempPath = os.path.join(addondir,"library","temp.strm") - xbmcvfs.copy(playurl, tempPath) - sfile = open(tempPath, 'r') - playurl = sfile.readline() - sfile.close() - xbmcvfs.delete(tempPath) - WINDOW.setProperty("virtualstrm", id) - WINDOW.setProperty("virtualstrmtype", result.get("Type")) - listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath) self.setListItemProps(server, id, listItem, result) @@ -130,9 +116,7 @@ class PlaybackUtils(): if mediaSources[0].get('DefaultSubtitleStreamIndex') != None: WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex'))) - #this launches the playback - #artwork only works with both resolvedurl and player command - #xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) + #launch the playback xbmc.Player().play(playurl,listItem) def setArt(self, list,name,path): diff --git a/service.py b/service.py index 9baa934e..c8f57a03 100644 --- a/service.py +++ b/service.py @@ -68,11 +68,19 @@ class Service(): if self.KodiMonitor.waitForAbort(1): # Abort was requested while waiting. We should exit break - + + #detection that file needs to be playback if WINDOW.getProperty("GUIPLAY") != "": + downloadUtils = DownloadUtils() id = WINDOW.getProperty("GUIPLAY") WINDOW.setProperty("GUIPLAY", "") - PlaybackUtils().PLAY(id) + WINDOW = xbmcgui.Window( 10000 ) + username = WINDOW.getProperty('currUser') + userid = WINDOW.getProperty('userId%s' % username) + server = WINDOW.getProperty('server%s' % username) + url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % id + result = downloadUtils.downloadUrl(url) + PlaybackUtils().PLAY(result) if xbmc.Player().isPlaying(): try: @@ -122,7 +130,7 @@ class Service(): if(libSync): startupComplete = True else: - if self.KodiMonitor.waitForAbort(10): + if self.KodiMonitor.waitForAbort(1): # Abort was requested while waiting. We should exit break WebSocketThread().processPendingActions()