Spostamento videoteca (integrazione funzioni)

This commit is contained in:
axlt2002
2020-03-31 01:42:42 +02:00
parent 58ec5b2c01
commit e44578c4a3
4 changed files with 342 additions and 356 deletions

View File

@@ -219,25 +219,25 @@ def open_settings():
set_setting('adult_aux_new_password1', '')
set_setting('adult_aux_new_password2', '')
from specials import move_videolibrary
from specials import videolibrary
from platformcode import xbmc_videolibrary
if settings_pre.get('downloadpath', None) != settings_post.get('downloadpath', None):
move_videolibrary.update_sources(settings_pre.get('downloadpath', None), settings_post.get('downloadpath', None))
xbmc_videolibrary.update_sources(settings_pre.get('downloadpath', None), settings_post.get('downloadpath', None))
# si se ha cambiado la ruta de la videoteca llamamos a comprobar directorios para que lo cree y pregunte
# automaticamente si configurar la videoteca
if settings_pre.get("videolibrarypath", None) != settings_post.get("videolibrarypath", None) or \
settings_pre.get("folder_movies", None) != settings_post.get("folder_movies", None) or \
settings_pre.get("folder_tvshows", None) != settings_post.get("folder_tvshows", None):
move_videolibrary.move_videolibrary(settings_pre.get("videolibrarypath", None), settings_post.get("videolibrarypath", None),
settings_pre.get("folder_movies", None), settings_post.get("folder_movies", None),
settings_pre.get("folder_tvshows", None), settings_post.get("folder_tvshows", None))
videolibrary.move_videolibrary(settings_pre.get("videolibrarypath", None), settings_post.get("videolibrarypath", None),
settings_pre.get("folder_movies", None), settings_post.get("folder_movies", None),
settings_pre.get("folder_tvshows", None), settings_post.get("folder_tvshows", None))
# si se ha puesto que se quiere autoconfigurar y se había creado el directorio de la videoteca
if not settings_pre.get("videolibrary_kodi", None) and settings_post.get("videolibrary_kodi", None):
from platformcode import xbmc_videolibrary
xbmc_videolibrary.ask_set_content(silent=True)
elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None):
move_videolibrary.clear_db()
xbmc_videolibrary.clear_db()
def get_setting(name, channel="", server="", default=None):

View File

