Fix Episodi esistenti in libreria

This commit is contained in:
Alhaziel01
2021-06-09 19:03:14 +02:00
parent a00641ab7a
commit db2a4cea91
2 changed files with 15 additions and 53 deletions

View File

@@ -590,6 +590,11 @@ def save_episodes(path, episodelist, serie, silent=False, overwrite=True):
nfo_path = filetools.join(path, "tvshow.nfo")
head_nfo, item_nfo = read_nfo(nfo_path)
if config.get_setting('videolibrary_kodi'):
from platformcode.xbmc_videolibrary import check_db
for p in check_db(item_nfo.infoLabels['code']):
local_episodelist += get_local_content(p)
if item_nfo.update_last:
local_episodes_path = item_nfo.local_episodes_path
elif config.get_setting("local_episodes", "videolibrary"):
@@ -601,47 +606,7 @@ def save_episodes(path, episodelist, serie, silent=False, overwrite=True):
filetools.write(nfo_path, head_nfo + item_nfo.tojson())
if local_episodes_path:
from platformcode.xbmc_videolibrary import check_db, clean
# check if the local episodes are in the Kodi video library
if check_db(local_episodes_path):
local_episodelist += get_local_content(local_episodes_path)
clean_list = []
for f in filetools.listdir(path):
match = scrapertools.find_single_match(f, r'[Ss]?(\d+)(?:x|_|\s+)?[Ee]?[Pp]?(\d+)')
if match:
ep = '%dx%02d' % (int(match[0]), int(match[1]))
if ep in local_episodelist:
del_file = filetools.join(path, f)
filetools.remove(del_file)
if f.endswith('strm'):
sep = '\\' if '\\' in path else '/'
clean_path = path[:-len(sep)] if path.endswith(sep) else path
clean_path = '%/' + clean_path.split(sep)[-1] + '/' + f
clean_list.append(clean_path)
clean_list.append(clean_path.replace('/','\\'))
if clean_list:
clean(clean_list)
update = True
if item_nfo.local_episodes_list:
difference = [x for x in item_nfo.local_episodes_list if (x not in local_episodelist)]
if len(difference) > 0:
clean_list = []
for f in difference:
sep = '\\' if '\\' in local_episodes_path else '/'
clean_path = local_episodes_path[:-len(sep)] if local_episodes_path.endswith(sep) else local_episodes_path
clean_path = '%/' + clean_path.split(sep)[-1] + '/%' + f.replace('x','%') + '%'
clean_list.append(clean_path)
clean_list.append(clean_path.replace('/','\\'))
clean(clean_list)
update = True
item_nfo.local_episodes_list = sorted(local_episodelist)
filetools.write(nfo_path, head_nfo + item_nfo.tojson())
# the local episodes are not in the Kodi video library
else:
process_local_episodes(local_episodes_path, path)
process_local_episodes(local_episodes_path, path)
insertados = 0
sobreescritos = 0

View File

@@ -1072,18 +1072,15 @@ def clean(path_list=[]):
progress.close()
def check_db(path):
if '\\' in path: sep = '\\'
else: sep = '/'
if path.endswith(sep): path = path[:-len(sep)]
ret = False
sql_path = '%' + sep + path.split(sep)[-1] + sep + '%'
sql = 'SELECT idShow FROM tvshow_view where strPath LIKE "%s"' % sql_path
logger.debug('sql: ' + sql)
nun_records, records = execute_sql_kodi(sql)
if records:
ret = True
return ret
def check_db(code):
path_list = []
for _id in code:
sql = 'SELECT strPath FROM tvshow_view where uniqueid_value = "%s"' % _id.replace('tmdb_','').replace('tvdb_','')
logger.debug('sql: ' + sql)
nun_records, records = execute_sql_kodi(sql)
if records:
path_list += [xbmc.translatePath(r[0]) for r in records]
return path_list
def execute_sql_kodi(sql):