Fix grouped views

Something changed in the emby returned paths so the verification was
failing. For now, we are getting one item from the media folder and
comparing using the user view to make sure we are referring to the
correct one with the tag name. Asked Luke for an api that would do this.
This commit is contained in:
angelblue05 2016-03-01 18:00:19 -06:00
parent e2a117ea97
commit 4cdf5c3c4d
2 changed files with 50 additions and 9 deletions

View file

@ -366,6 +366,7 @@ class LibrarySync(threading.Thread):
log = self.logMsg log = self.logMsg
# Compare the views to emby # Compare the views to emby
emby = self.emby
emby_db = embydb.Embydb_Functions(embycursor) emby_db = embydb.Embydb_Functions(embycursor)
kodi_db = kodidb.Kodidb_Functions(kodicursor) kodi_db = kodidb.Kodidb_Functions(kodicursor)
doUtils = self.doUtils doUtils = self.doUtils
@ -404,7 +405,7 @@ class LibrarySync(threading.Thread):
nodes = [] # Prevent duplicate for nodes of the same type nodes = [] # Prevent duplicate for nodes of the same type
playlists = [] # Prevent duplicate for playlists of the same type playlists = [] # Prevent duplicate for playlists of the same type
# Get media folders from server # Get media folders from server
folders = self.emby.getViews(mediatype, root=True) folders = emby.getViews(mediatype, root=True)
for folder in folders: for folder in folders:
folderid = folder['id'] folderid = folder['id']
@ -413,11 +414,25 @@ class LibrarySync(threading.Thread):
if folderid in groupedFolders: if folderid in groupedFolders:
# Media folders are grouped into userview # Media folders are grouped into userview
url = "{server}/emby/Users/{UserId}/Items?format=json"
params = {
'ParentId': folderid,
'Limit': 1
} # Get one item from server using the folderid
result = doUtils(url, parameters=params)
try:
verifyitem = result['Items'][0]['Id']
except (TypeError, IndexError):
# Something is wrong. Keep the same folder name.
# Could be the view is empty or the connection
pass
else:
for grouped_view in grouped_views: for grouped_view in grouped_views:
# This is only reserved for the detection of grouped views # This is only reserved for the detection of grouped views
if (grouped_view['Type'] == "UserView" and if (grouped_view['Type'] == "UserView" and
grouped_view.get('CollectionType') == mediatype and grouped_view.get('CollectionType') == mediatype):
grouped_view['Id'] in grouped_view.get('Path', "")): # Take the userview, and validate the item belong to the view
if emby.verifyView(grouped_view['Id'], verifyitem):
# Take the name of the userview # Take the name of the userview
foldername = grouped_view['Name'] foldername = grouped_view['Name']
break break

View file

@ -367,6 +367,32 @@ class Read_EmbyServer():
return views return views
def verifyView(self, parentid, itemid):
belongs = False
url = "{server}/emby/Users/{UserId}/Items?format=json"
params = {
'ParentId': parentid,
'CollapseBoxSetItems': False,
'IsVirtualUnaired': False,
'IsMissing': False,
'Recursive': True,
'Ids': itemid
}
result = self.doUtils(url, parameters=params)
try:
total = result['TotalRecordCount']
except TypeError:
# Something happened to the connection
pass
else:
if total:
belongs = True
return belongs
def getMovies(self, parentId, basic=False, dialog=None): def getMovies(self, parentId, basic=False, dialog=None):
items = self.getSection(parentId, "Movie", basic=basic, dialog=dialog) items = self.getSection(parentId, "Movie", basic=basic, dialog=dialog)