From c854ee621ea7707e4d4f7ecac341b8a6c2d7bde6 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 11 Jan 2016 09:57:45 +0100 Subject: [PATCH] videonodes v0.1 --- resources/lib/PlexAPI.py | 14 +++-- resources/lib/itemtypes.py | 3 ++ resources/lib/librarysync.py | 100 +++++++++++++---------------------- resources/lib/videonodes.py | 10 ++-- 4 files changed, 53 insertions(+), 74 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 495aae65..bbaceac8 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1594,12 +1594,16 @@ class API(): """ item = self.item item = item[self.child].attrib - regex = re.compile(r'''com.plexapp.agents.(.+)$''') + try: + item = item['guid'] + except KeyError: + return None - provider = regex.findall(item['guid']) + regex = re.compile(r'''com\.plexapp\.agents\.(.+)$''') + provider = regex.findall(item) try: provider = provider[0] - except KeyError: + except IndexError: provider = None return provider @@ -1662,7 +1666,7 @@ class API(): item = item[self.child].attrib try: rating = item['audienceRating'] - except: + except KeyError: rating = None return rating @@ -1674,7 +1678,7 @@ class API(): item = item[self.child].attrib try: year = item['year'] - except: + except KeyError: year = None return year diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 9d0b1609..7b9df1c0 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -333,6 +333,7 @@ class Movies(Items): shortplot = None tagline = API.getTagline() votecount = None + rating = API.getAudienceRating() year = API.getYear() imdb = API.getProvider('Imdb') @@ -346,9 +347,11 @@ class Movies(Items): studio = studios[0] except IndexError: studio = None + self.logMsg("Retrieved metadata for %s" % itemid, 2) # TODO: trailers trailer = None + self.logMsg("Retrieved trailer for %s" % itemid, 2) ##### GET THE FILE AND PATH ##### playurl = API.getFilePath() diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 08dbb8bc..1d3b3628 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -346,10 +346,11 @@ class LibrarySync(threading.Thread): starttotal = datetime.now() - # Set views - # self.maintainViews(embycursor, kodicursor) - # embyconn.commit() + # Ensure that DBs exist if called for very first time self.initializeDBs() + # Set views + self.maintainViews() + # Sync video library # process = { @@ -362,7 +363,6 @@ class LibrarySync(threading.Thread): process = { 'movies': self.PlexMovies, 'tvshows': self.PlexTVShows - # 'tvshows': self.PlexTVShows } for itemtype in process: @@ -420,79 +420,46 @@ class LibrarySync(threading.Thread): sound=False) return True - - def refreshViews(self): - - embyconn = utils.kodiSQL('emby') - embycursor = embyconn.cursor() - kodiconn = utils.kodiSQL('video') - kodicursor = kodiconn.cursor() - - # Compare views, assign correct tags to items - self.maintainViews(embycursor, kodicursor) - - self.dbCommit(kodiconn) - kodicursor.close() - - embyconn.commit() - embycursor.close() - - def maintainViews(self, embycursor, kodicursor): + def maintainViews(self): """ - Reverse engineering: + Compare the views to Plex - Input: - embycursor - kodicursor Output: vnodes.viewNode(totalnodes, foldername, mediatype, viewtype) kodi_db.createTag(foldername) kodi_db.updateTag(current_tagid, tagid, item[0],Current_viewtype[:-1]) """ - # Compare the views to emby + # Open DB links + embyconn = utils.kodiSQL('emby') + embycursor = embyconn.cursor() + kodiconn = utils.kodiSQL('video') + kodicursor = kodiconn.cursor() + emby_db = embydb.Embydb_Functions(embycursor) kodi_db = kodidb.Kodidb_Functions(kodicursor) doUtils = self.doUtils vnodes = self.vnodes - - # Get views - url = "{server}/emby/Users/{UserId}/Views?format=json" - result = doUtils.downloadUrl(url) - grouped_views = result['Items'] - try: - groupedFolders = self.user.userSettings['Configuration']['GroupedFolders'] - except TypeError: - url = "{server}/emby/Users/{UserId}?format=json" - result = doUtils.downloadUrl(url) - groupedFolders = result['Configuration']['GroupedFolders'] + # Get views + url = "{server}/library/sections" + result = doUtils.downloadUrl(url) + result = result['_children'] # total nodes for window properties vnodes.clearProperties() totalnodes = 0 # Set views for supported media type - mediatypes = ['movies', 'tvshows', 'musicvideos', 'homevideos', 'music'] - for mediatype in mediatypes: - - # Get media folders from server - folders = self.emby.getViews(mediatype, root=True) - for folder in folders: - - folderid = folder['id'] - foldername = folder['name'] + mediatypes = [ + 'movie', + 'show' + ] + for folder in result: + mediatype = folder['type'] + if mediatype in mediatypes: + folderid = folder['key'] + foldername = folder['title'] viewtype = folder['type'] - - if folderid in groupedFolders: - # Media folders are grouped into userview - for grouped_view in grouped_views: - # This is only reserved for the detection of grouped views - if (grouped_view['Type'] == "UserView" and - grouped_view.get('CollectionType') == mediatype and - grouped_view['Id'] not in grouped_view.get('Path', "")): - # Take the name of the userview - foldername = grouped_view['Name'] - break # Get current media folders from emby database view = emby_db.getView_byId(folderid) @@ -567,14 +534,19 @@ class LibrarySync(threading.Thread): totalnodes += 1 else: # Add video nodes listings - vnodes.singleNode(totalnodes, "Favorite movies", "movies", "favourites") - totalnodes += 1 - vnodes.singleNode(totalnodes, "Favorite tvshows", "tvshows", "favourites") - totalnodes += 1 - vnodes.singleNode(totalnodes, "channels", "movies", "channels") - totalnodes += 1 + # vnodes.singleNode(totalnodes, "Favorite movies", "movies", "favourites") + # totalnodes += 1 + # vnodes.singleNode(totalnodes, "Favorite tvshows", "tvshows", "favourites") + # totalnodes += 1 + # vnodes.singleNode(totalnodes, "channels", "movies", "channels") + # totalnodes += 1 # Save total utils.window('Emby.nodes.total', str(totalnodes)) + # commit changes to DB + embyconn.commit() + kodiconn.commit() + embyconn.close() + kodiconn.close() def GetUpdatelist(self, elementList, itemType, method, viewName, viewId): """ diff --git a/resources/lib/videonodes.py b/resources/lib/videonodes.py index ffd0700b..f81c8144 100644 --- a/resources/lib/videonodes.py +++ b/resources/lib/videonodes.py @@ -93,7 +93,7 @@ class VideoNodes(object): # Create index entry nodeXML = "%sindex.xml" % nodepath # Set windows property - path = "library://video/Emby - %s/" % dirname + path = "library://video/plexkodiconnect - %s/" % dirname for i in range(1, indexnumber): # Verify to make sure we don't create duplicates if utils.window('Emby.nodes.%s.index' % i) == path: @@ -124,7 +124,7 @@ class VideoNodes(object): } mediatypes = { # label according to nodetype per mediatype - 'movies': { + 'movie': { '1': tagname, '2': 30174, '4': 30177, @@ -134,7 +134,7 @@ class VideoNodes(object): '10': 30229, '11': 30230}, - 'tvshows': { + 'show': { '1': tagname, '2': 30170, '3': 30175, @@ -171,7 +171,7 @@ class VideoNodes(object): # Custom query path = "plugin://plugin.video.plexkodiconnect/?id=%s&mode=inprogressepisodes&limit=25"% tagname else: - path = "library://video/Emby - %s/%s_%s.xml" % (dirname, cleantagname, nodetype) + path = "library://video/plexkodiconnect - %s/%s_%s.xml" % (dirname, cleantagname, nodetype) windowpath = "ActivateWindow(Video,%s,return)" % path if nodetype == "all": @@ -276,7 +276,7 @@ class VideoNodes(object): cleantagname = utils.normalize_nodes(tagname) nodepath = xbmc.translatePath("special://profile/library/video/").decode('utf-8') nodeXML = "%semby_%s.xml" % (nodepath, cleantagname) - path = "library://video/emby_%s.xml" % (cleantagname) + path = "library://video/plexkodiconnect_%s.xml" % (cleantagname) windowpath = "ActivateWindow(Video,%s,return)" % path # Create the video node directory