Spostamento Videoteca reintegrata Modifica DB
This commit is contained in:
@@ -56,6 +56,9 @@ def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_
|
||||
log('current tvshows folder:', current_tvshows_folder)
|
||||
log('new tvshows folder:', new_tvshows_folder)
|
||||
|
||||
backup_current_path = current_path
|
||||
backup_new_path = new_path
|
||||
|
||||
if current_path != new_path or current_movies_folder != new_movies_folder or current_tvshows_folder != new_tvshows_folder:
|
||||
notify = False
|
||||
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80011))
|
||||
@@ -83,22 +86,24 @@ def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_
|
||||
if current_path != new_path and not filetools.listdir(current_path) and not "plugin.video.kod\\videolibrary" in current_path:
|
||||
filetools.rmdirtree(current_path)
|
||||
|
||||
progress.update(90, config.get_localized_string(20000), config.get_localized_string(80013))
|
||||
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
|
||||
set_new_path(new_path, current_path)
|
||||
update_db(new_path, current_path)
|
||||
update_db(backup_current_path, backup_new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress)
|
||||
clear_cache()
|
||||
else:
|
||||
progress.update(90, config.get_localized_string(20000), config.get_localized_string(80013))
|
||||
|
||||
progress.update(100)
|
||||
progress.close()
|
||||
if notify:
|
||||
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80014), icon=0,
|
||||
time=5000, sound=False)
|
||||
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80014), icon=0, time=5000, sound=False)
|
||||
|
||||
def update_db(new, old):
|
||||
NEW = new
|
||||
OLD = old
|
||||
def update_db(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress):
|
||||
|
||||
new = new_path
|
||||
old = current_path
|
||||
|
||||
# rename main path for search in the DB
|
||||
if new.startswith("special://") or scrapertools.find_single_match(new, r'(^\w+:\/\/)'):
|
||||
new = new.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
|
||||
sep = '/'
|
||||
@@ -115,44 +120,170 @@ def update_db(new, old):
|
||||
if not old.endswith(sep):
|
||||
old += sep
|
||||
|
||||
|
||||
# search MAIN path in the DB
|
||||
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# change main path
|
||||
if records:
|
||||
idPath = records[0][0]
|
||||
strPath = records[0][1].replace(OLD, NEW)
|
||||
strPath = records[0][1].replace(current_path, new_path)
|
||||
sql = 'UPDATE path SET strPath="%s" WHERE idPath=%s' % (strPath, idPath)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
old += '%'
|
||||
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
if records:
|
||||
for record in records:
|
||||
idPath = record[0]
|
||||
strPath = record[1].replace(OLD, NEW)
|
||||
sql = 'UPDATE path SET strPath="%s"WHERE idPath=%s' % (strPath, idPath)
|
||||
p = 80
|
||||
progress.update(90, config.get_localized_string(20000), config.get_localized_string(80013))
|
||||
|
||||
OLD = old
|
||||
for OldPath, NewPath in [[current_movies_folder, new_movies_folder], [current_tvshows_folder, new_tvshows_folder]]:
|
||||
old = OLD + OldPath
|
||||
if not old.endswith(sep): old += sep
|
||||
|
||||
# Search Main Sub Folder
|
||||
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# Change Main Sub Folder
|
||||
if records:
|
||||
for record in records:
|
||||
idPath = record[0]
|
||||
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
|
||||
sql = 'UPDATE path SET strPath="%s"WHERE idPath=%s' % (strPath, idPath)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# Search if Sub Folder exixt in all paths
|
||||
old += '%'
|
||||
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
#Change Sub Folder in all paths
|
||||
if records:
|
||||
for record in records:
|
||||
idPath = record[0]
|
||||
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
|
||||
sql = 'UPDATE path SET strPath="%s"WHERE idPath=%s' % (strPath, idPath)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
|
||||
if OldPath == current_movies_folder:
|
||||
# if is Movie Folder
|
||||
# search and modify in "movie"
|
||||
sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# dbg()
|
||||
sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
if records:
|
||||
for record in records:
|
||||
idMovie = record[0]
|
||||
strPath = record[1].replace(OLD, NEW)
|
||||
sql = 'UPDATE movie SET c22="%s" WHERE idMovie=%s' % (strPath, idMovie)
|
||||
if records:
|
||||
for record in records:
|
||||
idMovie = record[0]
|
||||
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
|
||||
sql = 'UPDATE movie SET c22="%s" WHERE idMovie=%s' % (strPath, idMovie)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
else:
|
||||
# if is Tv Show Folder
|
||||
# search and modify in "episode"
|
||||
sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % old
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % old
|
||||
if records:
|
||||
for record in records:
|
||||
idEpisode = record[0]
|
||||
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
|
||||
sql = 'UPDATE episode SET c18="%s" WHERE idEpisode=%s' % (strPath, idEpisode)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
p += 5
|
||||
progress.update(90, config.get_localized_string(20000), config.get_localized_string(80013))
|
||||
|
||||
def clear_videolibrary_db(item):
|
||||
# search path in the db
|
||||
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % '%/plugin.video.kod/%'
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# change main path
|
||||
if records:
|
||||
for record in records:
|
||||
idEpisode = record[0]
|
||||
strPath = record[1].replace(OLD, NEW)
|
||||
sql = 'UPDATE episode SET c18="%s" WHERE idEpisode=%s' % (strPath, idEpisode)
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
"""global p
|
||||
p += 30
|
||||
progress.update(p)"""
|
||||
idPath = records[0][0]
|
||||
sql = 'DELETE from path WHERE idPath=%s' % idPath
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# search path in the db
|
||||
sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % '%/plugin.video.kod/%'
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# change main path
|
||||
if records:
|
||||
idMovie = records[0][0]
|
||||
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# search path in the db
|
||||
sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % '%/plugin.video.kod/%'
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# change main path
|
||||
if records:
|
||||
idEpisode = records[0][0]
|
||||
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
|
||||
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
|
||||
# for new, old in [[current_path, new_path], [current_movies_folder, new_movies_folder], [current_tvshows_folder, new_tvshows_folder]]:
|
||||
# log('Paths:',new, old)
|
||||
# NEW = new
|
||||
# OLD = old
|
||||
# if new.startswith("special://") or scrapertools.find_single_match(new, r'(^\w+:\/\/)'):
|
||||
# new = new.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
|
||||
# sep = '/'
|
||||
# else:
|
||||
# sep = os.sep
|
||||
# if not new.endswith(sep):
|
||||
# new += sep
|
||||
|
||||
# if old.startswith("special://") or scrapertools.find_single_match(old, r'(^\w+:\/\/)'):
|
||||
# old = old.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
|
||||
# sep = '/'
|
||||
# else:
|
||||
# sep = os.sep
|
||||
# if not old.endswith(sep):
|
||||
# old += sep
|
||||
|
||||
|
||||
# sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# if records:
|
||||
# idPath = records[0][0]
|
||||
# strPath = records[0][1].replace(OLD, NEW)
|
||||
# sql = 'UPDATE path SET strPath="%s" WHERE idPath=%s' % (strPath, idPath)
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# old += '%'
|
||||
# sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# if not records:
|
||||
# old = '%' + old + '%'
|
||||
# sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# if records:
|
||||
# for record in records:
|
||||
# idPath = record[0]
|
||||
# strPath = record[1].replace(OLD, NEW)
|
||||
# sql = 'UPDATE path SET strPath="%s"WHERE idPath=%s' % (strPath, idPath)
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
|
||||
# sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % old
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# if records:
|
||||
# for record in records:
|
||||
# idMovie = record[0]
|
||||
# strPath = record[1].replace(OLD, NEW)
|
||||
# sql = 'UPDATE movie SET c22="%s" WHERE idMovie=%s' % (strPath, idMovie)
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % old
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# if records:
|
||||
# for record in records:
|
||||
# idEpisode = record[0]
|
||||
# strPath = record[1].replace(OLD, NEW)
|
||||
# sql = 'UPDATE episode SET c18="%s" WHERE idEpisode=%s' % (strPath, idEpisode)
|
||||
# nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
|
||||
# """global p
|
||||
# p += 30
|
||||
# progress.update(p)"""
|
||||
|
||||
def set_new_path(new, old):
|
||||
write = False
|
||||
|
||||
Reference in New Issue
Block a user