Follow ordered views

This affects the node numbering.
This commit is contained in:
angelblue05 2016-02-24 22:28:42 -06:00
parent dc7473bfae
commit c3d78c871e
3 changed files with 66 additions and 26 deletions

View file

@ -118,6 +118,15 @@ class Embydb_Functions():
)) ))
self.embycursor.execute(query, (name, tagid, mediafolderid)) self.embycursor.execute(query, (name, tagid, mediafolderid))
def removeView(self, viewid):
query = ' '.join((
"DELETE FROM view",
"WHERE view_id = ?"
))
self.embycursor.execute(query, (viewid,))
def getItem_byId(self, embyid): def getItem_byId(self, embyid):
embycursor = self.embycursor embycursor = self.embycursor

View file

@ -353,13 +353,6 @@ class LibrarySync(threading.Thread):
kodiconn = utils.kodiSQL('video') kodiconn = utils.kodiSQL('video')
kodicursor = kodiconn.cursor() kodicursor = kodiconn.cursor()
# Erase saved views
embycursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = embycursor.fetchall()
for row in rows:
tablename = row[0]
if tablename == "view":
embycursor.execute("DELETE FROM " + tablename)
# Compare views, assign correct tags to items # Compare views, assign correct tags to items
self.maintainViews(embycursor, kodicursor) self.maintainViews(embycursor, kodicursor)
@ -382,6 +375,15 @@ class LibrarySync(threading.Thread):
url = "{server}/emby/Users/{UserId}/Views?format=json" url = "{server}/emby/Users/{UserId}/Views?format=json"
result = doUtils(url) result = doUtils(url)
grouped_views = result['Items'] grouped_views = result['Items']
ordered_views = self.emby.getViews(sortedlist=True)
sorted_views = []
for view in ordered_views:
if view['type'] == "music":
continue
if view['type'] == "mixed":
sorted_views.append(view['name'])
sorted_views.append(view['name'])
try: try:
groupedFolders = self.user.userSettings['Configuration']['GroupedFolders'] groupedFolders = self.user.userSettings['Configuration']['GroupedFolders']
@ -394,6 +396,7 @@ class LibrarySync(threading.Thread):
vnodes.clearProperties() vnodes.clearProperties()
totalnodes = 0 totalnodes = 0
current_views = emby_db.getViews()
# Set views for supported media type # Set views for supported media type
mediatypes = ['movies', 'tvshows', 'musicvideos', 'homevideos', 'music', 'photos'] mediatypes = ['movies', 'tvshows', 'musicvideos', 'homevideos', 'music', 'photos']
for mediatype in mediatypes: for mediatype in mediatypes:
@ -427,7 +430,7 @@ class LibrarySync(threading.Thread):
current_tagid = view[2] current_tagid = view[2]
except TypeError: except TypeError:
self.logMsg("Creating viewid: %s in Emby database." % folderid, 1) log("Creating viewid: %s in Emby database." % folderid, 1)
tagid = kodi_db.createTag(foldername) tagid = kodi_db.createTag(foldername)
# Create playlist for the video library # Create playlist for the video library
if (foldername not in playlists and if (foldername not in playlists and
@ -435,9 +438,11 @@ class LibrarySync(threading.Thread):
utils.playlistXSP(mediatype, foldername, folderid, viewtype) utils.playlistXSP(mediatype, foldername, folderid, viewtype)
playlists.append(foldername) playlists.append(foldername)
# Create the video node # Create the video node
if (foldername not in nodes and if foldername not in nodes and mediatype not in ("musicvideos", "music"):
mediatype in ('movies', 'tvshows', 'musicvideos', 'homevideos')): vnodes.viewNode(sorted_views.index(foldername), foldername, mediatype,
vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) viewtype, folderid)
if viewtype == "mixed": # Change the value
sorted_views[sorted_views.index(foldername)] = "%ss" % foldername
nodes.append(foldername) nodes.append(foldername)
totalnodes += 1 totalnodes += 1
# Add view to emby database # Add view to emby database
@ -451,6 +456,13 @@ class LibrarySync(threading.Thread):
"viewtype: %s" % current_viewtype, "viewtype: %s" % current_viewtype,
"tagid: %s" % current_tagid)), 2) "tagid: %s" % current_tagid)), 2)
# View is still valid
try:
current_views.remove(folderid)
except ValueError:
# View was just created, nothing to remove
pass
# View was modified, update with latest info # View was modified, update with latest info
if current_viewname != foldername: if current_viewname != foldername:
log("viewid: %s new viewname: %s" % (folderid, foldername), 1) log("viewid: %s new viewname: %s" % (folderid, foldername), 1)
@ -468,7 +480,7 @@ class LibrarySync(threading.Thread):
# Delete video node # Delete video node
if mediatype != "musicvideos": if mediatype != "musicvideos":
vnodes.viewNode( vnodes.viewNode(
indexnumber=totalnodes, indexnumber=sorted_views.index(foldername),
tagname=current_viewname, tagname=current_viewname,
mediatype=mediatype, mediatype=mediatype,
viewtype=current_viewtype, viewtype=current_viewtype,
@ -481,7 +493,10 @@ class LibrarySync(threading.Thread):
playlists.append(foldername) playlists.append(foldername)
# Add new video node # Add new video node
if foldername not in nodes and mediatype != "musicvideos": if foldername not in nodes and mediatype != "musicvideos":
vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) vnodes.viewNode(sorted_views.index(foldername), foldername,
mediatype, viewtype, folderid)
if viewtype == "mixed": # Change the value
sorted_views[sorted_views.index(foldername)] = "%ss" % foldername
nodes.append(foldername) nodes.append(foldername)
totalnodes += 1 totalnodes += 1
@ -500,7 +515,10 @@ class LibrarySync(threading.Thread):
playlists.append(foldername) playlists.append(foldername)
# Create the video node if not already exists # Create the video node if not already exists
if foldername not in nodes and mediatype != "musicvideos": if foldername not in nodes and mediatype != "musicvideos":
vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) vnodes.viewNode(sorted_views.index(foldername), foldername,
mediatype, viewtype, folderid)
if viewtype == "mixed": # Change the value
sorted_views[sorted_views.index(foldername)] = "%ss" % foldername
nodes.append(foldername) nodes.append(foldername)
totalnodes += 1 totalnodes += 1
else: else:
@ -514,6 +532,11 @@ class LibrarySync(threading.Thread):
# Save total # Save total
utils.window('Emby.nodes.total', str(totalnodes)) utils.window('Emby.nodes.total', str(totalnodes))
# Remove any old referenced views
log("Removing views: %s" % current_views, 1)
for view in current_views:
emby_db.removeView(view)
def movies(self, embycursor, kodicursor, pdialog): def movies(self, embycursor, kodicursor, pdialog):
log = self.logMsg log = self.logMsg

