Prettify music removal

This commit is contained in:
croneter 2018-04-07 14:30:17 +02:00
parent cac60d695d
commit c1b2d3d54f

View file

@ -1719,109 +1719,101 @@ class Music(Items):
# Update album artwork # Update album artwork
artwork.modify_artwork(artworks, albumid, v.KODI_TYPE_ALBUM, kodicursor) artwork.modify_artwork(artworks, albumid, v.KODI_TYPE_ALBUM, kodicursor)
def remove(self, itemid): def remove(self, plex_id):
""" """
Remove kodiid, file_id, pathid, plex reference Completely remove the item with plex_id from the Kodi and Plex DBs.
Orphaned entries will also be deleted.
""" """
plex_db = self.plex_db plex_dbitem = self.plex_db.getItem_byId(plex_id)
plex_dbitem = plex_db.getItem_byId(itemid)
try: try:
kodiid = plex_dbitem[0] kodi_id = plex_dbitem[0]
mediatype = plex_dbitem[4] file_id = plex_dbitem[1]
LOG.info("Removing %s kodiid: %s", mediatype, kodiid) parent_id = plex_dbitem[3]
kodi_type = plex_dbitem[4]
LOG.info("Removing %s with kodi_id: %s, parent_id: %s, file_id: %s",
kodi_type, kodi_id, parent_id, file_id)
except TypeError: except TypeError:
LOG.debug('Cannot delete item with plex id %s from Kodi', plex_id)
return return
##### PROCESS ITEM #####
# Remove the plex reference # Remove the plex reference
plex_db.removeItem(itemid) self.plex_db.removeItem(plex_id)
##### SONG #####
##### IF SONG ##### if kodi_type == v.KODI_TYPE_SONG:
if mediatype == v.KODI_TYPE_SONG:
# Delete song # Delete song
self.removeSong(kodiid) self.remove_song(kodi_id)
# This should only address single song scenario, where server doesn't actually # Album verification
# create an album for the song.
plex_db.removeWildItem(itemid)
for item in plex_db.getItem_byWildId(itemid): for item in self.plex_db.getItem_byWildId(plex_id):
item_kid = item[0] item_kid = item[0]
item_mediatype = item[1] item_kodi_type = item[1]
if item_mediatype == v.KODI_TYPE_ALBUM: if item_kodi_type == v.KODI_TYPE_ALBUM:
childs = plex_db.getItem_byParentId(item_kid, childs = self.plex_db.getItem_byParentId(item_kid,
v.KODI_TYPE_SONG) v.KODI_TYPE_SONG)
if not childs: if not childs:
# Delete album # Delete album
self.removeAlbum(item_kid) self.remove_album(item_kid)
##### IF ALBUM ##### ##### ALBUM #####
elif mediatype == v.KODI_TYPE_ALBUM: elif kodi_type == v.KODI_TYPE_ALBUM:
# Delete songs, album # Delete songs, album
album_songs = plex_db.getItem_byParentId(kodiid, album_songs = self.plex_db.getItem_byParentId(kodi_id,
v.KODI_TYPE_SONG) v.KODI_TYPE_SONG)
for song in album_songs: for song in album_songs:
self.removeSong(song[1]) self.remove_song(song[1])
# Remove plex songs # Remove plex songs
plex_db.removeItems_byParentId(kodiid, self.plex_db.removeItems_byParentId(kodi_id,
v.KODI_TYPE_SONG) v.KODI_TYPE_SONG)
# Remove the album # Remove the album
self.removeAlbum(kodiid) self.remove_album(kodi_id)
##### IF ARTIST ##### ##### IF ARTIST #####
elif mediatype == v.KODI_TYPE_ARTIST: elif kodi_type == v.KODI_TYPE_ARTIST:
# Delete songs, album, artist # Delete songs, album, artist
albums = plex_db.getItem_byParentId(kodiid, albums = self.plex_db.getItem_byParentId(kodi_id, v.KODI_TYPE_ALBUM)
v.KODI_TYPE_ALBUM)
for album in albums: for album in albums:
albumid = album[1] albumid = album[1]
album_songs = plex_db.getItem_byParentId(albumid, album_songs = self.plex_db.getItem_byParentId(albumid,
v.KODI_TYPE_SONG) v.KODI_TYPE_SONG)
for song in album_songs: for song in album_songs:
self.removeSong(song[1]) self.remove_song(song[1])
# Remove plex song # Remove plex song
plex_db.removeItems_byParentId(albumid, self.plex_db.removeItems_byParentId(albumid, v.KODI_TYPE_SONG)
v.KODI_TYPE_SONG)
# Remove plex artist # Remove plex artist
plex_db.removeItems_byParentId(albumid, self.plex_db.removeItems_byParentId(albumid, v.KODI_TYPE_ARTIST)
v.KODI_TYPE_ARTIST)
# Remove kodi album # Remove kodi album
self.removeAlbum(albumid) self.remove_album(albumid)
# Remove plex albums # Remove plex albums
plex_db.removeItems_byParentId(kodiid, self.plex_db.removeItems_byParentId(kodi_id, v.KODI_TYPE_ALBUM)
v.KODI_TYPE_ALBUM)
# Remove artist # Remove artist
self.removeArtist(kodiid) self.remove_artist(kodi_id)
LOG.info("Deleted %s: %s from kodi database", mediatype, itemid) LOG.debug("Deleted plex_id %s from kodi database", plex_id)
def removeSong(self, kodiid): def remove_song(self, kodi_id):
""" """
Remove song, and only the song Remove song, and only the song
""" """
self.artwork.delete_artwork(kodiid, v.KODI_TYPE_SONG, self.kodicursor) self.artwork.delete_artwork(kodi_id, v.KODI_TYPE_SONG, self.kodicursor)
self.kodicursor.execute("DELETE FROM song WHERE idSong = ?", self.kodicursor.execute("DELETE FROM song WHERE idSong = ?",
(kodiid,)) (kodi_id,))
def removeAlbum(self, kodiid): def remove_album(self, kodi_id):
""" """
Remove an album, and only the album Remove an album, and only the album
""" """
self.artwork.delete_artwork(kodiid, v.KODI_TYPE_ALBUM, self.kodicursor) self.artwork.delete_artwork(kodi_id, v.KODI_TYPE_ALBUM, self.kodicursor)
self.kodicursor.execute("DELETE FROM album WHERE idAlbum = ?", self.kodicursor.execute("DELETE FROM album WHERE idAlbum = ?",
(kodiid,)) (kodi_id,))
def removeArtist(self, kodiid): def remove_artist(self, kodi_id):
""" """
Remove an artist, and only the artist Remove an artist, and only the artist
""" """
self.artwork.delete_artwork(kodiid, self.artwork.delete_artwork(kodi_id,
v.KODI_TYPE_ARTIST, v.KODI_TYPE_ARTIST,
self.kodicursor) self.kodicursor)
self.kodicursor.execute("DELETE FROM artist WHERE idArtist = ?", self.kodicursor.execute("DELETE FROM artist WHERE idArtist = ?",
(kodiid,)) (kodi_id,))