Remove content with update library

Now remove irrelevant content as well
This commit is contained in:
angelblue05 2018-10-04 05:10:25 -05:00
parent c63bfd1346
commit 586717c7a1
6 changed files with 121 additions and 18 deletions

View file

@ -254,7 +254,7 @@ class FullSync(object):
message=movie['Name']) message=movie['Name'])
obj.movie(movie, library=library) obj.movie(movie, library=library)
#self.movies_compare(library, obj, embydb) self.movies_compare(library, obj, embydb)
def movies_compare(self, library, obj, embydb): def movies_compare(self, library, obj, embydb):
@ -266,8 +266,8 @@ class FullSync(object):
current = obj.item_ids current = obj.item_ids
for x in items: for x in items:
if x not in current: if x[0] not in current:
obj.remove(x) obj.remove(x[0])
@progress() @progress()
def tvshows(self, library, dialog): def tvshows(self, library, dialog):
@ -277,7 +277,7 @@ class FullSync(object):
with self.library.database_lock: with self.library.database_lock:
with Database() as videodb: with Database() as videodb:
with Database('emby') as embydb: with Database('emby') as embydb:
obj = TVShows(self.server, embydb, videodb, self.direct_path) obj = TVShows(self.server, embydb, videodb, self.direct_path, True)
for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):
@ -298,6 +298,8 @@ class FullSync(object):
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)
self.tvshows_compare(library, obj, embydb)
def tvshows_compare(self, library, obj, embydb): def tvshows_compare(self, library, obj, embydb):
''' Compare entries from library to what's in the embydb. Remove surplus ''' Compare entries from library to what's in the embydb. Remove surplus
@ -305,11 +307,14 @@ class FullSync(object):
db = emby_db.EmbyDatabase(embydb.cursor) db = emby_db.EmbyDatabase(embydb.cursor)
items = db.get_item_by_media_folder(library['Id']) items = db.get_item_by_media_folder(library['Id'])
for x in list(items):
items.extend(obj.get_child(x[0]))
current = obj.item_ids current = obj.item_ids
for x in items: for x in items:
if x not in current: if x[0] not in current:
obj.remove(x) obj.remove(x[0])
@progress() @progress()
def musicvideos(self, library, dialog): def musicvideos(self, library, dialog):
@ -333,7 +338,7 @@ class FullSync(object):
message=mvideo['Name']) message=mvideo['Name'])
obj.musicvideo(mvideo, library=library) obj.musicvideo(mvideo, library=library)
#self.movies_compare(library, obj, embydb) self.musicvideos_compare(library, obj, embydb)
def musicvideos_compare(self, library, obj, embydb): def musicvideos_compare(self, library, obj, embydb):
@ -345,8 +350,8 @@ class FullSync(object):
current = obj.item_ids current = obj.item_ids
for x in items: for x in items:
if x not in current: if x[0] not in current:
obj.remove(x) obj.remove(x[0])
@progress() @progress()
def music(self, library, dialog): def music(self, library, dialog):
@ -382,6 +387,24 @@ class FullSync(object):
message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7])) message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
obj.song(song) obj.song(song)
self.music_compare(library, obj, embydb)
def music_compare(self, library, obj, embydb):
''' Compare entries from library to what's in the embydb. Remove surplus
'''
db = emby_db.EmbyDatabase(embydb.cursor)
items = db.get_item_by_media_folder(library['Id'])
for x in list(items):
items.extend(obj.get_child(x[0]))
current = obj.item_ids
for x in items:
if x[0] not in current:
obj.remove(x[0])
@progress(_(33018)) @progress(_(33018))
def boxsets(self, library_id=None, dialog=None): def boxsets(self, library_id=None, dialog=None):

View file

@ -630,7 +630,7 @@ class UpdatedWorker(threading.Thread):
break break
obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])[item['Type']] obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])[item['Type']]
LOG.info(item['Type'])
try: try:
if obj(item) and self.notify: if obj(item) and self.notify:
self.notify_output.put((item['Type'], api.API(item).get_naming())) self.notify_output.put((item['Type'], api.API(item).get_naming()))

View file

@ -126,7 +126,6 @@ class Movies(KodiDb):
self.add_people(*values(obj, QU.add_people_movie_obj)) self.add_people(*values(obj, QU.add_people_movie_obj))
self.add_streams(*values(obj, QU.add_streams_obj)) self.add_streams(*values(obj, QU.add_streams_obj))
self.artwork.add(obj['Artwork'], obj['MovieId'], "movie") self.artwork.add(obj['Artwork'], obj['MovieId'], "movie")
self.item_ids.append(obj['Id']) self.item_ids.append(obj['Id'])
return not update return not update

