changed autoplay to popup in last 20 seconds rather than at play stopped

This commit is contained in:
im85288 2015-04-09 13:29:48 +01:00
parent f084608e84
commit 31656e4684
3 changed files with 59 additions and 29 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.emby"
name="Emby"
version="0.0.22"
version="0.0.23"
provider-name="Emby.media">
<requires>
<import addon="xbmc.python" version="2.1.0"/>

View File

@ -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"))

View File

@ -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))