Merge remote-tracking branch 'origin/master'

This commit is contained in:
marco
2020-03-25 18:52:19 +01:00
4 changed files with 189 additions and 110 deletions

View File

@@ -219,22 +219,30 @@ def open_settings():
set_setting('adult_aux_new_password1', '')
set_setting('adult_aux_new_password2', '')
# 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):
verify_directories_created()"""
from specials import move_videolibrary
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))
# 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) \
and settings_post.get("videolibrary_kodi_flag", None) == 1:
from platformcode import xbmc_videolibrary
xbmc_videolibrary.ask_set_content(2, silent=True)
xbmc.sleep(2000)
xbmc_videolibrary.update(settings_post.get("folder_movies", None))
xbmc_videolibrary.update(settings_post.get("folder_tvshows", None))
elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None) \
and settings_post.get("videolibrary_kodi_flag", None) == 2:
move_videolibrary.clear_videolibrary_db()
# 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):
verify_directories_created()"""
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))
def get_setting(name, channel="", server="", default=None):

View File

@@ -35,7 +35,8 @@
<setting label="59997" type="lsep"/>
<setting id="videolibrary_kodi_flag" type="number" label="" default="0" visible="false"/>
<setting id="videolibrary_kodi_force" type="bool" label="" default="false" visible="false"/>
<setting id="videolibrary_kodi" type="bool" label="70120" enable="lt(-1,2)+eq(0,false)" default="false"/>
<setting id="videolibrary_kodi" type="bool" label="70120" default="false"/>
<!-- <setting id="videolibrary_kodi" type="bool" label="70120" enable="lt(-1,2)+eq(0,false)" default="false"/> -->
<setting id="videolibrary_max_quality" type="bool" label="70729" default="false" visible="true"/>
<setting id="next_ep" type="select" label="70746" lvalues="70752|70747|70748" default="0"/>
<setting id="next_ep_type" type="select" label="70754" lvalues="70755|70756|70757" default="0" visible="eq(-1,2)" subsetting="true"/>

View File

@@ -559,7 +559,8 @@ def filter_thread(filter, key, item, description):
id = results['id']
if id:
thumbnail = 'http://image.tmdb.org/t/p/original' + results['profile_path'] if results['profile_path'] else item.thumbnail
json_file = httptools.downloadpage('http://api.themoviedb.org/3/person/'+ str(id) + '?api_key=' + tmdb_api + '&language=%s', lang, use_requests=True).data
json_file = httptools.downloadpage('http://api.themoviedb.org/3/person/'+ str(id) + '?api_key=' + tmdb_api + '&language=en', use_requests=True).data
support.log(json_file)
plot += jsontools.load(json_file)['biography']
if description:

View File

@@ -7,45 +7,6 @@ from core.support import log, dbg
from distutils import dir_util, file_util
from xml.dom import minidom
"""global p
p = 0
progress = platformtools.dialog_progress('Spostamento Videoteca','Spostamento File')"""
"""def set_videolibrary_path(item):
log()
global p
previous_path = config.get_setting('videolibrarypath')
path = xbmcgui.Dialog().browse(3, 'Seleziona la cartella', 'files', '', False, False, config.get_setting('videolibrarypath'))
log('New Videolibrary path:', path)
log('Previous Videolibrary path:', previous_path)
if path != previous_path:
config.set_setting('videolibrarypath', path)
progress.update(p, '')
set_new_path(path, previous_path)
if platformtools.dialog_yesno('Spostare la Videoteca?', 'vuoi spostare la videoteca e il relativo contenuto nella nuova posizione?'):
move_videolibrary(path, previous_path)
progress.update(p, 'Spostamento Database')
move_db(path, previous_path)
clear_cache()
progress.close()
platformtools.dialog_ok('Spostamento Completato','')
def move_videolibrary(new, old):
old = xbmc.translatePath(old)
new = xbmc.translatePath(new)
move_list = filetools.listdir(old)
for d in move_list:
od = filetools.join(old, d)
nd = filetools.join(new, d)
dir_util.copy_tree(od,nd)
dir_util.remove_tree(od,1)
global p
p += 30
progress.update(p)"""
def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder):
log()
@@ -56,6 +17,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 +47,26 @@ 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)
set_new_path(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()
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):
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 = '/'
@@ -115,47 +83,147 @@ 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
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)
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)
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():
log()
progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(60601))
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]
strPath = record[1].replace(OLD, NEW)
sql = 'UPDATE path SET strPath="%s"WHERE idPath=%s' % (strPath, idPath)
sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
# dbg()
sql = 'SELECT idMovie, c22 FROM movie where c22 LIKE "%s"' % old
# 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]
strPath = record[1].replace(OLD, NEW)
sql = 'UPDATE movie SET c22="%s" WHERE idMovie=%s' % (strPath, idMovie)
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
sql = 'SELECT idEpisode, c18 FROM episode where c18 LIKE "%s"' % old
# 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]
strPath = record[1].replace(OLD, NEW)
sql = 'UPDATE episode SET c18="%s" WHERE idEpisode=%s' % (strPath, idEpisode)
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
nun_records, records = xbmc_videolibrary.execute_sql_kodi(sql)
"""global p
p += 30
progress.update(p)"""
progress.update(80)
set_new_path(path)
clear_cache()
progress.update(100)
progress.close()
def set_new_path(new, old):
write = False
def set_new_path(old, new=''):
log()
SOURCES_PATH = xbmc.translatePath("special://userdata/sources.xml")
if filetools.isfile(SOURCES_PATH):
xmldoc = minidom.parse(SOURCES_PATH)
@@ -178,46 +246,47 @@ def set_new_path(new, old):
else:
filetools.write(SOURCES_PATH, b'\n'.join([x for x in xmldoc.toprettyxml().encode("utf-8").splitlines() if x.strip()]), vfs=False)
# 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 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")
# 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)
# <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)
# <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)
# <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)
# 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)
# 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()