Support report playback for music

This commit is contained in:
angelblue05 2015-10-20 04:18:13 -05:00
parent a0347ce03d
commit 54f39fa58e

View file

@ -38,7 +38,9 @@ class Kodi_Monitor( xbmc.Monitor ):
WINDOW = self.WINDOW WINDOW = self.WINDOW
downloadUtils = DownloadUtils() downloadUtils = DownloadUtils()
#player started playing an item - #player started playing an item -
if ("Playlist.OnAdd" in method or "Player.OnPlay" in method) and utils.settings('useDirectPaths')=='true': if ("Playlist.OnAdd" in method or "Player.OnPlay" in method):
if utils.settings('useDirectPaths')=='true' or utils.settings('enableMusicSync') == "true":
jsondata = json.loads(data) jsondata = json.loads(data)
if jsondata != None: if jsondata != None:
@ -46,64 +48,38 @@ class Kodi_Monitor( xbmc.Monitor ):
if jsondata.get("item").has_key("id") and jsondata.get("item").has_key("type"): if jsondata.get("item").has_key("id") and jsondata.get("item").has_key("type"):
id = jsondata.get("item").get("id") id = jsondata.get("item").get("id")
type = jsondata.get("item").get("type") type = jsondata.get("item").get("type")
if type == "song":
connection = utils.KodiSQL('music')
cursor = connection.cursor()
embyid = ReadKodiDB().getEmbyIdByKodiId(id, type, connection, cursor)
cursor.close()
else:
embyid = ReadKodiDB().getEmbyIdByKodiId(id,type) embyid = ReadKodiDB().getEmbyIdByKodiId(id,type)
if embyid != None: if embyid:
playurl = xbmc.Player().getPlayingFile() url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json" % embyid
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/" + embyid + "?format=json&ImageTypeLimit=1"
result = downloadUtils.downloadUrl(url) result = downloadUtils.downloadUrl(url)
print "Here: %s" % result self.logMsg("Result: %s" % result, 2)
userData = result['UserData']
playurl = PlayUtils().getPlayUrl(server, embyid, result) playurl = None
count = 0
watchedurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayedItems/' + embyid while not playurl and count < 2:
positionurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayingItems/' + embyid try:
deleteurl = 'http://' + server + '/mediabrowser/Items/' + embyid playurl = xbmc.Player().getPlayingFile()
except RuntimeError:
# set the current playing info xbmc.sleep(200)
WINDOW.setProperty(playurl+"watchedurl", watchedurl)
WINDOW.setProperty(playurl+"positionurl", positionurl)
WINDOW.setProperty(playurl+"deleteurl", "")
WINDOW.setProperty(playurl+"deleteurl", deleteurl)
if result.get("Type")=="Episode":
WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId"))
else: else:
WINDOW.setProperty(playurl+"refresh_id", embyid) listItem = xbmcgui.ListItem()
PlaybackUtils().setProperties(playurl, result, listItem)
WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) if type == "song" and utils.settings('directstreammusic') == "true":
WINDOW.setProperty(playurl+"type", result.get("Type")) utils.window('%splaymethod' % playurl, value="DirectStream")
WINDOW.setProperty(playurl+"item_id", embyid)
if PlayUtils().isDirectPlay(result) == True:
playMethod = "DirectPlay"
else: else:
playMethod = "Transcode" utils.window('%splaymethod' % playurl, value="DirectPlay")
WINDOW.setProperty(playurl+"playmethod", playMethod) count += 1
mediaSources = result.get("MediaSources")
if(mediaSources != None):
mediaStream = mediaSources[0].get('MediaStreams')
defaultsubs = ""
for stream in mediaStream:
if u'Subtitle' in stream[u'Type'] and stream[u'IsDefault']:
if u'Language' in stream:
defaultsubs = stream[u'Language']
else:
defaultsubs = stream[u'Codec']
WINDOW.setProperty("%ssubs" % playurl, defaultsubs.encode('utf-8'))
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')))
if method == "VideoLibrary.OnUpdate": if method == "VideoLibrary.OnUpdate":
# Triggers 4 times, the following is only for manually marking as watched/unwatched # Triggers 4 times, the following is only for manually marking as watched/unwatched