@@ -20,6 +20,7 @@ from core import jsontools
from platformcode import config, logger
from platformcode import platformtools
from core import scrapertools
from xml.dom import minidom
def mark_auto_as_watched(item):
@@ -794,6 +795,207 @@ def set_content(content_type, silent=False, custom=False):
return continuar
def update_db(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress):
logger.info()
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 = '/'
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
# search MAIN path in the DB
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % old
nun_records, records = execute_sql_kodi(sql)
# change main path
if records:
idPath = records[0][0]
strPath = records[0][1].replace(current_path, new_path)
sql = 'UPDATE path SET strPath="%s" WHERE idPath=%s' % (strPath, idPath)
nun_records, records = execute_sql_kodi(sql)
p = 80
progress.update(p, 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 = 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 = 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 = 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 = 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 = execute_sql_kodi(sql)
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 = execute_sql_kodi(sql)
# search and modify in "movie_view"
sql = 'SELECT idMovie, c22, strPath FROM movie_view where c22 LIKE "%s"' % old
nun_records, records = execute_sql_kodi(sql)
if records:
for record in records:
idMovie = record[0]
c22 = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
strPath = record[2].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE movie_view SET c22="%s", strPath="%s" WHERE idMovie=%s' % (c22, strPath, idMovie)
nun_records, records = 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 = execute_sql_kodi(sql)
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 = execute_sql_kodi(sql)
# search and modify in "episode_view"
sql = 'SELECT idEpisode, c18, strPath FROM episode_view where strPath LIKE "%s"' % old
nun_records, records = execute_sql_kodi(sql)
if records:
for record in records:
idEpisode = record[0]
c18 = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
strPath = record[2].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE episode_view SET c18="%s", strPath="%s" WHERE idEpisode=%s' % (c18, strPath, idEpisode)
nun_records, records = execute_sql_kodi(sql)
# search and modify in "season_view"
sql = 'SELECT idSeason, strPath FROM season_view where strPath LIKE "%s"' % old
nun_records, records = execute_sql_kodi(sql)
if records:
for record in records:
idSeason = record[0]
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE season_view SET strPath="%s" WHERE idSeason=%s' % (strPath, idSeason)
nun_records, records = execute_sql_kodi(sql)
# search and modify in "tvshow_view"
sql = 'SELECT idShow, strPath FROM tvshow_view where strPath LIKE "%s"' % old
nun_records, records = execute_sql_kodi(sql)
if records:
for record in records:
idShow = record[0]
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE tvshow_view SET strPath="%s" WHERE idShow=%s' % (strPath, idShow)
nun_records, records = execute_sql_kodi(sql)
p += 5
progress.update(p, config.get_localized_string(20000), config.get_localized_string(80013))
def clear_db():
logger.info()
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80025))
progress.update(0)
config.set_setting('videolibrary_kodi_flag', 1)
config.set_setting('videolibrary_kodi', False)
path = config.get_setting('videolibrarypath')
# rename main path for search in the DB
if path.startswith("special://") or scrapertools.find_single_match(path, r'(^\w+:\/\/)'):
path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
else:
sep = os.sep
if not path.endswith(sep):
path += sep
# search path in the db
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % path
nun_records, records = execute_sql_kodi(sql)
# change main path
if records:
idPath = records[0][0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(20)
path += '%'
# search path in the db
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % path
nun_records, records = execute_sql_kodi(sql)
# change main path
if records:
for record in records:
idPath = record[0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
# search path in the db
sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % path
nun_records, records = execute_sql_kodi(sql)
progress.update(40)
# change main path
if records:
for record in records:
idMovie = record[0]
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
nun_records, records = execute_sql_kodi(sql)
# search path in the db
sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % path
nun_records, records = execute_sql_kodi(sql)
progress.update(60)
# change main path
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(80)
update_sources(path)
clear_cache()
progress.update(100)
progress.close()
def execute_sql_kodi(sql):
"""
Ejecuta la consulta sql contra la base de datos de kodi
@@ -862,8 +1064,6 @@ def execute_sql_kodi(sql):
def add_sources(path):
logger.info()
try:
from xml.dom import minidom
SOURCES_PATH = xbmc.translatePath("special://userdata/sources.xml")
if os.path.exists(SOURCES_PATH):
@@ -935,6 +1135,93 @@ def add_sources(path):
logger.debug("An error occurred. The path %s has not been added to sources.xml" % path)
return False
def update_sources(old, new=''):
logger.info()
if new == old: return
SOURCES_PATH = xbmc.translatePath("special://userdata/sources.xml")
if filetools.isfile(SOURCES_PATH):
xmldoc = minidom.parse(SOURCES_PATH)
# collect nodes
# nodes = xmldoc.getElementsByTagName("video")
video_node = xmldoc.childNodes[0].getElementsByTagName("video")[0]
paths_node = video_node.getElementsByTagName("path")
# delete old path
for node in paths_node:
if node.firstChild.data == old:
parent = node.parentNode
remove = parent.parentNode
remove.removeChild(parent)
# write changes
if sys.version_info[0] >= 3: #PY3
filetools.write(SOURCES_PATH, '\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]))
else:
filetools.write(SOURCES_PATH, b'\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]), vfs=False)
if new:
# create new path
list_path = [p.firstChild.data for p in paths_node]
if new in list_path:
logger.info("path %s already exists in sources.xml" % new)
return
logger.info("path %s does not exist in sources.xml" % new)
# if the path does not exist we create one
source_node = xmldoc.createElement("source")
# <name> Node
name_node = xmldoc.createElement("name")
sep = os.sep
if new.startswith("special://") or scrapertools.find_single_match(new, r'(^\w+:\/\/)'):
sep = "/"
name = new
if new.endswith(sep):
name = new[:-1]
name_node.appendChild(xmldoc.createTextNode(name.rsplit(sep)[-1]))
source_node.appendChild(name_node)
# <path> Node
path_node = xmldoc.createElement("path")
path_node.setAttribute("pathversion", "1")
path_node.appendChild(xmldoc.createTextNode(new))
source_node.appendChild(path_node)
# <allowsharing> Node
allowsharing_node = xmldoc.createElement("allowsharing")
allowsharing_node.appendChild(xmldoc.createTextNode('true'))
source_node.appendChild(allowsharing_node)
# Añadimos <source> a <video>
video_node.appendChild(source_node)
# write changes
if sys.version_info[0] >= 3: #PY3
filetools.write(SOURCES_PATH, '\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]))
else:
filetools.write(SOURCES_PATH, b'\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]), vfs=False)
else:
xmldoc = minidom.Document()
source_nodes = xmldoc.createElement("sources")
for type in ['programs', 'video', 'music', 'picture', 'files']:
nodo_type = xmldoc.createElement(type)
element_default = xmldoc.createElement("default")
element_default.setAttribute("pathversion", "1")
nodo_type.appendChild(element_default)
source_nodes.appendChild(nodo_type)
xmldoc.appendChild(source_nodes)
def clear_cache():
path = xbmc.translatePath('special://home/cache/archive_cache/')
for file in filetools.listdir(path):
filetools.remove(filetools.join(path, file))
xbmc.executebuiltin('XBMC.ReloadSkin()')
def ask_set_content(silent=False):
logger.info()

View File

@@ -1,346 +0,0 @@
# -*- coding: utf-8 -*-
import xbmcgui, xbmc, os, sys
from platformcode import platformtools, xbmc_videolibrary, config
from core import filetools, scrapertools
from core.support import log, dbg
from distutils import dir_util, file_util
from xml.dom import minidom
def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder):
log()
log('current video library path:', current_path)
log('new video library path:', new_path)
log('current movies folder:', current_movies_folder)
log('new movies folder:', new_movies_folder)
log('current tvshows folder:', current_tvshows_folder)
log('new tvshows folder:', new_tvshows_folder)
backup_current_path = current_path
backup_new_path = new_path
notify = False
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80011))
current_path = xbmc.translatePath(current_path)
new_path = xbmc.translatePath(new_path)
current_movies_path = filetools.join(current_path, current_movies_folder)
new_movies_path = filetools.join(new_path, new_movies_folder)
current_tvshows_path = os.path.join(current_path, current_tvshows_folder)
new_tvshows_path = os.path.join(new_path, new_tvshows_folder)
config.verify_directories_created()
progress.update(10, config.get_localized_string(20000), config.get_localized_string(80012))
if current_movies_path != new_movies_path:
if filetools.listdir(current_movies_path):
dir_util.copy_tree(current_movies_path, new_movies_path)
notify = True
filetools.rmdirtree(current_movies_path)
progress.update(40)
if current_tvshows_path != new_tvshows_path:
if filetools.listdir(current_tvshows_path):
dir_util.copy_tree(current_tvshows_path, new_tvshows_path)
notify = True
filetools.rmdirtree(current_tvshows_path)
progress.update(70)
if current_path != new_path and not filetools.listdir(current_path) and not "plugin.video.kod\\videolibrary" in current_path:
filetools.rmdirtree(current_path)
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
update_sources(backup_current_path, backup_new_path)
update_db(backup_current_path, backup_new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress)
clear_cache()
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)
def update_db(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress):
log()
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 = '/'
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
# 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(current_path, new_path)
sql = 'UPDATE path SET strPath="%s" WHERE idPath=%s' % (strPath, idPath)
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
p = 80
progress.update(p, 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)
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)
# search and modify in "movie_view"
sql = 'SELECT idMovie, c22, strPath FROM movie_view where c22 LIKE "%s"' % old
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
if records:
for record in records:
idMovie = record[0]
c22 = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
strPath = record[2].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE movie_view SET c22="%s", strPath="%s" WHERE idMovie=%s' % (c22, 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)
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)
# search and modify in "episode_view"
sql = 'SELECT idEpisode, c18, strPath FROM episode_view where strPath LIKE "%s"' % old
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
if records:
for record in records:
idEpisode = record[0]
c18 = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
strPath = record[2].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE episode_view SET c18="%s", strPath="%s" WHERE idEpisode=%s' % (c18, strPath, idEpisode)
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
# search and modify in "season_view"
sql = 'SELECT idSeason, strPath FROM season_view where strPath LIKE "%s"' % old
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
if records:
for record in records:
idSeason = record[0]
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE season_view SET strPath="%s" WHERE idSeason=%s' % (strPath, idSeason)
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
# search and modify in "tvshow_view"
sql = 'SELECT idShow, strPath FROM tvshow_view where strPath LIKE "%s"' % old
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
if records:
for record in records:
idShow = record[0]
strPath = record[1].replace(filetools.join(current_path, OldPath), filetools.join(new_path, NewPath))
sql = 'UPDATE tvshow_view SET strPath="%s" WHERE idShow=%s' % (strPath, idShow)
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
p += 5
progress.update(p, config.get_localized_string(20000), config.get_localized_string(80013))
def clear_db():
log()
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80025))
progress.update(0)
config.set_setting('videolibrary_kodi_flag', 1)
config.set_setting('videolibrary_kodi', False)
path = config.get_setting('videolibrarypath')
# rename main path for search in the DB
if path.startswith("special://") or scrapertools.find_single_match(path, r'(^\w+:\/\/)'):
path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
else:
sep = os.sep
if not path.endswith(sep):
path += sep
# search path in the db
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % path
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
# change main path
if records:
idPath = records[0][0]
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
progress.update(20)
path += '%'
# search path in the db
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % path
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
# change main path
if records:
for record in records:
idPath = record[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"' % path
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
progress.update(40)
# change main path
if records:
for record in records:
idMovie = record[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"' % path
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
progress.update(60)
# change main path
if records:
for record in records:
idEpisode = record[0]
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
progress.update(80)
update_sources(path)
clear_cache()
progress.update(100)
progress.close()
def update_sources(old, new=''):
log()
if new == old: return
SOURCES_PATH = xbmc.translatePath("special://userdata/sources.xml")
if filetools.isfile(SOURCES_PATH):
xmldoc = minidom.parse(SOURCES_PATH)
# collect nodes
# nodes = xmldoc.getElementsByTagName("video")
video_node = xmldoc.childNodes[0].getElementsByTagName("video")[0]
paths_node = video_node.getElementsByTagName("path")
# delete old path
for node in paths_node:
if node.firstChild.data == old:
parent = node.parentNode
remove = parent.parentNode
remove.removeChild(parent)
# write changes
if sys.version_info[0] >= 3: #PY3
filetools.write(SOURCES_PATH, '\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]))
else:
filetools.write(SOURCES_PATH, b'\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]), vfs=False)
if new:
# create new path
list_path = [p.firstChild.data for p in paths_node]
if new in list_path:
log("path %s already exists in sources.xml" % new)
return
log("path %s does not exist in sources.xml" % new)
# if the path does not exist we create one
source_node = xmldoc.createElement("source")
# <name> Node
name_node = xmldoc.createElement("name")
sep = os.sep
if new.startswith("special://") or scrapertools.find_single_match(new, r'(^\w+:\/\/)'):
sep = "/"
name = new
if new.endswith(sep):
name = new[:-1]
name_node.appendChild(xmldoc.createTextNode(name.rsplit(sep)[-1]))
source_node.appendChild(name_node)
# <path> Node
path_node = xmldoc.createElement("path")
path_node.setAttribute("pathversion", "1")
path_node.appendChild(xmldoc.createTextNode(new))
source_node.appendChild(path_node)
# <allowsharing> Node
allowsharing_node = xmldoc.createElement("allowsharing")
allowsharing_node.appendChild(xmldoc.createTextNode('true'))
source_node.appendChild(allowsharing_node)
# Añadimos <source> a <video>
video_node.appendChild(source_node)
# write changes
if sys.version_info[0] >= 3: #PY3
filetools.write(SOURCES_PATH, '\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]))
else:
filetools.write(SOURCES_PATH, b'\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]), vfs=False)
else:
xmldoc = minidom.Document()
source_nodes = xmldoc.createElement("sources")
for type in ['programs', 'video', 'music', 'picture', 'files']:
nodo_type = xmldoc.createElement(type)
element_default = xmldoc.createElement("default")
element_default.setAttribute("pathversion", "1")
nodo_type.appendChild(element_default)
source_nodes.appendChild(nodo_type)
xmldoc.appendChild(source_nodes)
def clear_cache():
path = xbmc.translatePath('special://home/cache/archive_cache/')
for file in filetools.listdir(path):
filetools.remove(filetools.join(path, file))
xbmc.executebuiltin('XBMC.ReloadSkin()')

View File

@@ -8,7 +8,7 @@ from core.support import typo
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
import os, traceback
import xbmc, os, traceback
from channelselector import get_thumb
from core import filetools
@@ -18,6 +18,7 @@ from core.item import Item
from platformcode import config, logger
from platformcode import platformtools
from lib import generictools
from distutils import dir_util
def mainlist(item):
@@ -683,6 +684,50 @@ def update_videolibrary(item):
filetools.rmdirtree(raiz)
def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder):
logger.info()
backup_current_path = current_path
backup_new_path = new_path
notify = False
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80011))
current_path = xbmc.translatePath(current_path)
new_path = xbmc.translatePath(new_path)
current_movies_path = filetools.join(current_path, current_movies_folder)
new_movies_path = filetools.join(new_path, new_movies_folder)
current_tvshows_path = os.path.join(current_path, current_tvshows_folder)
new_tvshows_path = os.path.join(new_path, new_tvshows_folder)
config.verify_directories_created()
progress.update(10, config.get_localized_string(20000), config.get_localized_string(80012))
if current_movies_path != new_movies_path:
if filetools.listdir(current_movies_path):
dir_util.copy_tree(current_movies_path, new_movies_path)
notify = True
filetools.rmdirtree(current_movies_path)
progress.update(40)
if current_tvshows_path != new_tvshows_path:
if filetools.listdir(current_tvshows_path):
dir_util.copy_tree(current_tvshows_path, new_tvshows_path)
notify = True
filetools.rmdirtree(current_tvshows_path)
progress.update(70)
if current_path != new_path and not filetools.listdir(current_path) and not "plugin.video.kod\\videolibrary" in current_path:
filetools.rmdirtree(current_path)
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
from platformcode import xbmc_videolibrary
xbmc_videolibrary.update_sources(backup_current_path, backup_new_path)
xbmc_videolibrary.update_db(backup_current_path, backup_new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress)
xbmc_videolibrary.clear_cache()
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)
# metodos de menu contextual
def update_tvshow(item):
logger.info()