use the service to actual start the playback, this makes all playback work the same

This commit is contained in:
Shaun
2017-04-14 20:21:20 +10:00
parent f4ca297eb9
commit 78b75f0501
4 changed files with 142 additions and 113 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.0.10"
version="1.1.0"
provider-name="null_pointer">
<requires>
<import addon="xbmc.python" version="2.1.0"/>

View File

@@ -242,6 +242,7 @@ def delete (item_id):
def addGUIItem( url, details, extraData, folder=True ):
WINDOW = xbmcgui.Window(10000)
url = url.encode('utf-8')
log.debug("Adding GuiItem for [%s]" % details.get('title','Unknown'))
@@ -260,7 +261,7 @@ def addGUIItem( url, details, extraData, folder=True ):
if url.startswith('http'):
u = sys.argv[0] + "?url=" + urllib.quote(url) + mode
else:
u = sys.argv[0] + "?item_id=" + url + '&mode=PLAY'# + "&timestamp=" + str(datetime.today())
u = sys.argv[0] + "?item_id=" + url + '&mode=PLAY'
#Create the ListItem that will be displayed
thumbPath=str(extraData.get('thumb',''))
@@ -425,35 +426,6 @@ def addContextMenu(details, extraData, folder):
return(commands)
def setListItemProps(server, id, listItem, result):
# set up item and item info
thumbID = id
eppNum = -1
seasonNum = -1
setArt(listItem, 'poster', downloadUtils.getArtwork(result, "Primary"))
listItem.setProperty('IsPlayable', 'true')
listItem.setProperty('IsFolder', 'false')
# play info
details = {
'title' : result.get("Name", "Missing Name"),
'plot' : result.get("Overview")
}
if(eppNum > -1):
details["episode"] = str(eppNum)
if(seasonNum > -1):
details["season"] = str(seasonNum)
listItem.setInfo( "Video", infoLabels=details )
return
def get_params(paramstring):
log.debug("Parameter string: " + paramstring)
param = {}
@@ -1137,85 +1109,14 @@ def PLAY(params, handle):
log.info("PLAY ACTION PARAMS : " + str(params))
id = params.get("item_id")
autoResume = int(params.get("auto_resume", "0"))
autoResume = int(params.get("auto_resume", "-1"))
log.info("AUTO_RESUME: " + str(autoResume))
userid = downloadUtils.getUserId()
seekTime = 0
port = __settings__.getSetting('port')
host = __settings__.getSetting('ipaddress')
server = host + ":" + port
jsonData = downloadUtils.downloadUrl("http://" + server + "/emby/Users/" + userid + "/Items/" + id + "?format=json",
suppress=False, popup=1)
result = json.loads(jsonData)
if autoResume != 0:
resume_result = 0
seekTime = (autoResume / 1000) / 10000
else:
userData = result.get("UserData")
resume_result = 0
if userData.get("PlaybackPositionTicks") != 0:
reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000
seekTime = reasonableTicks / 10000
displayTime = str(timedelta(seconds=seekTime))
resumeDialog = ResumeDialog("ResumeDialog.xml", __cwd__, "default", "720p")
resumeDialog.setResumeTime("Resume from " + displayTime)
resumeDialog.doModal()
resume_result = resumeDialog.getResumeAction()
del resumeDialog
log.info("Resume Dialog Result: " + str(resume_result))
if resume_result == -1:
return
playurl = PlayUtils().getPlayUrl(id, result)
log.info("Play URL: " + playurl)
thumbPath = downloadUtils.getArtwork(result, "Primary")
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
setListItemProps(server, id, listItem, result)
# Can not play virtual items
if (result.get("LocationType") == "Virtual"):
xbmcgui.Dialog().ok(__language__(30128), __language__(30129))
return
# set the current playing item id
# set all the playback info, this will be picked up by the service
# the service will then start the playback
WINDOW = xbmcgui.Window(10000)
WINDOW.setProperty("item_id", id)
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
playlist.add(playurl, listItem)
xbmc.Player().play(playlist)
#xbmc.Player().play(playurl, listItem)
#xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
# Set a loop to wait for positive confirmation of playback
count = 0
while not xbmc.Player().isPlaying():
log.info("Not playing yet...sleep for 1 sec")
count = count + 1
if count >= 10:
return
else:
time.sleep(1)
if resume_result == 0:
jumpBackSec = int(__settings__.getSetting("resumeJumpBack"))
seekToTime = seekTime - jumpBackSec
while xbmc.Player().getTime() < (seekToTime - 5):
xbmc.Player().pause
xbmc.sleep(100)
xbmc.Player().seekTime(seekToTime)
xbmc.sleep(100)
xbmc.Player().play()
WINDOW.setProperty("play_item_id", id)
WINDOW.setProperty("play_item_resume", str(autoResume))

119
resources/lib/play_utils.py Normal file
View File