View file

@ -305,11 +305,11 @@ class Read_EmbyServer():
log("Increase jump limit to: %s" % jump, 1) log("Increase jump limit to: %s" % jump, 1)
return items return items
def getViews(self, type, root=False): def getViews(self, mediatype="", root=False, sortedlist=False):
# Build a list of user views # Build a list of user views
doUtils = self.doUtils doUtils = self.doUtils
views = [] views = []
type = type.lower() mediatype = mediatype.lower()
if not root: if not root:
url = "{server}/emby/Users/{UserId}/Views?format=json" url = "{server}/emby/Users/{UserId}/Views?format=json"
@ -319,10 +319,8 @@ class Read_EmbyServer():
result = doUtils(url) result = doUtils(url)
try: try:
items = result['Items'] items = result['Items']
except TypeError: except TypeError:
self.logMsg("Error retrieving views for type: %s" % type, 2) self.logMsg("Error retrieving views for type: %s" % mediatype, 2)
else: else:
for item in items: for item in items:
@ -347,15 +345,25 @@ class Read_EmbyServer():
if itemId == folder['Id']: if itemId == folder['Id']:
itemtype = folder.get('CollectionType', "mixed") itemtype = folder.get('CollectionType', "mixed")
if (name not in ('Collections', 'Trailers') and (itemtype == type or if name not in ('Collections', 'Trailers'):
(itemtype == "mixed" and type in ("movies", "tvshows")))):
views.append({ if sortedlist:
views.append({
'name': name, 'name': name,
'type': itemtype, 'type': itemtype,
'id': itemId 'id': itemId
}) })
elif (itemtype == mediatype or
(itemtype == "mixed" and mediatype in ("movies", "tvshows"))):
views.append({
'name': name,
'type': itemtype,
'id': itemId
})
return views return views