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
+6
View File
@@ -247,6 +247,12 @@ def open_settings():
elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None): elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None):
xbmc_videolibrary.clean(get_setting('videolibrarypath')) 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): def get_setting(name, channel="", server="", default=None):
""" """
+122 -98
View File
@@ -515,27 +515,6 @@ def update(folder_content=config.get_setting("folder_tvshows"), folder=""):
xbmc.executebuiltin('XBMC.ReloadSkin()') 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(): def search_library_path():
sql = 'SELECT strPath FROM path WHERE strPath LIKE "special://%/plugin.video.kod/library/" AND idParentPath ISNULL' sql = 'SELECT strPath FROM path WHERE strPath LIKE "special://%/plugin.video.kod/library/" AND idParentPath ISNULL'
nun_records, records = execute_sql_kodi(sql) 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()') 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() logger.info()
if path.startswith("special://"): idParentPath = 0
path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/') sql_path = ''
sep = '/' sql_movies_path = ''
elif '://' in path: sql_tvshows_path = ''
sep = '/' sql_episodes_path = ''
else: sep = os.sep
if not path.endswith(sep): path, sep = sql_format(path)
path += sep 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 = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80025))
progress.update(0) progress.update(0)
idParentPath = 0 if sql_path:
# search video library path in the DB # search video library path in the DB
sql = 'SELECT idPath FROM path where strPath LIKE "%s"' % path sql = 'SELECT idPath FROM path where strPath LIKE "%s"' % sql_path
nun_records, records = execute_sql_kodi(sql) nun_records, records = execute_sql_kodi(sql)
# delete video library path # delete video library path
if records: if records:
idPath = records[0][0] idPath = records[0][0]
idParentPath = idPath idParentPath = idPath
if not config.get_setting("videolibrary_kodi"): if not config.get_setting("videolibrary_kodi"):
sql = 'DELETE from path WHERE idPath=%s' % idPath sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql) nun_records, records = execute_sql_kodi(sql)
progress.update(10) progress.update(10)
movies_path = path + config.get_setting("folder_movies") if sql_movies_path:
if not movies_path.endswith(sep): movies_path += sep # search movies in the DB
movies_path += '%' sql = 'SELECT idMovie FROM movie where c22 LIKE "%s"' % sql_movies_path
nun_records, records = execute_sql_kodi(sql)
# search movies in the DB # delete movies
sql = 'SELECT idMovie FROM movie where c22 LIKE "%s"' % movies_path if records:
nun_records, records = execute_sql_kodi(sql) for record in records:
# delete movies idMovie = record[0]
if records: sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
for record in records: nun_records, records = execute_sql_kodi(sql)
idMovie = record[0]
sql = 'DELETE from movie WHERE idMovie=%s' % idMovie
nun_records, records = execute_sql_kodi(sql)
progress.update(28) progress.update(28)
# search movies path and folders in the DB if sql_movies_path:
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % movies_path # search movies path and folders in the DB
nun_records, records = execute_sql_kodi(sql) sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % sql_movies_path
# delete movies path and folders nun_records, records = execute_sql_kodi(sql)
if records: # delete movies path and folders
for record in records: if records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"): for record in records:
continue if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
idPath = record[0] continue
sql = 'DELETE from path WHERE idPath=%s' % idPath idPath = record[0]
nun_records, records = execute_sql_kodi(sql) sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(46) progress.update(46)
tvshows_path = path + config.get_setting("folder_tvshows") if sql_tvshows_path:
if not tvshows_path.endswith(sep): tvshows_path += sep # search TV shows in the DB
tvshows_path += '%' sql = 'SELECT idShow FROM tvshow_view where strPath LIKE "%s"' % sql_tvshows_path
nun_records, records = execute_sql_kodi(sql)
# search TV shows in the DB # delete TV shows
sql = 'SELECT idShow FROM tvshow_view where strPath LIKE "%s"' % tvshows_path if records:
nun_records, records = execute_sql_kodi(sql) for record in records:
# delete TV shows idShow = record[0]
if records: sql = 'DELETE from tvshow WHERE idShow=%s' % idShow
for record in records: nun_records, records = execute_sql_kodi(sql)
idShow = record[0]
sql = 'DELETE from tvshow WHERE idShow=%s' % idShow
nun_records, records = execute_sql_kodi(sql)
progress.update(64) progress.update(64)
# search episodes in the DB if sql_episodes_path:
sql = 'SELECT idEpisode FROM episode where c18 LIKE "%s"' % tvshows_path # search episodes in the DB
nun_records, records = execute_sql_kodi(sql) sql = 'SELECT idEpisode FROM episode where c18 LIKE "%s"' % sql_episodes_path
# delete episodes nun_records, records = execute_sql_kodi(sql)
if records: # delete episodes
for record in records: if records:
idEpisode = record[0] for record in records:
sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode idEpisode = record[0]
nun_records, records = execute_sql_kodi(sql) sql = 'DELETE from episode WHERE idEpisode=%s' % idEpisode
nun_records, records = execute_sql_kodi(sql)
progress.update(82) progress.update(82)
# search TV shows path and folders in the DB if sql_tvshows_path:
sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % tvshows_path # search TV shows path and folders in the DB
nun_records, records = execute_sql_kodi(sql) sql = 'SELECT idPath, idParentPath FROM path where strPath LIKE "%s"' % sql_tvshows_path
# delete tvshows path and folders nun_records, records = execute_sql_kodi(sql)
if records: # delete tvshows path and folders
for record in records: if records:
if record[1] == idParentPath and config.get_setting("videolibrary_kodi"): for record in records:
continue if record[1] == idParentPath and config.get_setting("videolibrary_kodi"):
idPath = record[0] continue
sql = 'DELETE from path WHERE idPath=%s' % idPath idPath = record[0]
nun_records, records = execute_sql_kodi(sql) sql = 'DELETE from path WHERE idPath=%s' % idPath
nun_records, records = execute_sql_kodi(sql)
progress.update(100) progress.update(100)
xbmc.sleep(1000) xbmc.sleep(1000)
+7 -3
View File
@@ -3277,7 +3277,7 @@ msgid "Movies folder*"
msgstr "" msgstr ""
msgctxt "#70120" msgctxt "#70120"
msgid "Add KoD content to Kodi video library*" msgid "Add KoD contents to Kodi video library*"
msgstr "" msgstr ""
msgctxt "#70121" msgctxt "#70121"
@@ -3717,7 +3717,7 @@ msgid "Add completed downloads to the video library "
msgstr "" msgstr ""
msgctxt "#70231" msgctxt "#70231"
msgid "Move the downloaded file to the video library" msgid "Move downloaded files to the video library*"
msgstr "" msgstr ""
msgctxt "#70232" msgctxt "#70232"
@@ -5924,7 +5924,7 @@ msgid "Logging"
msgstr "" msgstr ""
msgctxt "#70789" msgctxt "#70789"
msgid "* Change by opening the settings from the KoD main menu" msgid "* Change by opening the settings from KoD main menu"
msgstr "" msgstr ""
@@ -6223,4 +6223,8 @@ msgstr ""
msgctxt "#80039" msgctxt "#80039"
msgid "The video library has been deleted" msgid "The video library has been deleted"
msgstr ""
msgctxt "#80040"
msgid "In order to watch the downloaded files that have been moved to the video library, you have first to enable the option to add KoD contents to Kodi video library"
msgstr "" msgstr ""
+10 -6
View File
@@ -3276,8 +3276,8 @@ msgid "Movies folder*"
msgstr "Cartella film*" msgstr "Cartella film*"
msgctxt "#70120" msgctxt "#70120"
msgid "Add KoD content to Kodi video library*" msgid "Add KoD contents to Kodi video library*"
msgstr "Aggiungi i contenuti di KoD alla videoteca di Kodi*" msgstr "Aggiungi la videoteca di KoD alla libreria di Kodi*"
msgctxt "#70121" msgctxt "#70121"
msgid "Activate" msgid "Activate"
@@ -3716,8 +3716,8 @@ msgid "Add completed downloads to the video library "
msgstr "Aggiungi download completi alla videoteca" msgstr "Aggiungi download completi alla videoteca"
msgctxt "#70231" msgctxt "#70231"
msgid "Move the downloaded file to the video library" msgid "Move downloaded files to the video library*"
msgstr "Sposta i files scaricati nella videoteca" msgstr "Sposta i file scaricati nella videoteca*"
msgctxt "#70232" msgctxt "#70232"
msgid "View downloaded files" msgid "View downloaded files"
@@ -5924,7 +5924,7 @@ msgid "Logging"
msgstr "Logging" msgstr "Logging"
msgctxt "#70789" msgctxt "#70789"
msgid "* Change by opening the settings from the KoD main menu" msgid "* Change by opening the settings from KoD main menu"
msgstr "* Cambia aprendo le impostazioni dal menu principale di KoD" msgstr "* Cambia aprendo le impostazioni dal menu principale di KoD"
@@ -6223,4 +6223,8 @@ msgstr "Eliminazione videoteca..."
msgctxt "#80039" msgctxt "#80039"
msgid "The video library has been deleted" msgid "The video library has been deleted"
msgstr "La videoteca è stata eliminata" msgstr "La videoteca è stata eliminata"
msgctxt "#80040"
msgid "In order to watch the downloaded files that have been moved to the video library, you have first to enable the option to add KoD contents to Kodi video library"
msgstr "Per guardare i file scaricati che sono stati spostati nella videoteca, devi prima abilitare l'opzione per aggiungere la videoteca di KoD alla libreria di Kodi"
+10 -9
View File
@@ -93,15 +93,16 @@
<!-- Downloads --> <!-- Downloads -->
<category label="30153"> <category label="30153">
<setting id="downloadenabled" type="bool" label="70689" default="false"/> <setting id="downloadenabled" type="bool" label="70689" default="false"/>
<setting id="downloadpath" type="folder" label="30017" visible="eq(-1,true)" default="special://profile/addon_data/plugin.video.kod/downloads/" subsetting="true" option="writeable"/> <setting id="downloadpath" type="folder" label="30017" visible="eq(-1,true)" default="special://profile/addon_data/plugin.video.kod/downloads/" option="writeable"/>
<setting id="downloadlistpath" type="folder" label="30018" visible="eq(-2,true)" default="special://profile/addon_data/plugin.video.kod/downloads/list/" subsetting="true"/> <setting id="downloadlistpath" type="folder" label="30018" visible="eq(-2,true)" default="special://profile/addon_data/plugin.video.kod/downloads/list/" option="writeable"/>
<setting id="settings_kod1" type="action" label="70789" action="" visible="eq(-3,true)"/> <!-- <setting id="library_add" type="bool" label="70230" default="false"/>
<setting id="library_add" type="bool" label="70230" default="false"/> <setting id="library_move" type="bool" label="70231" default="false" visible="eq(-1,true)" subsetting="true"/> -->
<setting id="library_move" type="bool" label="70231" default="false" visible="eq(-1,true)" subsetting="true"/> <setting id="library_move" type="bool" label="70231" visible="eq(-3,true)" default="false"/>
<setting id="browser" type="bool" label="70232" default="true"/> <setting id="settings_kod1" type="action" label="70789" action="" visible="eq(-4,true)"/>
<setting id="server_speed" type="bool" label="70242" default="true"/> <setting id="browser" type="bool" label="70232" visible="eq(-5,true)" default="true"/>
<setting id="quality" type="select" label="70240" lvalues="70241|70763|70764|70765" default="0"/> <setting id="server_speed" type="bool" label="70242" visible="eq(-6,true)" default="true"/>
<setting id="download_adv" type="action" label="30030" action="RunPlugin(plugin://plugin.video.kod/?ew0KCSJhY3Rpb24iOiJjaGFubmVsX2NvbmZpZyIsDQoJImNvbmZpZyI6ImRvd25sb2FkcyIsDQogICAgImNoYW5uZWwiOiJzZXR0aW5nIg0KfQ==)"/> <setting id="quality" type="select" label="70240" lvalues="70241|70763|70764|70765" visible="eq(-7,true)" default="0"/>
<setting id="download_adv" type="action" label="30030" visible="eq(-8,true)" action="RunPlugin(plugin://plugin.video.kod/?ew0KCSJhY3Rpb24iOiJjaGFubmVsX2NvbmZpZyIsDQoJImNvbmZpZyI6ImRvd25sb2FkcyIsDQogICAgImNoYW5uZWwiOiJzZXR0aW5nIg0KfQ==)"/>
</category> </category>
<!-- News --> <!-- News -->
+40 -3
View File
@@ -363,7 +363,44 @@ def move_to_libray(item):
library_path = filetools.join(move_path, *filetools.split(item.downloadFilename)) library_path = filetools.join(move_path, *filetools.split(item.downloadFilename))
final_path = download_path final_path = download_path
if config.get_setting("library_add") == True and config.get_setting("library_move") == True: if not filetools.isdir(filetools.dirname(library_path)):
filetools.mkdir(filetools.dirname(library_path))
if filetools.isfile(library_path) and filetools.isfile(download_path):
filetools.remove(library_path)
if filetools.isfile(download_path):
if filetools.move(download_path, library_path):
final_path = library_path
if len(filetools.listdir(filetools.dirname(download_path))) == 0:
filetools.rmdir(filetools.dirname(download_path))
logger.info('ITEM = ' + str(item))
name = item.contentTitle if item.contentType == 'movie' else str(item.infoLabels['season']) + 'x' + str(item.infoLabels['episode']).zfill(2)
list_item = filetools.listdir(filetools.join(config.get_videolibrary_path(), FOLDER, path_title))
clean = False
for File in list_item:
filename = File.lower()
name = name.lower()
if filename.startswith(name) and (filename.endswith('.strm') or filename.endswith('.json') or filename.endswith('.nfo')):
clean = True
file_path = filetools.join(config.get_videolibrary_path(), FOLDER, path_title, File)
logger.info('Delete File: ' + str(file_path))
filetools.remove(file_path)
if file_path.endswith('.strm'):
file_strm_path = file_path
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
from platformcode import xbmc_videolibrary
if clean == True:
import xbmc
xbmc_videolibrary.clean(file_strm_path)
xbmc_videolibrary.update(FOLDER, path_title)
"""if config.get_setting("library_add") == True and config.get_setting("library_move") == True:
if not filetools.isdir(filetools.dirname(library_path)): if not filetools.isdir(filetools.dirname(library_path)):
filetools.mkdir(filetools.dirname(library_path)) filetools.mkdir(filetools.dirname(library_path))
@@ -413,7 +450,7 @@ def move_to_libray(item):
action="findvideos", infoLabels=item.infoLabels, url=final_path) action="findvideos", infoLabels=item.infoLabels, url=final_path)
tvshow = Item(channel="downloads", contentType="tvshow", tvshow = Item(channel="downloads", contentType="tvshow",
infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]}) infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]})
videolibrarytools.save_tvshow(tvshow, [library_item]) videolibrarytools.save_tvshow(tvshow, [library_item])"""
def update_json(path, params): def update_json(path, params):
@@ -619,7 +656,7 @@ def download_from_url(url, item):
save_server_statistics(item.server, d.speed[0], d.state != d.states.error) save_server_statistics(item.server, d.speed[0], d.state != d.states.error)
if status == STATUS_CODES.completed: if status == STATUS_CODES.completed and config.get_setting("library_move") == True:
move_to_libray(item.clone(downloadFilename=file)) move_to_libray(item.clone(downloadFilename=file))
return {"downloadUrl": d.download_url, "downloadStatus": status, "downloadSize": d.size[0], return {"downloadUrl": d.download_url, "downloadStatus": status, "downloadSize": d.size[0],
+1 -6
View File
@@ -1018,13 +1018,8 @@ def delete(item):
filetools.rmdir(_item.path) filetools.rmdir(_item.path)
if config.is_xbmc() and config.get_setting("videolibrary_kodi"): if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
import xbmc
# esperamos 5 segundos para dar tiempo a borrar los ficheros
xbmc.sleep(5000)
# TODO mirar por qué no funciona al limpiar en la videoteca de Kodi al añadirle un path
# limpiamos la videoteca de Kodi
from platformcode import xbmc_videolibrary from platformcode import xbmc_videolibrary
xbmc_videolibrary.clean() xbmc_videolibrary.clean(_item.path)
logger.info("All links removed") logger.info("All links removed")
platformtools.itemlist_refresh() platformtools.itemlist_refresh()