View file

@ -30,6 +30,7 @@ class Music(KodiDb):
self.emby_db = emby_db.EmbyDatabase(embydb.cursor) self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, musicdb.cursor) KodiDb.__init__(self, musicdb.cursor)
@ -49,7 +50,7 @@ class Music(KodiDb):
@stop() @stop()
@emby_item() @emby_item()
@library_check() @library_check()
def artist(self, item, e_item, library, artist_type=None): def artist(self, item, e_item, library):
''' If item does not exist, entry will be added. ''' If item does not exist, entry will be added.
If item exists, entry will be updated. If item exists, entry will be updated.
@ -74,7 +75,7 @@ class Music(KodiDb):
obj['LibraryId'] = library['Id'] obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name'] obj['LibraryName'] = library['Name']
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['ArtistType'] = artist_type or "MusicArtist" obj['ArtistType'] = "MusicArtist"
obj['Genre'] = " / ".join(obj['Genres'] or []) obj['Genre'] = " / ".join(obj['Genres'] or [])
obj['Bio'] = API.get_overview(obj['Bio']) obj['Bio'] = API.get_overview(obj['Bio'])
obj['Artwork'] = API.get_all_artwork(self.objects.map(item, 'ArtworkMusic'), True) obj['Artwork'] = API.get_all_artwork(self.objects.map(item, 'ArtworkMusic'), True)
@ -96,6 +97,7 @@ class Music(KodiDb):
self.update(obj['Genre'], obj['Bio'], obj['Thumb'], obj['Backdrops'], obj['LastScraped'], obj['ArtistId']) self.update(obj['Genre'], obj['Bio'], obj['Thumb'], obj['Backdrops'], obj['LastScraped'], obj['ArtistId'])
self.artwork.add(obj['Artwork'], obj['ArtistId'], "artist") self.artwork.add(obj['Artwork'], obj['ArtistId'], "artist")
self.item_ids.append(obj['Id'])
def artist_add(self, obj): def artist_add(self, obj):
@ -163,6 +165,7 @@ class Music(KodiDb):
self.update_album(*values(obj, QU.update_album_obj)) self.update_album(*values(obj, QU.update_album_obj))
self.add_genres(*values(obj, QU.add_genres_obj)) self.add_genres(*values(obj, QU.add_genres_obj))
self.artwork.add(obj['Artwork'], obj['AlbumId'], "album") self.artwork.add(obj['Artwork'], obj['AlbumId'], "album")
self.item_ids.append(obj['Id'])
def album_add(self, obj): def album_add(self, obj):
@ -218,10 +221,10 @@ class Music(KodiDb):
except Exception as error: except Exception as error:
LOG.error(error) LOG.error(error)
continue continue
else:
self.update_artist_name(*values(temp_obj, QU.update_artist_name_obj))
self.update_artist_name(*values(temp_obj, QU.update_artist_name_obj))
self.link(*values(temp_obj, QU.update_link_obj)) self.link(*values(temp_obj, QU.update_link_obj))
self.item_ids.append(temp_obj['Id'])
@stop() @stop()
@ -290,6 +293,7 @@ class Music(KodiDb):
self.add_genres(*values(obj, QU.update_genre_song_obj)) self.add_genres(*values(obj, QU.update_genre_song_obj))
self.artwork.add(obj['Artwork'], obj['SongId'], "song") self.artwork.add(obj['Artwork'], obj['SongId'], "song")
self.item_ids.append(obj['Id'])
if obj['SongAlbumId'] is None: if obj['SongAlbumId'] is None:
self.artwork.add(obj['Artwork'], obj['AlbumId'], "album") self.artwork.add(obj['Artwork'], obj['AlbumId'], "album")
@ -320,7 +324,7 @@ class Music(KodiDb):
self.add_song(*values(obj, QU.add_song_obj)) self.add_song(*values(obj, QU.add_song_obj))
self.emby_db.add_reference(*values(obj, QUEM.add_reference_song_obj)) self.emby_db.add_reference(*values(obj, QUEM.add_reference_song_obj))
LOG.info("ADD song [%s/%s/%s] %s: %s", obj['PathId'], obj['AlbumId'], obj['SongId'], obj['Id'], obj['Title']) LOG.debug("ADD song [%s/%s/%s] %s: %s", obj['PathId'], obj['AlbumId'], obj['SongId'], obj['Id'], obj['Title'])
def song_update(self, obj): def song_update(self, obj):
@ -375,6 +379,7 @@ class Music(KodiDb):
continue continue
self.link(*values(temp_obj, QU.update_link_obj)) self.link(*values(temp_obj, QU.update_link_obj))
self.item_ids.append(temp_obj['Id'])
if obj['Album']: if obj['Album']:
@ -408,6 +413,7 @@ class Music(KodiDb):
continue continue
self.link_song_artist(*values(temp_obj, QU.update_song_artist_obj)) self.link_song_artist(*values(temp_obj, QU.update_song_artist_obj))
self.item_ids.append(temp_obj['Id'])
def single(self, obj): def single(self, obj):
@ -523,3 +529,32 @@ class Music(KodiDb):
self.artwork.delete(kodi_id, "song") self.artwork.delete(kodi_id, "song")
self.delete_song(kodi_id) self.delete_song(kodi_id)
LOG.info("DELETE song [%s] %s", kodi_id, item_id) LOG.info("DELETE song [%s] %s", kodi_id, item_id)
@emby_item()
def get_child(self, item_id, e_item):
''' Get all child elements from tv show emby id.
'''
obj = {'Id': item_id}
child = []
try:
obj['KodiId'] = e_item[0]
obj['FileId'] = e_item[1]
obj['ParentId'] = e_item[3]
obj['Media'] = e_item[4]
except TypeError:
return child
obj['ParentId'] = obj['KodiId']
for album in self.emby_db.get_item_by_parent_id(*values(obj, QUEM.get_item_by_parent_album_obj)):
temp_obj = dict(obj)
temp_obj['ParentId'] = album[1]
child.append((album[0],))
for song in self.emby_db.get_item_by_parent_id(*values(temp_obj, QUEM.get_item_by_parent_song_obj)):
child.append((song[0],))
return child

View file

@ -30,6 +30,7 @@ class MusicVideos(KodiDb):
self.emby_db = emby_db.EmbyDatabase(embydb.cursor) self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, videodb.cursor) KodiDb.__init__(self, videodb.cursor)
@ -136,6 +137,7 @@ class MusicVideos(KodiDb):
self.add_people(*values(obj, QU.add_people_mvideo_obj)) self.add_people(*values(obj, QU.add_people_mvideo_obj))
self.add_streams(*values(obj, QU.add_streams_obj)) self.add_streams(*values(obj, QU.add_streams_obj))
self.artwork.add(obj['Artwork'], obj['MvideoId'], "musicvideo") self.artwork.add(obj['Artwork'], obj['MvideoId'], "musicvideo")
self.item_ids.append(obj['Id'])
return not update return not update

View file

@ -22,15 +22,17 @@ LOG = logging.getLogger("EMBY."+__name__)
class TVShows(KodiDb): class TVShows(KodiDb):
def __init__(self, server, embydb, videodb, direct_path): def __init__(self, server, embydb, videodb, direct_path, update_library=False):
self.server = server self.server = server
self.emby = embydb self.emby = embydb
self.video = videodb self.video = videodb
self.direct_path = direct_path self.direct_path = direct_path
self.update_library = update_library
self.emby_db = emby_db.EmbyDatabase(embydb.cursor) self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, videodb.cursor) KodiDb.__init__(self, videodb.cursor)
@ -126,6 +128,7 @@ class TVShows(KodiDb):
self.add_genres(*values(obj, QU.add_genres_tvshow_obj)) self.add_genres(*values(obj, QU.add_genres_tvshow_obj))
self.add_studios(*values(obj, QU.add_studios_tvshow_obj)) self.add_studios(*values(obj, QU.add_studios_tvshow_obj))
self.artwork.add(obj['Artwork'], obj['ShowId'], "tvshow") self.artwork.add(obj['Artwork'], obj['ShowId'], "tvshow")
self.item_ids.append(obj['Id'])
season_episodes = {} season_episodes = {}
@ -133,9 +136,13 @@ class TVShows(KodiDb):
if season['SeriesId'] != obj['Id']: if season['SeriesId'] != obj['Id']:
obj['SeriesId'] = season['SeriesId'] obj['SeriesId'] = season['SeriesId']
self.item_ids.append(season['SeriesId'])
try: try:
self.emby_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0] self.emby_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0]
if self.update_library:
season_episodes[season['Id']] = season['SeriesId']
except TypeError: except TypeError:
self.emby_db.add_reference(*values(obj, QUEM.add_reference_pool_obj)) self.emby_db.add_reference(*values(obj, QUEM.add_reference_pool_obj))
@ -144,6 +151,7 @@ class TVShows(KodiDb):
try: try:
self.emby_db.get_item_by_id(season['Id'])[0] self.emby_db.get_item_by_id(season['Id'])[0]
self.item_ids.append(season['Id'])
except TypeError: except TypeError:
self.season(season, obj['ShowId']) self.season(season, obj['ShowId'])
else: else:
@ -236,6 +244,7 @@ class TVShows(KodiDb):
if obj['Location'] != "Virtual": if obj['Location'] != "Virtual":
self.emby_db.add_reference(*values(obj, QUEM.add_reference_season_obj)) self.emby_db.add_reference(*values(obj, QUEM.add_reference_season_obj))
self.item_ids.append(obj['Id'])
self.artwork.add(obj['Artwork'], obj['SeasonId'], "season") self.artwork.add(obj['Artwork'], obj['SeasonId'], "season")
LOG.info("UPDATE season [%s/%s] %s: %s", obj['ShowId'], obj['SeasonId'], obj['Title'] or obj['Index'], obj['Id']) LOG.info("UPDATE season [%s/%s] %s: %s", obj['ShowId'], obj['SeasonId'], obj['Title'] or obj['Index'], obj['Id'])
@ -336,6 +345,7 @@ class TVShows(KodiDb):
self.add_streams(*values(obj, QU.add_streams_obj)) self.add_streams(*values(obj, QU.add_streams_obj))
self.add_playstate(*values(obj, QU.add_bookmark_obj)) self.add_playstate(*values(obj, QU.add_bookmark_obj))
self.artwork.update(obj['Artwork']['Primary'], obj['EpisodeId'], "episode", "thumb") self.artwork.update(obj['Artwork']['Primary'], obj['EpisodeId'], "episode", "thumb")
self.item_ids.append(obj['Id'])
if not self.direct_path and obj['Resume']: if not self.direct_path and obj['Resume']:
@ -421,6 +431,8 @@ class TVShows(KodiDb):
else: else:
obj['ShowId'] = obj['ShowId'][0] obj['ShowId'] = obj['ShowId'][0]
self.item_ids.append(obj['SeriesId'])
return True return True
@ -558,7 +570,7 @@ class TVShows(KodiDb):
if not self.emby_db.get_item_by_parent_id(*values(obj, QUEM.delete_item_by_parent_season_obj)): if not self.emby_db.get_item_by_parent_id(*values(obj, QUEM.delete_item_by_parent_season_obj)):
self.remove_show(obj['ParentId'], obj['Id']) self.remove_tvshow(obj['ParentId'], obj['Id'])
self.emby_db.remove_item_by_kodi_id(*values(obj, QUEM.delete_item_by_parent_tvshow_obj)) self.emby_db.remove_item_by_kodi_id(*values(obj, QUEM.delete_item_by_parent_tvshow_obj))
# Remove any series pooling episodes # Remove any series pooling episodes
@ -586,3 +598,35 @@ class TVShows(KodiDb):
self.artwork.delete(kodi_id, "episode") self.artwork.delete(kodi_id, "episode")
self.delete_episode(kodi_id, file_id) self.delete_episode(kodi_id, file_id)
LOG.info("DELETE episode [%s/%s] %s", file_id, kodi_id, item_id) LOG.info("DELETE episode [%s/%s] %s", file_id, kodi_id, item_id)
@emby_item()
def get_child(self, item_id, e_item):
''' Get all child elements from tv show emby id.
'''
obj = {'Id': item_id}
child = []
try:
obj['KodiId'] = e_item[0]
obj['FileId'] = e_item[1]
obj['ParentId'] = e_item[3]
obj['Media'] = e_item[4]
except TypeError:
return child
obj['ParentId'] = obj['KodiId']
for season in self.emby_db.get_item_by_parent_id(*values(obj, QUEM.get_item_by_parent_season_obj)):
temp_obj = dict(obj)
temp_obj['ParentId'] = season[1]
child.append(season[0])
for episode in self.emby_db.get_item_by_parent_id(*values(temp_obj, QUEM.get_item_by_parent_episode_obj)):
child.append(episode[0])
for episode in self.emby_db.get_media_by_parent_id(obj['Id']):
child.append(episode[0])
return child