diff --git a/resources/lib/database.py b/resources/lib/database.py index 33574b76..d312a146 100644 --- a/resources/lib/database.py +++ b/resources/lib/database.py @@ -99,7 +99,6 @@ class DatabaseConn(object): def __enter__(self): # Open the connection self.path = self._SQL(self.db_file) - log.info("opening: %s", self.path) #traceback.print_stack() if settings('dblock') == "true": diff --git a/resources/lib/embydb_functions.py b/resources/lib/embydb_functions.py index f3d32aaa..2c71e5d0 100644 --- a/resources/lib/embydb_functions.py +++ b/resources/lib/embydb_functions.py @@ -5,6 +5,8 @@ import logging from sqlite3 import OperationalError +import downloadutils + ################################################################################################## log = logging.getLogger("EMBY."+__name__) @@ -18,6 +20,7 @@ class Embydb_Functions(): def __init__(self, embycursor): self.embycursor = embycursor + self.download = downloadutils.DownloadUtils().downloadUrl def get_version(self, version=None): @@ -52,6 +55,33 @@ class Embydb_Functions(): return views + def getView_embyId(self, item_id): + # Returns ancestors using embyId + url = "{server}/emby/Items/%s/Ancestors?UserId={UserId}&format=json" % item_id + for view in self.download(url): + + if view['Type'] == "CollectionFolder": + # Found view + view_id = view['Id'] + break + else: # No view found + return [None, None] + + # Compare to view table in emby database + query = ' '.join(( + + "SELECT view_name", + "FROM view", + "WHERE view_id = ?" + )) + self.embycursor.execute(query, (view_id,)) + try: + view_name = self.embycursor.fetchone()[0] + except TypeError: + view_name = None + + return [view_name, view_id] + def getView_byId(self, viewid): diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py index 2f1a12cc..9f21b172 100644 --- a/resources/lib/objects/movies.py +++ b/resources/lib/objects/movies.py @@ -141,7 +141,7 @@ class Movies(Items): if not view: # Get view tag from emby - viewtag, viewid, mediatype = self.emby.getView_embyId(itemid) + viewtag, viewid = emby_db.getView_embyId(itemid) log.debug("View tag found: %s", viewtag) else: viewtag = view['name'] diff --git a/resources/lib/objects/musicvideos.py b/resources/lib/objects/musicvideos.py index cc15a2ab..615b3c87 100644 --- a/resources/lib/objects/musicvideos.py +++ b/resources/lib/objects/musicvideos.py @@ -115,7 +115,7 @@ class MusicVideos(Items): if not view: # Get view tag from emby - viewtag, viewid, mediatype = self.emby.getView_embyId(itemid) + viewtag, viewid = emby_db.getView_embyId(itemid) log.debug("View tag found: %s", viewtag) else: viewtag = view['name'] diff --git a/resources/lib/objects/tvshows.py b/resources/lib/objects/tvshows.py index 211e662e..a94c205e 100644 --- a/resources/lib/objects/tvshows.py +++ b/resources/lib/objects/tvshows.py @@ -266,7 +266,7 @@ class TVShows(Items): if view is None: # Get view tag from emby - viewtag, viewid, mediatype = emby.getView_embyId(itemid) + viewtag, viewid = emby_db.getView_embyId(itemid) log.debug("View tag found: %s", viewtag) else: viewtag = view['name']