Merge pull request #201 from druscoe/in_progress_ui_updates

Allow for UI updates as the library is being sync'ed
This commit is contained in:
mcarlton00 2020-02-20 19:20:07 -05:00 committed by GitHub
commit 2fbdd191d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################## ##################################################################################################
from contextlib import contextmanager
import datetime import datetime
import logging import logging
@ -248,6 +249,13 @@ class FullSync(object):
raise raise
@contextmanager
def video_database_locks(self):
with self.library.database_lock:
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
yield videodb, jellyfindb
@progress() @progress()
def movies(self, library, dialog): def movies(self, library, dialog):
@ -255,26 +263,26 @@ class FullSync(object):
''' '''
Movies = self.library.media['Movies'] Movies = self.library.media['Movies']
with self.library.database_lock: for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')):
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')): self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex']
self.sync['RestorePoint'] = items['RestorePoint'] for index, movie in enumerate(items['Items']):
start_index = items['RestorePoint']['params']['StartIndex']
for index, movie in enumerate(items['Items']): dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
heading="%s: %s" % (translate('addon_name'), library['Name']),
message=movie['Name'])
obj.movie(movie, library=library)
dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100), with self.video_database_locks() as (videodb, jellyfindb):
heading="%s: %s" % (translate('addon_name'), library['Name']), obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
message=movie['Name'])
obj.movie(movie, library=library)
if self.update_library: if self.update_library:
self.movies_compare(library, obj, jellyfindb) self.movies_compare(library, obj, jellyfindb)
def movies_compare(self, library, obj, jellyfinydb): def movies_compare(self, library, obj, jellyfinydb):
@ -296,32 +304,32 @@ class FullSync(object):
''' '''
TVShows = self.library.media['TVShows'] TVShows = self.library.media['TVShows']
with self.library.database_lock: for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)
for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')): with self.video_database_locks() as (videodb, jellyfindb):
obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
for index, show in enumerate(items['Items']): for index, show in enumerate(items['Items']):
percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100) percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100)
message = show['Name'] message = show['Name']
dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message) dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)
if obj.tvshow(show, library=library) is not False: if obj.tvshow(show, library=library) is not False:
for episodes in server.get_episode_by_show(show['Id']): for episodes in server.get_episode_by_show(show['Id']):
for episode in episodes['Items']: for episode in episodes['Items']:
dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10])) dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10]))
obj.episode(episode) obj.episode(episode)
if self.update_library: with self.video_database_locks() as (videodb, jellyfindb):
self.tvshows_compare(library, obj, jellyfindb) obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)
if self.update_library:
self.tvshows_compare(library, obj, jellyfindb)
def tvshows_compare(self, library, obj, jellyfindb): def tvshows_compare(self, library, obj, jellyfindb):
@ -346,25 +354,25 @@ class FullSync(object):
''' '''
MusicVideos = self.library.media['MusicVideos'] MusicVideos = self.library.media['MusicVideos']
with self.library.database_lock: for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')):
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path)
for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')): with self.video_database_locks() as (videodb, jellyfindb):
obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
for index, mvideo in enumerate(items['Items']): for index, mvideo in enumerate(items['Items']):
dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100), dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
heading="%s: %s" % (translate('addon_name'), library['Name']), heading="%s: %s" % (translate('addon_name'), library['Name']),
message=mvideo['Name']) message=mvideo['Name'])
obj.musicvideo(mvideo, library=library) obj.musicvideo(mvideo, library=library)
if self.update_library: with self.video_database_locks() as (videodb, jellyfindb):
self.musicvideos_compare(library, obj, jellyfindb) obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path)
if self.update_library:
self.musicvideos_compare(library, obj, jellyfindb)
def musicvideos_compare(self, library, obj, jellyfindb): def musicvideos_compare(self, library, obj, jellyfindb):
@ -447,22 +455,20 @@ class FullSync(object):
''' '''
Movies = self.library.media['Movies'] Movies = self.library.media['Movies']
with self.library.database_lock: for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')):
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
for index, boxset in enumerate(items['Items']): for index, boxset in enumerate(items['Items']):
dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100), dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
heading="%s: %s" % (translate('addon_name'), translate('boxsets')), heading="%s: %s" % (translate('addon_name'), translate('boxsets')),
message=boxset['Name']) message=boxset['Name'])
obj.boxset(boxset) obj.boxset(boxset)
def refresh_boxsets(self): def refresh_boxsets(self):
@ -470,12 +476,9 @@ class FullSync(object):
''' '''
Movies = self.library.media['Movies'] Movies = self.library.media['Movies']
with self.library.database_lock: with self.video_database_locks() as (videodb, jellyfindb):
with Database() as videodb: obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
with Database('jellyfin') as jellyfindb: obj.boxsets_reset()
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
obj.boxsets_reset()
self.boxsets(None) self.boxsets(None)