Ensure file id references get deleted
This commit is contained in:
parent
5882a6ef3b
commit
97dc1c1856
2 changed files with 41 additions and 77 deletions
|
@ -203,7 +203,7 @@ class Movies(Items):
|
||||||
plex_dbitem = plex_db.getItem_byId(itemid)
|
plex_dbitem = plex_db.getItem_byId(itemid)
|
||||||
try:
|
try:
|
||||||
movieid = plex_dbitem[0]
|
movieid = plex_dbitem[0]
|
||||||
fileid = plex_dbitem[1]
|
old_fileid = plex_dbitem[1]
|
||||||
pathid = plex_dbitem[2]
|
pathid = plex_dbitem[2]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -283,12 +283,16 @@ class Movies(Items):
|
||||||
# Network share
|
# Network share
|
||||||
filename = playurl.rsplit("/", 1)[1]
|
filename = playurl.rsplit("/", 1)[1]
|
||||||
path = playurl.replace(filename, "")
|
path = playurl.replace(filename, "")
|
||||||
|
pathid = self.kodi_db.add_video_path(path,
|
||||||
|
content='movies',
|
||||||
|
scraper='metadata.local')
|
||||||
if do_indirect:
|
if do_indirect:
|
||||||
# Set plugin path and media flags using real filename
|
# Set plugin path and media flags using real filename
|
||||||
path = 'plugin://%s.movies/' % v.ADDON_ID
|
path = 'plugin://%s.movies/' % v.ADDON_ID
|
||||||
filename = ('%s?plex_id=%s&plex_type=%s&mode=play'
|
filename = ('%s?plex_id=%s&plex_type=%s&mode=play'
|
||||||
% (path, itemid, v.PLEX_TYPE_MOVIE))
|
% (path, itemid, v.PLEX_TYPE_MOVIE))
|
||||||
playurl = filename
|
playurl = filename
|
||||||
|
pathid = self.kodi_db.get_path(path)
|
||||||
|
|
||||||
# movie table:
|
# movie table:
|
||||||
# c22 - playurl
|
# c22 - playurl
|
||||||
|
@ -297,12 +301,13 @@ class Movies(Items):
|
||||||
|
|
||||||
# add/retrieve pathid and fileid
|
# add/retrieve pathid and fileid
|
||||||
# if the path or file already exists, the calls return current value
|
# if the path or file already exists, the calls return current value
|
||||||
pathid = self.kodi_db.add_video_path(path)
|
fileid = self.kodi_db.add_file(filename, pathid, dateadded)
|
||||||
fileid = self.kodi_db.add_file(filename, pathid)
|
|
||||||
|
|
||||||
# UPDATE THE MOVIE #####
|
# UPDATE THE MOVIE #####
|
||||||
if update_item:
|
if update_item:
|
||||||
LOG.info("UPDATE movie itemid: %s - Title: %s", itemid, title)
|
LOG.info("UPDATE movie itemid: %s - Title: %s", itemid, title)
|
||||||
|
if fileid != old_fileid:
|
||||||
|
self.kodi_db.remove_file(old_fileid)
|
||||||
# Update the movie entry
|
# Update the movie entry
|
||||||
if v.KODIVERSION >= 17:
|
if v.KODIVERSION >= 17:
|
||||||
# update new ratings Kodi 17
|
# update new ratings Kodi 17
|
||||||
|
@ -415,25 +420,6 @@ class Movies(Items):
|
||||||
parent_id=None,
|
parent_id=None,
|
||||||
checksum=checksum,
|
checksum=checksum,
|
||||||
view_id=viewid)
|
view_id=viewid)
|
||||||
|
|
||||||
# Update the path
|
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"UPDATE path",
|
|
||||||
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?",
|
|
||||||
"WHERE idPath = ?"
|
|
||||||
))
|
|
||||||
kodicursor.execute(query, (path, "movies", "metadata.local", 1, pathid))
|
|
||||||
|
|
||||||
# Update the file
|
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"UPDATE files",
|
|
||||||
"SET idPath = ?, strFilename = ?, dateAdded = ?",
|
|
||||||
"WHERE idFile = ?"
|
|
||||||
))
|
|
||||||
kodicursor.execute(query, (pathid, filename, dateadded, fileid))
|
|
||||||
|
|
||||||
# Process countries
|
# Process countries
|
||||||
self.kodi_db.modify_countries(movieid, v.KODI_TYPE_MOVIE, countries)
|
self.kodi_db.modify_countries(movieid, v.KODI_TYPE_MOVIE, countries)
|
||||||
# Process cast
|
# Process cast
|
||||||
|
@ -793,7 +779,7 @@ class TVShows(Items):
|
||||||
plex_dbitem = plex_db.getItem_byId(itemid)
|
plex_dbitem = plex_db.getItem_byId(itemid)
|
||||||
try:
|
try:
|
||||||
episodeid = plex_dbitem[0]
|
episodeid = plex_dbitem[0]
|
||||||
fileid = plex_dbitem[1]
|
old_fileid = plex_dbitem[1]
|
||||||
pathid = plex_dbitem[2]
|
pathid = plex_dbitem[2]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update_item = False
|
update_item = False
|
||||||
|
@ -877,11 +863,13 @@ class TVShows(Items):
|
||||||
# if the path or file already exists, the calls return current value
|
# if the path or file already exists, the calls return current value
|
||||||
pathid = self.kodi_db.add_video_path(path,
|
pathid = self.kodi_db.add_video_path(path,
|
||||||
id_parent_path=parent_path_id)
|
id_parent_path=parent_path_id)
|
||||||
fileid = self.kodi_db.add_file(filename, pathid)
|
fileid = self.kodi_db.add_file(filename, pathid, dateadded)
|
||||||
|
|
||||||
# UPDATE THE EPISODE #####
|
# UPDATE THE EPISODE #####
|
||||||
if update_item:
|
if update_item:
|
||||||
LOG.info("UPDATE episode itemid: %s", itemid)
|
LOG.info("UPDATE episode itemid: %s", itemid)
|
||||||
|
if fileid != old_fileid:
|
||||||
|
self.kodi_db.remove_file(old_fileid)
|
||||||
# Update the movie entry
|
# Update the movie entry
|
||||||
if v.KODIVERSION >= 17:
|
if v.KODIVERSION >= 17:
|
||||||
# update new ratings Kodi 17
|
# update new ratings Kodi 17
|
||||||
|
@ -913,7 +901,7 @@ class TVShows(Items):
|
||||||
premieredate, runtime, director, season, episode, title,
|
premieredate, runtime, director, season, episode, title,
|
||||||
airs_before_season, airs_before_episode, playurl, pathid,
|
airs_before_season, airs_before_episode, playurl, pathid,
|
||||||
fileid, seasonid, userdata['UserRating'], episodeid))
|
fileid, seasonid, userdata['UserRating'], episodeid))
|
||||||
elif v.KODIVERSION == 16:
|
else:
|
||||||
# Kodi Jarvis
|
# Kodi Jarvis
|
||||||
query = '''
|
query = '''
|
||||||
UPDATE episode
|
UPDATE episode
|
||||||
|
@ -926,18 +914,6 @@ class TVShows(Items):
|
||||||
premieredate, runtime, director, season, episode, title,
|
premieredate, runtime, director, season, episode, title,
|
||||||
airs_before_season, airs_before_episode, playurl, pathid,
|
airs_before_season, airs_before_episode, playurl, pathid,
|
||||||
fileid, seasonid, episodeid))
|
fileid, seasonid, episodeid))
|
||||||
else:
|
|
||||||
query = '''
|
|
||||||
UPDATE episode
|
|
||||||
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
|
|
||||||
c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
|
|
||||||
c18 = ?, c19 = ?, idFile = ?
|
|
||||||
WHERE idEpisode = ?
|
|
||||||
'''
|
|
||||||
kodicursor.execute(query, (title, plot, rating, writer,
|
|
||||||
premieredate, runtime, director, season, episode, title,
|
|
||||||
airs_before_season, airs_before_episode, playurl, pathid,
|
|
||||||
fileid, episodeid))
|
|
||||||
# Update parentid reference
|
# Update parentid reference
|
||||||
plex_db.updateParentId(itemid, seasonid)
|
plex_db.updateParentId(itemid, seasonid)
|
||||||
|
|
||||||
|
@ -1015,18 +991,9 @@ class TVShows(Items):
|
||||||
parent_id=seasonid,
|
parent_id=seasonid,
|
||||||
checksum=checksum,
|
checksum=checksum,
|
||||||
view_id=viewid)
|
view_id=viewid)
|
||||||
# Update the file
|
|
||||||
query = '''
|
|
||||||
UPDATE files
|
|
||||||
SET idPath = ?, strFilename = ?, dateAdded = ?
|
|
||||||
WHERE idFile = ?
|
|
||||||
'''
|
|
||||||
kodicursor.execute(query, (pathid, filename, dateadded, fileid))
|
|
||||||
# Process cast
|
|
||||||
self.kodi_db.modify_people(episodeid,
|
self.kodi_db.modify_people(episodeid,
|
||||||
v.KODI_TYPE_EPISODE,
|
v.KODI_TYPE_EPISODE,
|
||||||
api.people_list())
|
api.people_list())
|
||||||
# Process artwork
|
|
||||||
# Wide "screenshot" of particular episode
|
# Wide "screenshot" of particular episode
|
||||||
poster = item.attrib.get('thumb')
|
poster = item.attrib.get('thumb')
|
||||||
if poster:
|
if poster:
|
||||||
|
@ -1034,11 +1001,8 @@ class TVShows(Items):
|
||||||
"%s%s" % (self.server, poster))
|
"%s%s" % (self.server, poster))
|
||||||
artwork.modify_art(
|
artwork.modify_art(
|
||||||
poster, episodeid, v.KODI_TYPE_EPISODE, "thumb", kodicursor)
|
poster, episodeid, v.KODI_TYPE_EPISODE, "thumb", kodicursor)
|
||||||
|
|
||||||
# Process stream details
|
|
||||||
streams = api.mediastreams()
|
streams = api.mediastreams()
|
||||||
self.kodi_db.modify_streams(fileid, streams, runtime)
|
self.kodi_db.modify_streams(fileid, streams, runtime)
|
||||||
# Process playstates
|
|
||||||
self.kodi_db.addPlaystate(fileid,
|
self.kodi_db.addPlaystate(fileid,
|
||||||
resume,
|
resume,
|
||||||
runtime,
|
runtime,
|
||||||
|
|
|
@ -185,7 +185,7 @@ class KodiDBMethods(object):
|
||||||
pathid = None
|
pathid = None
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def add_file(self, filename, path_id):
|
def add_file(self, filename, path_id, date_added):
|
||||||
"""
|
"""
|
||||||
Adds the filename [unicode] to the table files if not already added
|
Adds the filename [unicode] to the table files if not already added
|
||||||
and returns the idFile.
|
and returns the idFile.
|
||||||
|
@ -193,13 +193,30 @@ class KodiDBMethods(object):
|
||||||
query = 'SELECT idFile FROM files WHERE strFilename = ? AND idPath = ?'
|
query = 'SELECT idFile FROM files WHERE strFilename = ? AND idPath = ?'
|
||||||
self.cursor.execute(query, (filename, path_id))
|
self.cursor.execute(query, (filename, path_id))
|
||||||
try:
|
try:
|
||||||
fileid = self.cursor.fetchone()[0]
|
file_id = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.cursor.execute('SELECT COALESCE(MAX(idFile), 0) FROM files')
|
self.cursor.execute('SELECT COALESCE(MAX(idFile), 0) FROM files')
|
||||||
fileid = self.cursor.fetchone()[0] + 1
|
file_id = self.cursor.fetchone()[0] + 1
|
||||||
query = 'INSERT INTO files(idFile, strFilename) VALUES (?, ?)'
|
query = '''
|
||||||
self.cursor.execute(query, (fileid, filename))
|
INSERT INTO files(idFile, idPath, strFilename, dateAdded)
|
||||||
return fileid
|
VALUES (?, ?, ?, ?)
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (file_id, path_id, filename, date_added))
|
||||||
|
return file_id
|
||||||
|
|
||||||
|
def remove_file(self, file_id):
|
||||||
|
"""
|
||||||
|
Removes the entry for file_id from the files table. Will also delete
|
||||||
|
entries from the associated tables: bookmark, settings, streamdetails
|
||||||
|
"""
|
||||||
|
self.cursor.execute('DELETE FROM files WHERE idFile = ?',
|
||||||
|
(file_id,))
|
||||||
|
self.cursor.execute('DELETE FROM bookmark WHERE idFile = ?',
|
||||||
|
(file_id,))
|
||||||
|
self.cursor.execute('DELETE FROM settings WHERE idFile = ?',
|
||||||
|
(file_id,))
|
||||||
|
self.cursor.execute('DELETE FROM streamdetails WHERE idFile = ?',
|
||||||
|
(file_id,))
|
||||||
|
|
||||||
def getFile(self, fileid):
|
def getFile(self, fileid):
|
||||||
|
|
||||||
|
@ -217,19 +234,6 @@ class KodiDBMethods(object):
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def removeFile(self, path, filename):
|
|
||||||
|
|
||||||
pathid = self.get_path(path)
|
|
||||||
|
|
||||||
if pathid is not None:
|
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"DELETE FROM files",
|
|
||||||
"WHERE idPath = ?",
|
|
||||||
"AND strFilename = ?"
|
|
||||||
))
|
|
||||||
self.cursor.execute(query, (pathid, filename,))
|
|
||||||
|
|
||||||
def _modify_link_and_table(self, kodi_id, kodi_type, entries, link_table,
|
def _modify_link_and_table(self, kodi_id, kodi_type, entries, link_table,
|
||||||
table, key):
|
table, key):
|
||||||
query = '''
|
query = '''
|
||||||
|
@ -656,21 +660,17 @@ class KodiDBMethods(object):
|
||||||
"""
|
"""
|
||||||
self.cursor.execute("DELETE FROM bookmark")
|
self.cursor.execute("DELETE FROM bookmark")
|
||||||
|
|
||||||
def addPlaystate(self, fileid, resume_seconds, total_seconds, playcount,
|
def addPlaystate(self, file_id, resume_seconds, total_seconds, playcount,
|
||||||
dateplayed):
|
dateplayed):
|
||||||
# Delete existing resume point
|
# Delete existing resume point
|
||||||
query = '''
|
self.cursor.execute('DELETE FROM bookmark WHERE idFile = ?', (file_id,))
|
||||||
DELETE FROM bookmark
|
|
||||||
WHERE idFile = ?
|
|
||||||
'''
|
|
||||||
self.cursor.execute(query, (fileid,))
|
|
||||||
# Set watched count
|
# Set watched count
|
||||||
query = '''
|
query = '''
|
||||||
UPDATE files
|
UPDATE files
|
||||||
SET playCount = ?, lastPlayed = ?
|
SET playCount = ?, lastPlayed = ?
|
||||||
WHERE idFile = ?
|
WHERE idFile = ?
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query, (playcount, dateplayed, fileid))
|
self.cursor.execute(query, (playcount, dateplayed, file_id))
|
||||||
# Set the resume bookmark
|
# Set the resume bookmark
|
||||||
if resume_seconds:
|
if resume_seconds:
|
||||||
self.cursor.execute(
|
self.cursor.execute(
|
||||||
|
@ -683,11 +683,11 @@ class KodiDBMethods(object):
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query, (bookmark_id,
|
self.cursor.execute(query, (bookmark_id,
|
||||||
fileid,
|
file_id,
|
||||||
resume_seconds,
|
resume_seconds,
|
||||||
total_seconds,
|
total_seconds,
|
||||||
'',
|
'',
|
||||||
"VideoPlayer",
|
'VideoPlayer',
|
||||||
'',
|
'',
|
||||||
1))
|
1))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue