From 31656e46840e191f5980c21b98ec5ba58aa6e7c9 Mon Sep 17 00:00:00 2001 From: im85288 Date: Thu, 9 Apr 2015 13:29:48 +0100 Subject: [PATCH] changed autoplay to popup in last 20 seconds rather than at play stopped --- addon.xml | 2 +- resources/lib/Player.py | 79 ++++++++++++++++++++++++++--------------- service.py | 7 ++++ 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/addon.xml b/addon.xml index 7d265fa9..8bb91736 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/Player.py b/resources/lib/Player.py index 46c89953..9f5766b2 100644 --- a/resources/lib/Player.py +++ b/resources/lib/Player.py @@ -92,34 +92,6 @@ class Player( xbmc.Player ): #report updates playcount and resume status to Kodi and MB3 librarySync.updatePlayCount(item_id,type) - # if its an episode see if autoplay is enabled - if addonSettings.getSetting("autoPlaySeason")=="true" and type=="Episode": - port = addonSettings.getSetting('port') - host = addonSettings.getSetting('ipaddress') - server = host + ":" + port - userid = self.downloadUtils.getUserId() - # add remaining unplayed episodes if applicable - MB3Episode = ReadEmbyDB().getItem(item_id) - userData = MB3Episode["UserData"] - if userData!=None and userData["Played"]==True: - - pDialog = xbmcgui.DialogProgress() - pDialog.create("Auto Play","Further Episode(s) in "+MB3Episode["SeasonName"]+" for "+MB3Episode["SeriesName"]+ " found","Cancel to stop automatic play of remaining episodes") - count = 0 - while(pDialog.iscanceled==False or count < 10): - xbmc.sleep(1000) - count += 1 - progress = count * 10 - remainingsecs = 10 - count - pDialog.update(progress,"Further Episode(s) in "+MB3Episode["SeasonName"]+" for "+MB3Episode["SeriesName"]+ " found","Cancel to stop automatic play of remaining episodes", str(remainingsecs) + " second(s) until auto dismiss") - - if pDialog.iscanceled()==False: - seasonId = MB3Episode["SeasonId"] - jsonData = self.downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items?ParentId=" + seasonId + "&ImageTypeLimit=1&SortBy=SortName&SortOrder=Ascending&Filters=IsUnPlayed&IncludeItemTypes=Episode&IsVirtualUnaired=false&Recursive=true&IsMissing=False&format=json", suppress=False, popup=1 ) - if(jsonData != ""): - seasonData = json.loads(jsonData) - if seasonData.get("Items") != None: - PlaybackUtils().PLAYAllEpisodes(seasonData.get("Items")) self.played_information.clear() @@ -340,4 +312,55 @@ class Player( xbmc.Player ): # Will be called when user stops xbmc playing a file self.printDebug("emby Service -> onPlayBackStopped") self.stopAll() + + + def autoPlayPlayback(self): + currentFile = xbmc.Player().getPlayingFile() + data = self.played_information.get(currentFile) + + # only report playback if emby has initiated the playback (item_id has value) + if(data != None and data.get("item_id") != None): + addonSettings = xbmcaddon.Addon(id='plugin.video.emby') + + item_id = data.get("item_id") + type = data.get("Type") + + # if its an episode see if autoplay is enabled + if addonSettings.getSetting("autoPlaySeason")=="true" and type=="Episode": + port = addonSettings.getSetting('port') + host = addonSettings.getSetting('ipaddress') + server = host + ":" + port + userid = self.downloadUtils.getUserId() + # add remaining unplayed episodes if applicable + MB3Episode = ReadEmbyDB().getItem(item_id) + userData = MB3Episode["UserData"] + if userData!=None and userData["Played"]==True: + pDialog = xbmcgui.DialogProgress() + seasonId = MB3Episode["SeasonId"] + jsonData = self.downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items?ParentId=" + seasonId + "&ImageTypeLimit=1&Limit=1&SortBy=SortName&SortOrder=Ascending&Filters=IsUnPlayed&IncludeItemTypes=Episode&IsVirtualUnaired=false&Recursive=true&IsMissing=False&format=json", suppress=False, popup=1 ) + if(jsonData != ""): + seasonData = json.loads(jsonData) + if seasonData.get("Items") != None: + item = seasonData.get("Items")[0] + pDialog.create("Auto Play next episode", str(item.get("ParentIndexNumber")) + "x" + str(item.get("IndexNumber")) + ". " + item["Name"] + " found","Cancel to stop automatic play") + count = 0 + while(pDialog.iscanceled()==False and count < 10): + xbmc.sleep(1000) + count += 1 + progress = count * 10 + remainingsecs = 10 - count + pDialog.update(progress, str(item.get("ParentIndexNumber")) + "x" + str(item.get("IndexNumber")) + ". " + item["Name"] + " found","Cancel to stop automatic play", str(remainingsecs) + " second(s) until auto dismiss") + + pDialog.close() + + if pDialog.iscanceled()==False: + playTime = xbmc.Player().getTime() + totalTime = xbmc.Player().getTotalTime() + while xbmc.Player().isPlaying() and (totalTime-playTime > 2): + xbmc.sleep(500) + playTime = xbmc.Player().getTime() + totalTime = xbmc.Player().getTotalTime() + + PlaybackUtils().PLAYAllEpisodes(seasonData.get("Items")) + diff --git a/service.py b/service.py index f79ddb75..eafbe2d8 100644 --- a/service.py +++ b/service.py @@ -63,6 +63,8 @@ class Service(): player = Player() ws = WebSocketThread() + lastFile = None + while not self.KodiMonitor.abortRequested(): xbmc.sleep(1000) @@ -70,6 +72,7 @@ class Service(): if xbmc.Player().isPlaying(): try: playTime = xbmc.Player().getTime() + totalTime = xbmc.Player().getTotalTime() currentFile = xbmc.Player().getPlayingFile() if(player.played_information.get(currentFile) != None): @@ -85,6 +88,10 @@ class Service(): xbmc.log("MB3 Sync Service -> Exception reporting progress : " + msg) pass lastProgressUpdate = datetime.today() + # only try autoplay when there's 20 seconds or less remaining and only once! + if (totalTime - playTime <= 20 and (lastFile==None or lastFile!=currentFile)): + lastFile = currentFile + player.autoPlayPlayback() except Exception, e: xbmc.log("MB3 Sync Service -> Exception in Playback Monitor Service : " + str(e))