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,72 +38,48 @@ 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):
jsondata = json.loads(data) if utils.settings('useDirectPaths')=='true' or utils.settings('enableMusicSync') == "true":
if jsondata != None:
if jsondata.has_key("item"):
if jsondata.get("item").has_key("id") and jsondata.get("item").has_key("type"):
id = jsondata.get("item").get("id")
type = jsondata.get("item").get("type")
embyid = ReadKodiDB().getEmbyIdByKodiId(id,type)
if embyid != None: jsondata = json.loads(data)
if jsondata != None:
if jsondata.has_key("item"):
if jsondata.get("item").has_key("id") and jsondata.get("item").has_key("type"):
id = jsondata.get("item").get("id")
type = jsondata.get("item").get("type")
playurl = xbmc.Player().getPlayingFile() if type == "song":
connection = utils.KodiSQL('music')
WINDOW = xbmcgui.Window( 10000 ) cursor = connection.cursor()
username = WINDOW.getProperty('currUser') embyid = ReadKodiDB().getEmbyIdByKodiId(id, type, connection, cursor)
userid = WINDOW.getProperty('userId%s' % username) cursor.close()
server = WINDOW.getProperty('server%s' % username)
url = "{server}/mediabrowser/Users/{UserId}/Items/" + embyid + "?format=json&ImageTypeLimit=1"
result = downloadUtils.downloadUrl(url)
print "Here: %s" % result
userData = result['UserData']
playurl = PlayUtils().getPlayUrl(server, embyid, result)
watchedurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayedItems/' + embyid
positionurl = 'http://' + server + '/mediabrowser/Users/'+ userid + '/PlayingItems/' + embyid
deleteurl = 'http://' + server + '/mediabrowser/Items/' + 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.get("Type")=="Episode":
WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId"))
else: else:
WINDOW.setProperty(playurl+"refresh_id", embyid) embyid = ReadKodiDB().getEmbyIdByKodiId(id,type)
WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks"))) if embyid:
WINDOW.setProperty(playurl+"type", result.get("Type"))
WINDOW.setProperty(playurl+"item_id", embyid)
if PlayUtils().isDirectPlay(result) == True: url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json" % embyid
playMethod = "DirectPlay" result = downloadUtils.downloadUrl(url)
else: self.logMsg("Result: %s" % result, 2)
playMethod = "Transcode"
WINDOW.setProperty(playurl+"playmethod", playMethod) playurl = None
count = 0
while not playurl and count < 2:
try:
playurl = xbmc.Player().getPlayingFile()
except RuntimeError:
xbmc.sleep(200)
else:
listItem = xbmcgui.ListItem()
PlaybackUtils().setProperties(playurl, result, listItem)
mediaSources = result.get("MediaSources") if type == "song" and utils.settings('directstreammusic') == "true":
if(mediaSources != None): utils.window('%splaymethod' % playurl, value="DirectStream")
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: else:
defaultsubs = stream[u'Codec'] utils.window('%splaymethod' % playurl, value="DirectPlay")
WINDOW.setProperty("%ssubs" % playurl, defaultsubs.encode('utf-8'))
if mediaSources[0].get('DefaultAudioStreamIndex') != None: count += 1
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