Consolidato clean DB (rimpiazza metodo clean di Kodi) + revisione move_to_library per download

This commit is contained in:
axlt2002
2020-04-14 02:21:30 +02:00
parent ef7198b9c8
commit a2aa100178
7 changed files with 196 additions and 125 deletions

View File

@@ -247,6 +247,12 @@ def open_settings():
elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None):
xbmc_videolibrary.clean(get_setting('videolibrarypath'))
if not settings_pre.get("library_move", None) and settings_post.get("library_move", None):
if settings_post.get("library_move", None) and not get_setting("videolibrary_kodi"):
from platformcode import platformtools
platformtools.dialog_ok(get_localized_string(20000), get_localized_string(80040))
set_setting("library_move", False)
def get_setting(name, channel="", server="", default=None):
"""

View File

@@ -515,27 +515,6 @@ def update(folder_content=config.get_setting("folder_tvshows"), folder=""):
xbmc.executebuiltin('XBMC.ReloadSkin()')
def clean(path=''):
"""
limpia la libreria de elementos que no existen
@param mostrar_dialogo: muestra el cuadro de progreso mientras se limpia la videoteca
@type mostrar_dialogo: bool
"""
logger.info()
if path:
clean_db(path)
return True
payload = {"jsonrpc": "2.0", "method": "VideoLibrary.Clean", "id": 1,
"params": {"showdialogs": False}}
data = get_data(payload)
if data.get('result', False) == 'OK':
return True
return False
def search_library_path():
sql = 'SELECT strPath FROM path WHERE strPath LIKE "special://%/plugin.video.kod/library/" AND idParentPath ISNULL'
nun_records, records = execute_sql_kodi(sql)
@@ -899,98 +878,143 @@ def update_db(old_path, new_path, old_movies_folder, new_movies_folder, old_tvsh
xbmc.executebuiltin('XBMC.ReloadSkin()')
def clean_db(path=''):
def clean(path=''):
def sql_format(path):
if path.startswith("special://"):
path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
elif '://' in path:
sep = '/'
else: sep = os.sep
if sep == '/': path = path.replace('\\','/')
else: path = path.replace('/','\\')
return path, sep
logger.info()
if path.startswith("special://"):
path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
elif '://' in path:
sep = '/'
else: sep = os.sep
if not path.endswith(sep):
path += sep
idParentPath = 0
sql_path = ''
sql_movies_path = ''
sql_tvshows_path = ''
sql_episodes_path = ''
path, sep = sql_format(path)
movies_folder = config.get_setting("folder_movies")
tvshows_folder = config.get_setting("folder_tvshows")
# delete episode/movie (downloads.py move_to_libray)
if path.endswith(".strm"):
if movies_folder in path:
sql_movies_path = path
else:
sql_episodes_path = path
# delete movie
elif movies_folder in path:
if not path.endswith(sep): path += sep
sql_movies_path = path + '%'
# delete tvshow
elif tvshows_folder in path:
if not path.endswith(sep): path += sep
sql_tvshows_path = path + '%'
sql_episodes_path = sql_tvshows_path
# delete video library
else:
if not path.endswith(sep): path += sep
sql_path = path
sql_movies_path = sql_path + movies_folder
if not sql_movies_path.endswith(sep): sql_movies_path += sep
sql_movies_path += '%'
sql_tvshows_path = sql_path + tvshows_folder
if not sql_tvshows_path.endswith(sep): sql_tvshows_path += sep
sql_tvshows_path += '%'
sql_episodes_path = sql_tvshows_path
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80025))
progress.update(0)
idParentPath = 0
# search video library path in the DB
sql = 'SELECT idPath FROM path where strPath LIKE "%s"' % path
nun_records, records = execute_sql_kodi(sql)
# delete video library path
if records:
idPath = records[0][0]
idParentPath = idPath
if not config.get_setting("videolibrary_kodi"):
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
if sql_path:
# search video library path in the DB
sql = 'SELECT idPath FROM path where strPath LIKE "%s"' % sql_path
nun_records, records = execute_sql_kodi(sql)
# delete video library path
if records:
idPath = records[0][0]
idParentPath = idPath
if not config.get_setting("videolibrary_kodi"):
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(10)
movies_path = path + config.get_setting("folder_movies")
if not movies_path.endswith(sep): movies_path += sep
movies_path += '%'
# search movies in the DB
sql = 'SELECT idMovie FROM movie where c22 LIKE "%s"' % movies_path
nun_records, records = execute_sql_kodi(sql)
# delete movies
if records:
for record in records:
idMovie = record[0]
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
nun_records, records = execute_sql_kodi(sql)
if sql_movies_path:
# search movies in the DB
sql = 'SELECT idMovie FROM movie where c22 LIKE "%s"' % sql_movies_path
nun_records, records = execute_sql_kodi(sql)
# delete movies
if records:
for record in records:
idMovie = record[0]
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
nun_records, records = execute_sql_kodi(sql)
progress.update(28)
# search movies path and folders in the DB
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % movies_path
nun_records, records = execute_sql_kodi(sql)
# delete movies path and folders
if records:
for record in records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
continue
idPath = record[0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
if sql_movies_path:
# search movies path and folders in the DB
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % sql_movies_path
nun_records, records = execute_sql_kodi(sql)
# delete movies path and folders
if records:
for record in records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
continue
idPath = record[0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(46)
tvshows_path = path + config.get_setting("folder_tvshows")
if not tvshows_path.endswith(sep): tvshows_path += sep
tvshows_path += '%'
# search TV shows in the DB
sql = 'SELECT idShow FROM tvshow_view where strPath LIKE "%s"' % tvshows_path
nun_records, records = execute_sql_kodi(sql)
# delete TV shows
if records:
for record in records:
idShow = record[0]
sql = 'DELETE from tvshow WHERE idShow=%s' % idShow
nun_records, records = execute_sql_kodi(sql)
if sql_tvshows_path:
# search TV shows in the DB
sql = 'SELECT idShow FROM tvshow_view where strPath LIKE "%s"' % sql_tvshows_path
nun_records, records = execute_sql_kodi(sql)
# delete TV shows
if records:
for record in records:
idShow = record[0]
sql = 'DELETE from tvshow WHERE idShow=%s' % idShow
nun_records, records = execute_sql_kodi(sql)
progress.update(64)
# search episodes in the DB
sql = 'SELECT idEpisode FROM episode where c18 LIKE "%s"' % tvshows_path
nun_records, records = execute_sql_kodi(sql)
# delete episodes
if records:
for record in records:
idEpisode = record[0]
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
nun_records, records = execute_sql_kodi(sql)
if sql_episodes_path:
# search episodes in the DB
sql = 'SELECT idEpisode FROM episode where c18 LIKE "%s"' % sql_episodes_path
nun_records, records = execute_sql_kodi(sql)
# delete episodes
if records:
for record in records:
idEpisode = record[0]
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
nun_records, records = execute_sql_kodi(sql)
progress.update(82)
# search TV shows path and folders in the DB
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % tvshows_path
nun_records, records = execute_sql_kodi(sql)
# delete tvshows path and folders
if records:
for record in records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
continue
idPath = record[0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
if sql_tvshows_path:
# search TV shows path and folders in the DB
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % sql_tvshows_path
nun_records, records = execute_sql_kodi(sql)
# delete tvshows path and folders
if records:
for record in records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
continue
idPath = record[0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(100)
xbmc.sleep(1000)