def PLAY(self, result, setup="service"): xbmc.log("PLAY Called") WINDOW = xbmcgui.Window(10000) username = WINDOW.getProperty('currUser') userid = WINDOW.getProperty('userId%s' % username) server = WINDOW.getProperty('server%s' % username) try: id = result["Id"] except: return # For split movies if u'PartCount' in result: partcount = result[u'PartCount'] # Get additional parts/playurl url = "{server}/mediabrowser/Videos/%s/AdditionalParts" % id parts = self.downloadUtils.downloadUrl(url) partsId = [id] for part in parts[u'Items']: partId = part[u'Id'] partsId.append(partId) self.PLAYAllItems(partsId, startPositionTicks=None) userData = result['UserData'] resume_result = 0 seekTime = 0 if userData.get("PlaybackPositionTicks") != 0: reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000 seekTime = reasonableTicks / 10000 playurl = PlayUtils().getPlayUrl(server, id, result) if playurl == False: #xbmcgui.Dialog().ok('Warning', 'Failed to launch playback.') xbmc.log("Failed to retrieve the playback path/url.") return thumbPath = API().getArtwork(result, "Primary") #if the file is a virtual strm file, we need to override the path by reading it's contents if playurl.endswith(".strm"): xbmc.log("virtual strm file file detected, starting playback with 3th party addon...") StrmTemp = "special://temp/temp.strm" xbmcvfs.copy(playurl, StrmTemp) playurl = open(xbmc.translatePath(StrmTemp), 'r').readline() listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath) # Can not play virtual items if (result.get("LocationType") == "Virtual"): xbmcgui.Dialog().ok(self.language(30128), self.language(30129)) watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id) positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, id) deleteurl = "%s/mediabrowser/Items/%s" % (server, id) # set the current playing info WINDOW.setProperty(playurl+"watchedurl", watchedurl) WINDOW.setProperty(playurl+"positionurl", positionurl) WINDOW.setProperty(playurl+"deleteurl", "") WINDOW.setProperty(playurl+"deleteurl", deleteurl) #show the additional resume dialog if launched from a widget if xbmc.getCondVisibility("Window.IsActive(home)"): if userData.get("PlaybackPositionTicks") != 0: reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000 seekTime = reasonableTicks / 10000 if seekTime != 0: displayTime = str(datetime.timedelta(seconds=seekTime)) display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)] resumeScreen = xbmcgui.Dialog() resume_result = resumeScreen.select(self.language(30105), display_list) if resume_result == 0: WINDOW.setProperty(playurl+"seektime", str(seekTime)) elif resume_result < 0: # User cancelled dialog xbmc.log("Emby player -> User cancelled resume dialog.") return else: WINDOW.clearProperty(playurl+"seektime") else: WINDOW.clearProperty(playurl+"seektime") else: # Playback started from library WINDOW.setProperty(playurl+"seektime", str(seekTime)) if result.get("Type")=="Episode": WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) else: WINDOW.setProperty(playurl+"refresh_id", id) WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) WINDOW.setProperty(playurl+"type", result.get("Type")) WINDOW.setProperty(playurl+"item_id", id) mediaSources = result.get("MediaSources") if(mediaSources != None): if mediaSources[0].get('DefaultAudioStreamIndex') != None: WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex'))) if mediaSources[0].get('DefaultSubtitleStreamIndex') != None: WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex'))) #launch the playback - only set the listitem props if we're not using the setresolvedurl approach if setup == "service": self.setListItemProps(server, id, listItem, result) xbmc.Player().play(playurl,listItem) elif setup == "default": #artwork only works from widgets (home screen) with player command as there is no listitem selected if xbmc.getCondVisibility("Window.IsActive(home)"): self.setListItemProps(server, id, listItem, result) xbmc.Player().play(playurl,listItem) else: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
def PLAY(self, id): xbmc.log("PLAY Called") port = addon.getSetting('port') host = addon.getSetting('ipaddress') server = host + ":" + port userid = self.downloadUtils.getUserId() jsonData = self.downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + id + "?format=json&ImageTypeLimit=1", suppress=False, popup=1 ) result = json.loads(jsonData) userData = result.get("UserData") resume_result = 0 seekTime = 0 #get the resume point from Kodi DB for a Movie kodiItem = ReadKodiDB().getKodiMovie(id) if kodiItem != None: seekTime = int(round(kodiItem['resume'].get("position"))) else: #get the resume point from Kodi DB for an episode episodeItem = ReadEmbyDB().getItem(id) if episodeItem != None and str(episodeItem["Type"]) == "Episode": kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(id,episodeItem["SeriesId"]) if kodiItem != None: 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) # Can not play virtual items if (result.get("LocationType") == "Virtual"): xbmcgui.Dialog().ok(self.language(30128), self.language(30129)) watchedurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayedItems/' + id positionurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayingItems/' + id deleteurl = 'http://' + server + '/mediabrowser/Items/' + id # 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 seekTime != 0: displayTime = str(datetime.timedelta(seconds=seekTime)) display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)] resumeScreen = xbmcgui.Dialog() resume_result = resumeScreen.select(self.language(30105), display_list) if resume_result == 0: WINDOW.setProperty(playurl+"seektime", str(seekTime)) else: WINDOW.clearProperty(playurl+"seektime") else: WINDOW.clearProperty(playurl+"seektime") if result.get("Type")=="Episode": WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) else: WINDOW.setProperty(playurl+"refresh_id", id) WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) WINDOW.setProperty(playurl+"type", result.get("Type")) WINDOW.setProperty(playurl+"item_id", id) if PlayUtils().isDirectPlay(result) == True: playMethod = "DirectPlay" else: playMethod = "Transcode" WINDOW.setProperty(playurl+"playmethod", playMethod) mediaSources = result.get("MediaSources") if(mediaSources != None): if mediaSources[0].get('DefaultAudioStreamIndex') != None: WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex'))) 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 if isStrmFile: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) else: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) if(addon.getSetting("addExtraPlaybackArt") == "true"): utils.logMsg("PLAY", "Doing second xbmc.Player().play to add extra art") xbmc.Player().play(playurl,listItem)
def PLAY(self, result, setup="service"): xbmc.log("PLAY Called") WINDOW = xbmcgui.Window(10000) username = WINDOW.getProperty('currUser') userid = WINDOW.getProperty('userId%s' % username) server = WINDOW.getProperty('server%s' % username) try: id = result["Id"] except: return userData = result['UserData'] # BOOKMARK - RESUME POINT timeInfo = API().getTimeInfo(result) jumpBackSec = int(utils.settings("resumeJumpBack")) seekTime = round(float(timeInfo.get('ResumeTime')), 6) if seekTime > jumpBackSec: # To avoid negative bookmark seekTime = seekTime - jumpBackSec itemsToPlay = [] # Check for intros if seekTime == 0: # if we have any play them when the movie/show is not being resumed # We can add the option right here url = "{server}/mediabrowser/Users/{UserId}/Items/%s/Intros?format=json&ImageTypeLimit=1&Fields=Etag" % id intros = self.downloadUtils.downloadUrl(url) if intros[u'TotalRecordCount'] == 0: pass else: for intro in intros[u'Items']: introId = intro[u'Id'] itemsToPlay.append(introId) # Add original item itemsToPlay.append(id) # For split movies if u'PartCount' in result: partcount = result[u'PartCount'] # Get additional parts/playurl url = "{server}/mediabrowser/Videos/%s/AdditionalParts" % id parts = self.downloadUtils.downloadUrl(url) for part in parts[u'Items']: partId = part[u'Id'] itemsToPlay.append(partId) if len(itemsToPlay) > 1: # Let's play the playlist return self.AddToPlaylist(itemsToPlay) playurl = PlayUtils().getPlayUrl(server, id, result) if playurl == False or WINDOW.getProperty('playurlFalse') == "true": WINDOW.clearProperty('playurlFalse') xbmc.log("Failed to retrieve the playback path/url.") return if WINDOW.getProperty("%splaymethod" % playurl) == "Transcode": # Transcoding, we pull every track to set before playback starts playurlprefs = self.audioSubsPref(playurl, result.get("MediaSources")) if playurlprefs: playurl = playurlprefs else: # User cancelled dialog return thumbPath = API().getArtwork(result, "Primary") #if the file is a virtual strm file, we need to override the path by reading it's contents if playurl.endswith(".strm"): xbmc.log("virtual strm file file detected, starting playback with 3th party addon...") StrmTemp = "special://temp/temp.strm" xbmcvfs.copy(playurl, StrmTemp) playurl = open(xbmc.translatePath(StrmTemp), 'r').readline() listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath) if WINDOW.getProperty("%splaymethod" % playurl) != "Transcode": # Only for direct play and direct stream # Append external subtitles to stream subtitleList = self.externalSubs(id, playurl, server, result.get('MediaSources')) listItem.setSubtitles(subtitleList) #pass # Can not play virtual items if (result.get("LocationType") == "Virtual"): xbmcgui.Dialog().ok(self.language(30128), self.language(30129)) watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id) positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, id) deleteurl = "%s/mediabrowser/Items/%s" % (server, id) # set the current playing info WINDOW.setProperty(playurl+"watchedurl", watchedurl) WINDOW.setProperty(playurl+"positionurl", positionurl) WINDOW.setProperty(playurl+"deleteurl", "") WINDOW.setProperty(playurl+"deleteurl", deleteurl) #show the additional resume dialog if launched from a widget if xbmc.getCondVisibility("Window.IsActive(home)"): if seekTime != 0: displayTime = str(datetime.timedelta(seconds=(int(seekTime)))) display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)] resumeScreen = xbmcgui.Dialog() resume_result = resumeScreen.select(self.language(30105), display_list) if resume_result == 0: listItem.setProperty('StartOffset', str(seekTime)) elif resume_result < 0: # User cancelled dialog xbmc.log("Emby player -> User cancelled resume dialog.") xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listItem) return if result.get("Type")=="Episode": WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) else: WINDOW.setProperty(playurl+"refresh_id", id) WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) WINDOW.setProperty(playurl+"type", result.get("Type")) WINDOW.setProperty(playurl+"item_id", id) #launch the playback - only set the listitem props if we're not using the setresolvedurl approach if setup == "service": self.setListItemProps(server, id, listItem, result) xbmc.Player().play(playurl,listItem) elif setup == "default": if xbmc.getCondVisibility("Window.IsActive(home)"): self.setListItemProps(server, id, listItem, result) xbmc.Player().play(playurl,listItem) else: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
def PLAY(self, id): xbmc.log("PLAY Called") 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 = self.downloadUtils.downloadUrl(url) userData = result[u'UserData'] resume_result = 0 seekTime = 0 #get the resume point from Kodi DB for a Movie kodiItem = ReadKodiDB().getKodiMovie(id) if kodiItem != None: seekTime = int(round(kodiItem['resume'].get("position"))) else: #get the resume point from Kodi DB for an episode episodeItem = ReadEmbyDB().getItem(id) if episodeItem != None and str(episodeItem["Type"]) == "Episode": kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(id,episodeItem["SeriesId"]) if kodiItem != None: 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) # Can not play virtual items if (result.get("LocationType") == "Virtual"): xbmcgui.Dialog().ok(self.language(30128), self.language(30129)) watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id) positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, id) deleteurl = "%s/mediabrowser/Items/%s" % (server, id) # 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 seekTime != 0: displayTime = str(datetime.timedelta(seconds=seekTime)) display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)] resumeScreen = xbmcgui.Dialog() resume_result = resumeScreen.select(self.language(30105), display_list) if resume_result == 0: WINDOW.setProperty(playurl+"seektime", str(seekTime)) else: WINDOW.clearProperty(playurl+"seektime") else: WINDOW.clearProperty(playurl+"seektime") if result.get("Type")=="Episode": WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) else: WINDOW.setProperty(playurl+"refresh_id", id) WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) WINDOW.setProperty(playurl+"type", result.get("Type")) WINDOW.setProperty(playurl+"item_id", id) if PlayUtils().isDirectPlay(result) == True: playMethod = "DirectPlay" else: playMethod = "Transcode" WINDOW.setProperty(playurl+"playmethod", playMethod) mediaSources = result.get("MediaSources") if(mediaSources != None): if mediaSources[0].get('DefaultAudioStreamIndex') != None: WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex'))) 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 if isStrmFile: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) else: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) if(addon.getSetting("addExtraPlaybackArt") == "true"): utils.logMsg("PLAY", "Doing second xbmc.Player().play to add extra art") xbmc.Player().play(playurl,listItem)