Move method to embydb

to avoid opening a new db conn
This commit is contained in:
angelblue05 2016-11-06 14:49:37 -06:00
parent 83f88eef33
commit aab9750b40
5 changed files with 33 additions and 4 deletions

View file

@ -99,7 +99,6 @@ class DatabaseConn(object):
def __enter__(self): def __enter__(self):
# Open the connection # Open the connection
self.path = self._SQL(self.db_file) self.path = self._SQL(self.db_file)
log.info("opening: %s", self.path)
#traceback.print_stack() #traceback.print_stack()
if settings('dblock') == "true": if settings('dblock') == "true":

View file

@ -5,6 +5,8 @@
import logging import logging
from sqlite3 import OperationalError from sqlite3 import OperationalError
import downloadutils
################################################################################################## ##################################################################################################
log = logging.getLogger("EMBY."+__name__) log = logging.getLogger("EMBY."+__name__)
@ -18,6 +20,7 @@ class Embydb_Functions():
def __init__(self, embycursor): def __init__(self, embycursor):
self.embycursor = embycursor self.embycursor = embycursor
self.download = downloadutils.DownloadUtils().downloadUrl
def get_version(self, version=None): def get_version(self, version=None):
@ -52,6 +55,33 @@ class Embydb_Functions():
return views 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): def getView_byId(self, viewid):

View file

@ -141,7 +141,7 @@ class Movies(Items):
if not view: if not view:
# Get view tag from emby # 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) log.debug("View tag found: %s", viewtag)
else: else:
viewtag = view['name'] viewtag = view['name']

View file

@ -115,7 +115,7 @@ class MusicVideos(Items):
if not view: if not view:
# Get view tag from emby # 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) log.debug("View tag found: %s", viewtag)
else: else:
viewtag = view['name'] viewtag = view['name']

View file

@ -266,7 +266,7 @@ class TVShows(Items):
if view is None: if view is None:
# Get view tag from emby # 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) log.debug("View tag found: %s", viewtag)
else: else:
viewtag = view['name'] viewtag = view['name']