From a6497ce6c72bc41a954848cfc134ac0a2f024a28 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 11 Jun 2015 00:46:47 -0500 Subject: [PATCH] First attempt at supporting theme music --- default.py | 3 ++ resources/lib/Entrypoint.py | 69 +++++++++++++++++++++++++++++++++++++ resources/lib/PlayUtils.py | 12 ++++--- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/default.py b/default.py index 775c8965..718333c5 100644 --- a/default.py +++ b/default.py @@ -40,6 +40,9 @@ elif mode == "resetauth": elif mode == "adduser": entrypoint.addUser() + +elif mode == "thememedia": + entrypoint.getThemeMedia() elif mode == "userprefs": entrypoint.userPreferences() diff --git a/resources/lib/Entrypoint.py b/resources/lib/Entrypoint.py index 5118155f..d70fe5c5 100644 --- a/resources/lib/Entrypoint.py +++ b/resources/lib/Entrypoint.py @@ -14,6 +14,7 @@ WINDOW = xbmcgui.Window(10000) import Utils as utils from ClientInformation import ClientInformation from PlaybackUtils import PlaybackUtils +from PlayUtils import PlayUtils from DownloadUtils import DownloadUtils from ReadEmbyDB import ReadEmbyDB from API import API @@ -121,6 +122,74 @@ def addUser(): xbmc.log("Failed to add user to session.") xbmcgui.Dialog().notification("Error", "Unable to add/remove user from the session.", xbmcgui.NOTIFICATION_ERROR) +# THEME MUSIC/VIDEOS +def getThemeMedia(): + + doUtils = DownloadUtils() + playUtils = PlayUtils() + + currUser = WINDOW.getProperty('currUser') + server = WINDOW.getProperty('server%s' % currUser) + playback = None + + library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/") + + # Choose playback method + resp = xbmcgui.Dialog().select("Choose playback method for your themes", ["Direct Play", "Direct Stream"]) + if resp == 0: + # Direct Play + playback = "DirectPlay" + elif resp == 1: + # Direct Stream + playback = "DirectStream" + else:return + + # Create library directory + if not xbmcvfs.exists(library): + xbmcvfs.mkdir(library) + + # Get every user view Id + userViews = [] + url = "{server}/mediabrowser/Users/{UserId}/Items?format=json" + result = doUtils.downloadUrl(url) + + for view in result[u'Items']: + userviewId = view[u'Id'] + userViews.append(userviewId) + + # Get Ids with Theme songs + itemIds = {} + for view in userViews: + url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeSong=True&ParentId=%s&format=json" % view + result = doUtils.downloadUrl(url) + if result[u'TotalRecordCount'] != 0: + for item in result[u'Items']: + itemId = item[u'Id'] + folderName = item[u'Name'] + itemIds[itemId] = folderName + + # Get paths + for itemId in itemIds: + url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId + result = doUtils.downloadUrl(url) + if playback == "DirectPlay": + playurl = playUtils.directPlay(result[u'Items'][0]) + else: + playurl = playUtils.directStream(result, server, result[u'Items'][0][u'Id'], "Audio") + nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % itemIds[itemId]) + # Create folders for each content + if not xbmcvfs.exists(nfo_path): + xbmcvfs.mkdir(nfo_path) + # Where to put the nfos + nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo") + # Create nfo and write our URL to it + nfo_file = open(nfo_path, 'w') + nfo_file.write( + '%s' % playurl + ) + # Close nfo file + nfo_file.close() + def userPreferences(): doUtils = DownloadUtils() addonSettings = xbmcaddon.Addon(id='plugin.video.emby') diff --git a/resources/lib/PlayUtils.py b/resources/lib/PlayUtils.py index 1a26fc5a..3433d4d8 100644 --- a/resources/lib/PlayUtils.py +++ b/resources/lib/PlayUtils.py @@ -187,12 +187,16 @@ class PlayUtils(): return False return True - - def directStream(self, result, server, id): + + def directStream(self, result, server, id, type="Video"): try: - # Play with Direct Stream - playurl = "%s/mediabrowser/Videos/%s/stream?static=true" % (server, id) + if type == "Video": + # Play with Direct Stream + playurl = "%s/mediabrowser/Videos/%s/stream?static=true" % (server, id) + elif type == "Audio": + playurl = "%s/mediabrowser/Audio/%s/stream.mp3" % (server, id) + return playurl mediaSources = result[u'MediaSources'] if mediaSources[0].get('DefaultAudioStreamIndex') != None: