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'])
obj.movie(movie, library=library)
#self.movies_compare(library, obj, embydb)
self.movies_compare(library, obj, embydb)
def movies_compare(self, library, obj, embydb):
@ -266,8 +266,8 @@ class FullSync(object):
current = obj.item_ids
for x in items:
if x not in current:
obj.remove(x)
if x[0] not in current:
obj.remove(x[0])
@progress()
def tvshows(self, library, dialog):
@ -277,7 +277,7 @@ class FullSync(object):
with self.library.database_lock:
with Database() as videodb:
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')):
@ -298,6 +298,8 @@ class FullSync(object):
dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10]))
obj.episode(episode)
self.tvshows_compare(library, obj, embydb)
def tvshows_compare(self, library, obj, embydb):
''' 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)
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 not in current:
obj.remove(x)
if x[0] not in current:
obj.remove(x[0])
@progress()
def musicvideos(self, library, dialog):
@ -333,7 +338,7 @@ class FullSync(object):
message=mvideo['Name'])
obj.musicvideo(mvideo, library=library)
#self.movies_compare(library, obj, embydb)
self.musicvideos_compare(library, obj, embydb)
def musicvideos_compare(self, library, obj, embydb):
@ -345,8 +350,8 @@ class FullSync(object):
current = obj.item_ids
for x in items:
if x not in current:
obj.remove(x)
if x[0] not in current:
obj.remove(x[0])
@progress()
def music(self, library, dialog):
@ -382,6 +387,24 @@ class FullSync(object):
message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
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))
def boxsets(self, library_id=None, dialog=None):

View file

@ -630,7 +630,7 @@ class UpdatedWorker(threading.Thread):
break
obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])[item['Type']]
LOG.info(item['Type'])
try:
if obj(item) and self.notify:
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_streams(*values(obj, QU.add_streams_obj))
self.artwork.add(obj['Artwork'], obj['MovieId'], "movie")
self.item_ids.append(obj['Id'])
return not update

View file

@ -30,6 +30,7 @@ class Music(KodiDb):
self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, musicdb.cursor)
@ -49,7 +50,7 @@ class Music(KodiDb):
@stop()
@emby_item()
@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 exists, entry will be updated.
@ -74,7 +75,7 @@ class Music(KodiDb):
obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name']
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['Bio'] = API.get_overview(obj['Bio'])
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.artwork.add(obj['Artwork'], obj['ArtistId'], "artist")
self.item_ids.append(obj['Id'])
def artist_add(self, obj):
@ -163,6 +165,7 @@ class Music(KodiDb):
self.update_album(*values(obj, QU.update_album_obj))
self.add_genres(*values(obj, QU.add_genres_obj))
self.artwork.add(obj['Artwork'], obj['AlbumId'], "album")
self.item_ids.append(obj['Id'])
def album_add(self, obj):
@ -218,10 +221,10 @@ class Music(KodiDb):
except Exception as error:
LOG.error(error)
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.item_ids.append(temp_obj['Id'])
@stop()
@ -290,6 +293,7 @@ class Music(KodiDb):
self.add_genres(*values(obj, QU.update_genre_song_obj))
self.artwork.add(obj['Artwork'], obj['SongId'], "song")
self.item_ids.append(obj['Id'])
if obj['SongAlbumId'] is None:
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.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):
@ -375,6 +379,7 @@ class Music(KodiDb):
continue
self.link(*values(temp_obj, QU.update_link_obj))
self.item_ids.append(temp_obj['Id'])
if obj['Album']:
@ -408,6 +413,7 @@ class Music(KodiDb):
continue
self.link_song_artist(*values(temp_obj, QU.update_song_artist_obj))
self.item_ids.append(temp_obj['Id'])
def single(self, obj):
@ -523,3 +529,32 @@ class Music(KodiDb):
self.artwork.delete(kodi_id, "song")
self.delete_song(kodi_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.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, videodb.cursor)
@ -136,6 +137,7 @@ class MusicVideos(KodiDb):
self.add_people(*values(obj, QU.add_people_mvideo_obj))
self.add_streams(*values(obj, QU.add_streams_obj))
self.artwork.add(obj['Artwork'], obj['MvideoId'], "musicvideo")
self.item_ids.append(obj['Id'])
return not update

View file

@ -22,15 +22,17 @@ LOG = logging.getLogger("EMBY."+__name__)
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.emby = embydb
self.video = videodb
self.direct_path = direct_path
self.update_library = update_library
self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, videodb.cursor)
@ -126,6 +128,7 @@ class TVShows(KodiDb):
self.add_genres(*values(obj, QU.add_genres_tvshow_obj))
self.add_studios(*values(obj, QU.add_studios_tvshow_obj))
self.artwork.add(obj['Artwork'], obj['ShowId'], "tvshow")
self.item_ids.append(obj['Id'])
season_episodes = {}
@ -133,9 +136,13 @@ class TVShows(KodiDb):
if season['SeriesId'] != obj['Id']:
obj['SeriesId'] = season['SeriesId']
self.item_ids.append(season['SeriesId'])
try:
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:
self.emby_db.add_reference(*values(obj, QUEM.add_reference_pool_obj))
@ -144,6 +151,7 @@ class TVShows(KodiDb):
try:
self.emby_db.get_item_by_id(season['Id'])[0]
self.item_ids.append(season['Id'])
except TypeError:
self.season(season, obj['ShowId'])
else:
@ -236,6 +244,7 @@ class TVShows(KodiDb):
if obj['Location'] != "Virtual":
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")
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_playstate(*values(obj, QU.add_bookmark_obj))
self.artwork.update(obj['Artwork']['Primary'], obj['EpisodeId'], "episode", "thumb")
self.item_ids.append(obj['Id'])
if not self.direct_path and obj['Resume']:
@ -421,6 +431,8 @@ class TVShows(KodiDb):
else:
obj['ShowId'] = obj['ShowId'][0]
self.item_ids.append(obj['SeriesId'])
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)):
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))
# Remove any series pooling episodes
@ -586,3 +598,35 @@ class TVShows(KodiDb):
self.artwork.delete(kodi_id, "episode")
self.delete_episode(kodi_id, file_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