fixed playback

This commit is contained in:
Marcel van der Veldt 2015-05-02 16:49:47 +02:00
parent d489375ab2
commit 88b31ae5c4
6 changed files with 32 additions and 58 deletions

View file

@ -27,8 +27,10 @@ except:
id=None
if mode != None and mode == "play":
pass
#PlaybackUtils().PLAY(id)
WINDOW.setProperty('GUIPLAY', str(id)) # set window prop
#WINDOW.setProperty('GUIPLAY', str(id)) # set window prop
#xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, None)
elif sys.argv[1] == "reset":
utils.reset()
else:

View file

@ -13,6 +13,7 @@ from WriteKodiDB import WriteKodiDB
from ReadKodiDB import ReadKodiDB
from PlayUtils import PlayUtils
from DownloadUtils import DownloadUtils
from PlaybackUtils import PlaybackUtils
class Kodi_Monitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
@ -28,7 +29,7 @@ class Kodi_Monitor(xbmc.Monitor):
downloadUtils = DownloadUtils()
print "onNotification:" + method + ":" + sender + ":" + str(data)
#player started playing an item -
if method == "Player.OnPlay":
if method == "Playlist.OnAdd":
print "playlist onadd is called"
jsondata = json.loads(data)
if jsondata != None:
@ -38,6 +39,9 @@ class Kodi_Monitor(xbmc.Monitor):
type = jsondata.get("item").get("type")
embyid = ReadKodiDB().getEmbyIdByKodiId(id,type)
print "id --> " + str(id)
print "type --> " + type
print "emby_id --> " + embyid
if embyid != None:
WINDOW = xbmcgui.Window( 10000 )
@ -49,41 +53,8 @@ class Kodi_Monitor(xbmc.Monitor):
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % embyid
result = downloadUtils.downloadUrl(url)
userData = result[u'UserData']
playurl = PlayUtils().getPlayUrl(server, embyid, result)
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)
# 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)
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']))
#launch playbackutils
PlaybackUtils().PLAY(result)
if method == "VideoLibrary.OnUpdate":
jsondata = json.loads(data)

View file

@ -35,7 +35,7 @@ class PlaybackUtils():
def __init__(self, *args):
pass
def PLAY(self, id):
def PLAY(self, result):
xbmc.log("PLAY Called")
WINDOW = xbmcgui.Window(10000)
@ -43,11 +43,9 @@ class PlaybackUtils():
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)
id = result["Id"]
userData = result[u'UserData']
userData = result['UserData']
resume_result = 0
seekTime = 0
@ -134,13 +132,8 @@ class PlaybackUtils():
#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)
#xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
xbmc.Player().play(playurl,listItem)
def setArt(self, list,name,path):
if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators':

View file

@ -90,9 +90,9 @@ class Player( xbmc.Player ):
self.logMsg("emby Service -> Percent Complete:" + str(percentComplete) + " Mark Played At:" + str(markPlayedAt))
self.stopPlayback(data)
if(refresh_id != None):
#if(refresh_id != None):
#report updates playcount and resume status to Kodi and MB3
librarySync.updatePlayCount(item_id)
#librarySync.updatePlayCount(item_id)
self.played_information.clear()

View file

@ -42,3 +42,15 @@ class ReadKodiDB():
#this will return a list with tuples of all items returned from the database
return allepisodes
def getEmbyIdByKodiId(self, id, type, connection=None, cursor=None):
if not connection:
connection = utils.KodiSQL()
cursor = connection.cursor()
cursor.execute("SELECT emby_id FROM emby WHERE media_type=? AND kodi_id=?",(type,id))
result = cursor.fetchone()
if result:
return result[0]
else:
return None

View file

@ -25,7 +25,7 @@ sleepVal = 20
class WriteKodiDB():
def updatePlayCountFromKodi(self, id, type, playcount=0):
#when user marks item watched from kodi interface update this in MB3
#when user marks item watched from kodi interface update this in Emby
utils.logMsg("Emby", "updatePlayCountFromKodi Called")
connection = utils.KodiSQL()
@ -37,11 +37,8 @@ class WriteKodiDB():
if(emby_id != None):
addon = xbmcaddon.Addon(id='plugin.video.emby')
downloadUtils = DownloadUtils()
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
utils.logMsg("Emby","watchedurl -->" + watchedurl)
if playcount != 0:
downloadUtils.downloadUrl(watchedurl, type="POST")
else:
@ -883,7 +880,6 @@ class WriteKodiDB():
sql="insert into streamdetails(idFile, iStreamType, strAudioCodec, iAudioChannels) values(?, ?, ?, ?)"
cursor.execute(sql, (fileid,1,streamdetails.get("audiocodec"),streamdetails.get("channels")))
def addBoxsetToKodiLibrary(self, boxset, connection, cursor):
strSet = boxset["Name"]