Allow for UI updates as the library is being sync'ed

Periodically release the locks on the database as the sync with the
server is being performed. This allows the UI to communicate with its
database and update the UI in real time.

Taken this oppurtunity to refactor some common code improve
maintainance.
This commit is contained in:
Chuddah 2020-02-18 23:23:47 +00:00
parent 5fc60fce6b
commit af810861c8
1 changed files with 67 additions and 64 deletions

View File

@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from contextlib import contextmanager
import datetime
import logging
@ -248,6 +249,13 @@ class FullSync(object):
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()
def movies(self, library, dialog):
@ -255,14 +263,11 @@ class FullSync(object):
'''
Movies = self.library.media['Movies']
with self.library.database_lock:
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'], "Movie", 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']
start_index = items['RestorePoint']['params']['StartIndex']
@ -273,6 +278,9 @@ class FullSync(object):
message=movie['Name'])
obj.movie(movie, library=library)
with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
if self.update_library:
self.movies_compare(library, obj, jellyfindb)
@ -296,13 +304,11 @@ class FullSync(object):
'''
TVShows = self.library.media['TVShows']
with self.library.database_lock:
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']
start_index = items['RestorePoint']['params']['StartIndex']
@ -320,6 +326,8 @@ class FullSync(object):
dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10]))
obj.episode(episode)
with self.video_database_locks() as (videodb, jellyfindb):
obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)
if self.update_library:
self.tvshows_compare(library, obj, jellyfindb)
@ -346,13 +354,11 @@ class FullSync(object):
'''
MusicVideos = self.library.media['MusicVideos']
with self.library.database_lock:
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']
start_index = items['RestorePoint']['params']['StartIndex']
@ -363,6 +369,8 @@ class FullSync(object):
message=mvideo['Name'])
obj.musicvideo(mvideo, library=library)
with self.video_database_locks() as (videodb, jellyfindb):
obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path)
if self.update_library:
self.musicvideos_compare(library, obj, jellyfindb)
@ -447,13 +455,11 @@ class FullSync(object):
'''
Movies = self.library.media['Movies']
with self.library.database_lock:
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']
start_index = items['RestorePoint']['params']['StartIndex']
@ -470,10 +476,7 @@ class FullSync(object):
'''
Movies = self.library.media['Movies']
with self.library.database_lock:
with Database() as videodb:
with Database('jellyfin') as jellyfindb:
with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
obj.boxsets_reset()