Offline mode for views

This commit is contained in:
angelblue05 2017-10-04 17:34:00 -05:00
parent 9f355989a6
commit 6be4ffca3d
5 changed files with 61 additions and 7 deletions

View file

@ -122,7 +122,25 @@ class Embydb_Functions():
views.append({ views.append({
'id': row[0], 'id': row[0],
'name': row[1] 'name': row[1],
'mediatype': mediatype
})
if mediatype in ('tvshows', 'movies'):
query = ' '.join((
"SELECT view_id, view_name",
"FROM view",
"WHERE media_type = ?"
))
self.embycursor.execute(query, ("mixed",))
rows = self.embycursor.fetchall()
for row in rows:
views.append({
'id': row[0],
'name': row[1],
'mediatype': "mixed"
}) })
return views return views

View file

@ -372,6 +372,12 @@ class LibrarySync(threading.Thread):
# Compare views, assign correct tags to items # Compare views, assign correct tags to items
views.Views(cursor_emby, cursor_video).maintain() views.Views(cursor_emby, cursor_video).maintain()
def offline_mode_views(self):
with database.DatabaseConn('emby') as cursor_emby:
with database.DatabaseConn() as cursor_video:
views.Views(cursor_emby, cursor_video).offline_mode()
def movies(self, embycursor, kodicursor, pdialog): def movies(self, embycursor, kodicursor, pdialog):
# Get movies from emby # Get movies from emby

View file

@ -79,6 +79,9 @@ class Service(object):
# Clear video nodes properties # Clear video nodes properties
VideoNodes().clearProperties() VideoNodes().clearProperties()
# assume offline mode
log.info("Loading existing views...")
librarysync.LibrarySync().offline_mode_views()
# Set the minimum database version # Set the minimum database version
window('emby_minDBVersion', value="1.1.63") window('emby_minDBVersion', value="1.1.63")

View file

@ -77,7 +77,7 @@ class UserClient(threading.Thread):
def verify_server(self): def verify_server(self):
try: try:
url = "%s/emby/system/info/public?format=json" % self.get_server() url = "%s/emby/system/info/public?format=json" % self.get_server() # tried system/public but can't get reliable response from the server?
self.doutils.downloadUrl(url, authenticate=False) self.doutils.downloadUrl(url, authenticate=False)
return True return True
except Exception as error: except Exception as error:
@ -147,7 +147,7 @@ class UserClient(threading.Thread):
user = self.doutils.downloadUrl("{server}/emby/Users/{UserId}?format=json") user = self.doutils.downloadUrl("{server}/emby/Users/{UserId}?format=json")
settings('username', value=user['Name']) settings('username', value=user['Name'])
self._user = user self._user = user
window('emby.userinfo.json', user)
if "PrimaryImageTag" in self._user: if "PrimaryImageTag" in self._user:
window('EmbyUserImage', window('EmbyUserImage',
value=artwork.Artwork().get_user_artwork(self._user['Id'], 'Primary')) value=artwork.Artwork().get_user_artwork(self._user['Id'], 'Primary'))

View file

@ -151,11 +151,15 @@ class Views(object):
self.emby_db.addView(view_id, view_name, view_type, tag_id, group_series) self.emby_db.addView(view_id, view_name, view_type, tag_id, group_series)
def is_grouped_series(self, view_id, view_type): def is_grouped_series(self, view_id, view_type):
if window('emby.userinfo.json')['Policy']['IsAdministrator']:
try: try:
return self.emby.get_view_options(view_id)['EnableAutomaticSeriesGrouping'] if view_type == "tvshows" else None return self.emby.get_view_options(view_id)['EnableAutomaticSeriesGrouping'] if view_type == "tvshows" else None
except Exception as error: # Currently admin only api entrypoint except Exception as error: # Currently admin only api entrypoint
log.error(error) log.error(error)
return None return None
else:
return None
def compare_view(self, media_type, view_id, view_name, view_type): def compare_view(self, media_type, view_id, view_name, view_type):
@ -344,6 +348,29 @@ class Views(object):
self.video_nodes.singleNode(index, tag, media_type, view_type) self.video_nodes.singleNode(index, tag, media_type, view_type)
self.total_nodes += 1 self.total_nodes += 1
def offline_mode(self):
# Just reads from the db and populate views that way
# total nodes for window properties
self.video_nodes.clearProperties()
for media_type in ('movies', 'tvshows', 'musicvideos', 'homevideos', 'music', 'photos'):
self.nodes = list() # Prevent duplicate for nodes of the same type
self.playlists = list() # Prevent duplicate for playlists of the same type
views = self.emby_db.getView_byType(media_type)
for view in views:
try: # Make sure the view is in sorted views before proceeding
self.sorted_views.index(view['name'])
except ValueError:
self.sorted_views.append(view['name'])
self.add_playlist_node(media_type, view['id'], view['name'], view['mediatype'])
self.add_single_nodes()
window('Emby.nodes.total', str(self.total_nodes))
class Playlist(object): class Playlist(object):