From ab467e36f040aeab2017d2cbe9de2f92c8680aed Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 2 Mar 2016 13:29:07 -0600 Subject: [PATCH 1/9] Fix unicode --- resources/lib/userclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index 066f1a6b..ecda0a9c 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -349,7 +349,7 @@ class UserClient(threading.Thread): # If user has password if user['HasPassword'] == True: password = dialog.input( - heading="%s %s" % (lang(33008), username), + heading="%s %s" % (lang(33008), username.decode('utf-8')), option=xbmcgui.ALPHANUM_HIDE_INPUT) # If password dialog is cancelled if not password: From f16b5dfff6423e748320a4f7b6e29dc61d64f1eb Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 2 Mar 2016 14:50:08 -0600 Subject: [PATCH 2/9] Prevent errors during the view creation For grouped folders only. Include the itemtype to make sure we can correctly search the reference under the grouped view. --- resources/lib/librarysync.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index bc2b5b81..85391dc1 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -385,6 +385,7 @@ class LibrarySync(threading.Thread): if view['type'] == "mixed": sorted_views.append(view['name']) sorted_views.append(view['name']) + log("Sorted views: %s" % sorted_views, 1) try: groupedFolders = self.user.userSettings['Configuration']['GroupedFolders'] @@ -399,6 +400,15 @@ class LibrarySync(threading.Thread): current_views = emby_db.getViews() # Set views for supported media type + emby_mediatypes = { + + 'movies': "Movie", + 'tvshows': "Series", + 'musicvideos': "MusicVideo", + 'homevideos': "Video", + 'music': "Audio", + 'photos': "Photo" + } mediatypes = ['movies', 'tvshows', 'musicvideos', 'homevideos', 'music', 'photos'] for mediatype in mediatypes: @@ -416,8 +426,10 @@ class LibrarySync(threading.Thread): # Media folders are grouped into userview url = "{server}/emby/Users/{UserId}/Items?format=json" params = { + 'ParentId': folderid, - 'Limit': 1 + 'Limit': 1, + 'IncludeItemTypes': emby_mediatypes[mediatype] } # Get one item from server using the folderid result = doUtils(url, parameters=params) try: @@ -434,8 +446,13 @@ class LibrarySync(threading.Thread): # Take the userview, and validate the item belong to the view if emby.verifyView(grouped_view['Id'], verifyitem): # Take the name of the userview + log("Found corresponding view: %s %s" + % (grouped_view['Name'], grouped_view['Id']), 1) foldername = grouped_view['Name'] break + else: + # Unable to find a match, add the name to our sorted_view list + sorted_views.append(foldername) # Get current media folders from emby database view = emby_db.getView_byId(folderid) From 405cecfec786d7194a1492cafda4ebc5200c6f53 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 2 Mar 2016 18:23:51 -0600 Subject: [PATCH 3/9] Version bump 2.2.6 --- addon.xml | 2 +- changelog.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 1b3fb5fb..a64d8de4 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/changelog.txt b/changelog.txt index d8a3d486..200c0696 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +version 2.2.6 +- Fix unicode error +- Fix grouped folders error + version 2.2.5 - Add generate a new device Id option, found in the add-on settings > advanced. - Offer to delete cached thumbnails upon database reset. From 2a107b45fe5369163c20cac6f8b8c7a3cb2007d8 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 2 Mar 2016 18:25:17 -0600 Subject: [PATCH 4/9] Prevent screensaver during sync Initial, repair, manual syncs. --- resources/lib/librarysync.py | 6 ++++++ resources/lib/utils.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 85391dc1..4ac5cdea 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -229,6 +229,8 @@ class LibrarySync(threading.Thread): music_enabled = utils.settings('enableMusic') == "true" xbmc.executebuiltin('InhibitIdleShutdown(true)') + screensaver = utils.getScreensaver() + utils.setScreensaver(value="") window('emby_dbScan', value="true") # Add sources utils.sourcesXML() @@ -280,6 +282,7 @@ class LibrarySync(threading.Thread): completed = process[itemtype](embycursor, kodicursor, pDialog) if not completed: xbmc.executebuiltin('InhibitIdleShutdown(false)') + utils.setScreensaver(value=screensaver) window('emby_dbScan', clear=True) if pDialog: pDialog.close() @@ -307,6 +310,7 @@ class LibrarySync(threading.Thread): completed = self.music(embycursor, musiccursor, pDialog) if not completed: xbmc.executebuiltin('InhibitIdleShutdown(false)') + utils.setScreensaver(value=screensaver) window('emby_dbScan', clear=True) if pDialog: pDialog.close() @@ -334,6 +338,7 @@ class LibrarySync(threading.Thread): elapsedtotal = datetime.now() - starttotal xbmc.executebuiltin('InhibitIdleShutdown(false)') + utils.setScreensaver(value=screensaver) window('emby_dbScan', clear=True) window('emby_initialScan', clear=True) if forceddialog: @@ -453,6 +458,7 @@ class LibrarySync(threading.Thread): else: # Unable to find a match, add the name to our sorted_view list sorted_views.append(foldername) + log("Couldn't find corresponding grouped view: %s" % sorted_views, 1) # Get current media folders from emby database view = emby_db.getView_byId(folderid) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index b1e14638..9e8c1707 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -4,6 +4,7 @@ import cProfile import inspect +import json import pstats import sqlite3 import os @@ -119,6 +120,40 @@ def getKodiMusicDBPath(): % dbVersion.get(kodibuild, "")).decode('utf-8') return dbPath +def getScreensaver(): + # Get the current screensaver value + query = { + + 'jsonrpc': "2.0", + 'id': 0, + 'method': "Settings.getSettingValue", + 'params': { + + 'setting': "screensaver.mode" + } + } + result = xbmc.executeJSONRPC(json.dumps(query)) + result = json.loads(result) + screensaver = result['result']['value'] + + return screensaver + +def setScreensaver(value): + # Toggle the screensaver + query = { + + 'jsonrpc': "2.0", + 'id': 0, + 'method': "Settings.setSettingValue", + 'params': { + + 'setting': "screensaver.mode", + 'value': value + } + } + result = xbmc.executeJSONRPC(json.dumps(query)) + logMsg("EMBY", "Toggling screensaver: %s %s" % (value, result), 1) + def reset(): dialog = xbmcgui.Dialog() From c02c7ce242d926a2be1b2801743bbd249f416a23 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 2 Mar 2016 18:26:38 -0600 Subject: [PATCH 5/9] Version bump 2.2.7 --- addon.xml | 2 +- changelog.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index a64d8de4..246aea0f 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/changelog.txt b/changelog.txt index 200c0696..03f8f2c7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +version 2.2.7 +- Prevent Kodi screensaver during the initial sync + version 2.2.6 - Fix unicode error - Fix grouped folders error From 897780f059b2071405f4d8b5a31b87e67a33278f Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 3 Mar 2016 23:32:33 -0600 Subject: [PATCH 6/9] Fix views GroupedFolders sometimes return empty, even if the user's views are grouped (seems like a bug). Added a failsafe. --- resources/lib/librarysync.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 4ac5cdea..b40d5507 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -382,8 +382,9 @@ class LibrarySync(threading.Thread): result = doUtils(url) grouped_views = result['Items'] ordered_views = emby.getViews(sortedlist=True) - sorted_views = [] + all_views = [] for view in ordered_views: + all_views.append(view['name']) if view['type'] == "music": continue @@ -392,13 +393,6 @@ class LibrarySync(threading.Thread): sorted_views.append(view['name']) log("Sorted views: %s" % sorted_views, 1) - try: - groupedFolders = self.user.userSettings['Configuration']['GroupedFolders'] - except TypeError: - url = "{server}/emby/Users/{UserId}?format=json" - result = doUtils(url) - groupedFolders = result['Configuration']['GroupedFolders'] - # total nodes for window properties vnodes.clearProperties() totalnodes = len(sorted_views) + 0 @@ -427,12 +421,12 @@ class LibrarySync(threading.Thread): foldername = folder['name'] viewtype = folder['type'] - if folderid in groupedFolders: + if foldername not in all_views: # Media folders are grouped into userview url = "{server}/emby/Users/{UserId}/Items?format=json" params = { - 'ParentId': folderid, + 'Recursive': True, 'Limit': 1, 'IncludeItemTypes': emby_mediatypes[mediatype] } # Get one item from server using the folderid @@ -460,6 +454,12 @@ class LibrarySync(threading.Thread): sorted_views.append(foldername) log("Couldn't find corresponding grouped view: %s" % sorted_views, 1) + # Failsafe + try: + sorted_views.index(foldername) + except ValueError: + sorted_views.append(foldername) + # Get current media folders from emby database view = emby_db.getView_byId(folderid) try: From 48950820792fa9176c466908654f8df708a430c9 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 3 Mar 2016 23:54:53 -0600 Subject: [PATCH 7/9] Fix typo Accidentally pasted over line --- resources/lib/librarysync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index b40d5507..4b885ca9 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -383,6 +383,7 @@ class LibrarySync(threading.Thread): grouped_views = result['Items'] ordered_views = emby.getViews(sortedlist=True) all_views = [] + sorted_views = [] for view in ordered_views: all_views.append(view['name']) if view['type'] == "music": From b05033c9b848f47a23224a8c0ccfcc4cd5b9c535 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 4 Mar 2016 03:00:25 -0600 Subject: [PATCH 8/9] Fix unicode and invalid handle --- resources/lib/entrypoint.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 652d089f..d6d03cab 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -456,10 +456,10 @@ def BrowseContent(viewname, type="", folderid=""): if not folderid: views = emby.getViews(type) for view in views: - if view.get("name") == viewname: + if view.get("name") == viewname.decode('utf-8'): folderid = view.get("id") - utils.logMsg("BrowseContent","viewname: %s - type: %s - folderid: %s - filter: %s" %(viewname, type, folderid, filter)) + utils.logMsg("BrowseContent","viewname: %s - type: %s - folderid: %s - filter: %s" %(viewname.decode('utf-8'), type.decode('utf-8'), folderid.decode('utf-8'), filter.decode('utf-8'))) #set the correct params for the content type #only proceed if we have a folderid if folderid: @@ -494,14 +494,13 @@ def BrowseContent(viewname, type="", folderid=""): li = createListItemFromEmbyItem(item,art,doUtils) if item.get("IsFolder") == True: #for folders we add an additional browse request, passing the folderId - path = "%s?id=%s&mode=browsecontent&type=%s&folderid=%s" % (sys.argv[0], viewname, type, item.get("Id")) + path = "%s?id=%s&mode=browsecontent&type=%s&folderid=%s" % (sys.argv[0].decode('utf-8'), viewname.decode('utf-8'), type.decode('utf-8'), item.get("Id").decode('utf-8')) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=path, listitem=li, isFolder=True) else: #playable item, set plugin path and mediastreams xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=li.getProperty("path"), listitem=li) - xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) if filter == "recent": xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) else: @@ -510,6 +509,8 @@ def BrowseContent(viewname, type="", folderid=""): xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RUNTIME) + xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) + ##### CREATE LISTITEM FROM EMBY METADATA ##### def createListItemFromEmbyItem(item,art=artwork.Artwork(),doUtils=downloadutils.DownloadUtils()): API = api.API(item) From c04a0bab64da34369d64798b1f18054da475d2bb Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 4 Mar 2016 04:08:42 -0600 Subject: [PATCH 9/9] update url --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 246aea0f..5fd8a5a3 100644 --- a/addon.xml +++ b/addon.xml @@ -28,7 +28,7 @@ en GNU GENERAL PUBLIC LICENSE. Version 2, June 1991 - http://mediabrowser.tv/ + http://emby.media/ Welcome to Emby for Kodi A whole new way to manage and view your media library. The Emby addon for Kodi combines the best of Kodi - ultra smooth navigation, beautiful UIs and playback of any file under the sun, and Emby - the most powerful fully open source multi-client media metadata indexer and server. Emby for Kodi is the absolute best way to enjoy the incredible Kodi playback engine combined with the power of Emby's centralized database. Features: Direct integration with the Kodi library for native Kodi speed Instant synchronization with the Emby server Full support for Movie, TV and Music collections Emby Server direct stream and transcoding support - use Kodi when you are away from home!