Optimize code for deleting movies from Kodi DB
This commit is contained in:
parent
9101f49895
commit
2144995a29
2 changed files with 23 additions and 26 deletions
|
@ -449,15 +449,12 @@ class Movies(Items):
|
||||||
# Process playstates
|
# Process playstates
|
||||||
self.kodi_db.addPlaystate(fileid, resume, runtime, playcount, dateplayed)
|
self.kodi_db.addPlaystate(fileid, resume, runtime, playcount, dateplayed)
|
||||||
|
|
||||||
def remove(self, itemid):
|
def remove(self, plex_id):
|
||||||
"""
|
"""
|
||||||
Remove movieid, fileid, plex reference
|
Remove a movie with all references and all orphaned associated entries
|
||||||
|
from the Kodi DB
|
||||||
"""
|
"""
|
||||||
plex_db = self.plex_db
|
plex_dbitem = self.plex_db.getItem_byId(plex_id)
|
||||||
kodicursor = self.kodicursor
|
|
||||||
artwork = self.artwork
|
|
||||||
|
|
||||||
plex_dbitem = plex_db.getItem_byId(itemid)
|
|
||||||
try:
|
try:
|
||||||
kodi_id = plex_dbitem[0]
|
kodi_id = plex_dbitem[0]
|
||||||
file_id = plex_dbitem[1]
|
file_id = plex_dbitem[1]
|
||||||
|
@ -465,13 +462,14 @@ class Movies(Items):
|
||||||
LOG.debug('Removing %sid: %s file_id: %s',
|
LOG.debug('Removing %sid: %s file_id: %s',
|
||||||
kodi_type, kodi_id, file_id)
|
kodi_type, kodi_id, file_id)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
LOG.error('Movie with plex_id %s not found in DB - cannot delete',
|
||||||
|
plex_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Remove the plex reference
|
# Remove the plex reference
|
||||||
plex_db.removeItem(itemid)
|
self.plex_db.removeItem(plex_id)
|
||||||
# Remove artwork
|
# Remove artwork
|
||||||
artwork.delete_artwork(kodi_id, kodi_type, kodicursor)
|
self.artwork.delete_artwork(kodi_id, kodi_type, self.kodicursor)
|
||||||
|
|
||||||
if kodi_type == v.KODI_TYPE_MOVIE:
|
if kodi_type == v.KODI_TYPE_MOVIE:
|
||||||
set_id = self.kodi_db.get_set_id(kodi_id)
|
set_id = self.kodi_db.get_set_id(kodi_id)
|
||||||
self.kodi_db.modify_countries(kodi_id, kodi_type)
|
self.kodi_db.modify_countries(kodi_id, kodi_type)
|
||||||
|
@ -481,8 +479,8 @@ class Movies(Items):
|
||||||
self.kodi_db.modify_tags(kodi_id, kodi_type)
|
self.kodi_db.modify_tags(kodi_id, kodi_type)
|
||||||
# Delete kodi movie and file
|
# Delete kodi movie and file
|
||||||
self.kodi_db.remove_file(file_id)
|
self.kodi_db.remove_file(file_id)
|
||||||
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
|
self.kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
|
||||||
(kodi_id,))
|
(kodi_id,))
|
||||||
if set_id:
|
if set_id:
|
||||||
self.kodi_db.delete_possibly_empty_set(set_id)
|
self.kodi_db.delete_possibly_empty_set(set_id)
|
||||||
if v.KODIVERSION >= 17:
|
if v.KODIVERSION >= 17:
|
||||||
|
@ -490,16 +488,17 @@ class Movies(Items):
|
||||||
self.kodi_db.remove_ratings(kodi_id, kodi_type)
|
self.kodi_db.remove_ratings(kodi_id, kodi_type)
|
||||||
elif kodi_type == v.KODI_TYPE_SET:
|
elif kodi_type == v.KODI_TYPE_SET:
|
||||||
# Delete kodi boxset
|
# Delete kodi boxset
|
||||||
boxset_movies = plex_db.getItem_byParentId(kodi_id,
|
boxset_movies = self.plex_db.getItem_byParentId(kodi_id,
|
||||||
v.KODI_TYPE_MOVIE)
|
v.KODI_TYPE_MOVIE)
|
||||||
for movie in boxset_movies:
|
for movie in boxset_movies:
|
||||||
plexid = movie[0]
|
plexid = movie[0]
|
||||||
movieid = movie[1]
|
movieid = movie[1]
|
||||||
self.kodi_db.removefromBoxset(movieid)
|
self.kodi_db.removefromBoxset(movieid)
|
||||||
# Update plex reference
|
# Update plex reference
|
||||||
plex_db.updateParentId(plexid, None)
|
self.plex_db.updateParentId(plexid, None)
|
||||||
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodi_id,))
|
self.kodicursor.execute("DELETE FROM sets WHERE idSet = ?",
|
||||||
LOG.debug("Deleted %s %s from kodi database", kodi_type, itemid)
|
(kodi_id,))
|
||||||
|
LOG.debug("Deleted %s %s from kodi database", kodi_type, plex_id)
|
||||||
|
|
||||||
|
|
||||||
class TVShows(Items):
|
class TVShows(Items):
|
||||||
|
|
|
@ -769,15 +769,13 @@ class KodiDBMethods(object):
|
||||||
))
|
))
|
||||||
self.cursor.execute(query, (setid, movieid,))
|
self.cursor.execute(query, (setid, movieid,))
|
||||||
|
|
||||||
def removefromBoxset(self, movieid):
|
def remove_from_set(self, movieid):
|
||||||
|
"""
|
||||||
query = ' '.join((
|
Remove the movie with movieid [int] from an associated movie set, movie
|
||||||
|
collection
|
||||||
"UPDATE movie",
|
"""
|
||||||
"SET idSet = null",
|
self.cursor.execute('UPDATE movie SET idSet = null WHERE idMovie = ?',
|
||||||
"WHERE idMovie = ?"
|
(movieid,))
|
||||||
))
|
|
||||||
self.cursor.execute(query, (movieid,))
|
|
||||||
|
|
||||||
def get_set_id(self, kodi_id):
|
def get_set_id(self, kodi_id):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue