From 4958d106ec2ab3f8ba9c2611b30edaae701f3582 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 18 Oct 2016 03:17:33 -0500 Subject: [PATCH] Reduce code movies,boxsets,mvideos --- resources/lib/objects/movies.py | 36 ++------------ resources/lib/objects/musicvideos.py | 73 ++++++---------------------- 2 files changed, 18 insertions(+), 91 deletions(-) diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py index 9339c050..87df1990 100644 --- a/resources/lib/objects/movies.py +++ b/resources/lib/objects/movies.py @@ -83,25 +83,10 @@ class Movies(Items): if self.pdialog: self.pdialog.update(heading=lang(29999), message="%s %s..." % (lang(33026), view_name)) - movies = dict(self.emby_db.get_checksum_by_view('Movie', view_id)) + movies = dict(self.emby_db.get_checksum_by_view("Movie", view_id)) emby_movies = self.emby.getMovies(view_id, basic=True, dialog=self.pdialog) - update_list = self.compare_checksum(emby_movies['Items'], movies) - log.info("Movies to update for %s: %s", view_name, update_list) - emby_movies = self.emby.getFullItems(update_list) - total = len(update_list) - - if self.pdialog: - self.pdialog.update(heading="Processing %s / %s items" % (view_name, total)) - - # Process additions and updates - if emby_movies: - self.added(emby_movies, total, view) - # Process deletes - if movies: - self.remove_all("Movie", movies.items()) - - return True + return self.compare("Movie", emby_movies['Items'], movies, view) def compare_boxsets(self): @@ -111,22 +96,7 @@ class Movies(Items): boxsets = dict(self.emby_db.get_checksum('BoxSet')) emby_boxsets = self.emby.getBoxset(dialog=self.pdialog) - update_list = self.compare_checksum(emby_boxsets['Items'], boxsets) - log.info("Boxsets to update: %s", update_list) - emby_boxsets = self.emby.getFullItems(update_list) - total = len(update_list) - - if self.pdialog: - self.pdialog.update(heading="Processing Boxsets / %s items" % total) - - # Processing additions and updates - if emby_boxsets: - self.added_boxset(emby_boxsets, total) - # Processing removals - if boxsets: - self.remove_all("BoxSet", boxsets.items()) - - return True + return self.compare("BoxSet", emby_boxsets['Items'], boxsets) def added(self, items, total=None, view=None): diff --git a/resources/lib/objects/musicvideos.py b/resources/lib/objects/musicvideos.py index 118c36ee..78595d96 100644 --- a/resources/lib/objects/musicvideos.py +++ b/resources/lib/objects/musicvideos.py @@ -47,78 +47,35 @@ class MusicVideos(Items): return actions.get(action) def compare_all(self): - pdialog = self.pdialog # Pull the list of musicvideos in Kodi views = self.emby_db.getView_byType('musicvideos') log.info("Media folders: %s", views) - try: - all_kodimvideos = dict(self.emby_db.get_checksum('MusicVideo')) - except ValueError: - all_kodimvideos = {} - - all_embymvideosIds = set() - updatelist = [] - for view in views: if self.should_stop(): return False - # Get items per view - viewId = view['id'] - viewName = view['name'] + if not self.compare_mvideos(view): + return False - if pdialog: - pdialog.update( - heading=lang(29999), - message="%s %s..." % (lang(33028), viewName)) - - all_embymvideos = self.emby.getMusicVideos(viewId, basic=True, dialog=pdialog) - for embymvideo in all_embymvideos['Items']: - - if self.should_stop(): - return False - - API = api.API(embymvideo) - itemid = embymvideo['Id'] - all_embymvideosIds.add(itemid) - - - if all_kodimvideos.get(itemid) != API.get_checksum(): - # Only update if musicvideo is not in Kodi or checksum is different - updatelist.append(itemid) - - log.info("MusicVideos to update for %s: %s", viewName, updatelist) - embymvideos = self.emby.getFullItems(updatelist) - self.total = len(updatelist) - del updatelist[:] - - - if pdialog: - pdialog.update(heading="Processing %s / %s items" % (viewName, self.total)) - - self.count = 0 - for embymvideo in embymvideos: - # Process individual musicvideo - if self.should_stop(): - return False - self.title = embymvideo['Name'] - self.update_pdialog() - self.add_update(embymvideo, view) - self.count += 1 - - ##### PROCESS DELETES ##### - - for kodimvideo in all_kodimvideos: - if kodimvideo not in all_embymvideosIds: - self.remove(kodimvideo) - - log.info("MusicVideos compare finished.") return True + def compare_mvideos(self, view): + + view_id = view['id'] + view_name = view['name'] + + if self.pdialog: + self.pdialog.update(heading=lang(29999), message="%s %s..." % (lang(33028), view_name)) + + mvideos = dict(self.emby_db.get_checksum_by_view('MusicVideo', view_id)) + emby_mvideos = self.emby.getMusicVideos(view_id, basic=True, dialog=self.pdialog) + + return self.compare("MusicVideo", emby_mvideos['Items'], mvideos, view) def added(self, items, total=None, view=None): + for item in super(MusicVideos, self).added(items, total): if self.add_update(item, view): self.content_pop(item.get('Name', "unknown"))