@@ -0,0 +1,119 @@
# Gnu General Public License - see LICENSE.TXT
import xbmc
import xbmcgui
import xbmcaddon
from datetime import timedelta
import json as json
from simple_logging import SimpleLogging
from downloadutils import DownloadUtils
from resume_dialog import ResumeDialog
from utils import PlayUtils
log = SimpleLogging("EmbyCon." + __name__)
downloadUtils = DownloadUtils()
def playFile(id, auto_resume):
log.info("playFile id(" + str(id) + ") resume(" + str(auto_resume) + ")")
userid = downloadUtils.getUserId()
settings = xbmcaddon.Addon(id='plugin.video.embycon')
addon_path = settings.getAddonInfo('path')
port = settings.getSetting('port')
host = settings.getSetting('ipaddress')
server = host + ":" + port
jsonData = downloadUtils.downloadUrl("http://" + server + "/emby/Users/" + userid + "/Items/" + id + "?format=json",
suppress=False, popup=1)
result = json.loads(jsonData)
seekTime = 0
auto_resume = int(auto_resume)
if auto_resume != -1:
seekTime = (auto_resume / 1000) / 10000
else:
userData = result.get("UserData")
if userData.get("PlaybackPositionTicks") != 0:
reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000
seekTime = reasonableTicks / 10000
displayTime = str(timedelta(seconds=seekTime))
resumeDialog = ResumeDialog("ResumeDialog.xml", addon_path, "default", "720p")
resumeDialog.setResumeTime("Resume from " + displayTime)
resumeDialog.doModal()
resume_result = resumeDialog.getResumeAction()
del resumeDialog
log.info("Resume Dialog Result: " + str(resume_result))
if resume_result == 1:
seekTime = 0
elif resume_result == -1:
return
playurl = PlayUtils().getPlayUrl(id, result)
log.info("Play URL: " + playurl)
thumbPath = downloadUtils.getArtwork(result, "Primary")
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
setListItemProps(id, listItem, result)
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
playlist.add(playurl, listItem)
xbmc.Player().play(playlist)
if seekTime == 0:
return
count = 0
while not xbmc.Player().isPlaying():
log.info("Not playing yet...sleep for 1 sec")
count = count + 1
if count >= 10:
return
else:
time.sleep(1)
while xbmc.Player().getTime() < (seekTime - 5):
xbmc.Player().pause
xbmc.sleep(100)
xbmc.Player().seekTime(seekTime)
xbmc.sleep(100)
xbmc.Player().play()
def setListItemProps(id, listItem, result):
# set up item and item info
thumbID = id
eppNum = -1
seasonNum = -1
primary_inage = downloadUtils.getArtwork(result, "Primary")
listItem.setProperty("poster", primary_inage)
listItem.setArt({"poster": primary_inage})
listItem.setProperty('IsPlayable', 'true')
listItem.setProperty('IsFolder', 'false')
# play info
details = {
'title': result.get("Name", "Missing Name"),
'plot': result.get("Overview")
}
if (eppNum > -1):
details["episode"] = str(eppNum)
if (seasonNum > -1):
details["season"] = str(seasonNum)
listItem.setInfo("Video", infoLabels=details)
return

View File

@@ -9,6 +9,7 @@ from datetime import datetime
from resources.lib.websocketclient import WebSocketThread
from resources.lib.downloadutils import DownloadUtils
from resources.lib.simple_logging import SimpleLogging
from resources.lib.play_utils import playFile
log = SimpleLogging("EmbyCon.service")
download_utils = DownloadUtils()
@@ -69,16 +70,14 @@ class Service(xbmc.Player):
current_playing_file = xbmc.Player().getPlayingFile()
log.info("onPlayBackStarted: " + current_playing_file)
window_handle = xbmcgui.Window(10000)
emby_item_id = window_handle.getProperty("item_id")
#emby_item_id = window_handle.getProperty("playback_url_" + current_playing_file)
log.info("item_id: " + emby_item_id)
window_handle.setProperty("item_id", "")
# if we could not find the ID of the current item then return
if emby_item_id is None or len(emby_item_id) == 0:
return
websocket_thread.playbackStarted(emby_item_id)
data = {}
@@ -102,7 +101,9 @@ monitor = Service()
last_progress_update = datetime.today()
while not xbmc.abortRequested:
window_handle = xbmcgui.Window(10000)
if xbmc.Player().isPlaying():
try:
# send update
@@ -129,6 +130,14 @@ while not xbmc.abortRequested:
log.error("Exception in Playback Monitor : " + str(e))
pass
else:
emby_item_id = window_handle.getProperty("play_item_id")
emby_item_resume = window_handle.getProperty("play_item_resume")
if emby_item_id and emby_item_resume:
window_handle.clearProperty("play_item_id")
window_handle.clearProperty("play_item_resume")
playFile(emby_item_id, emby_item_resume)
xbmc.sleep(1000)
xbmcgui.Window(10000).setProperty("EmbyCon_Service_Timestamp", str(int(time.time())))