From 023e219143bcaebc70afa87811c02c56a593bf23 Mon Sep 17 00:00:00 2001 From: axlt2002 Date: Sat, 18 Apr 2020 01:32:23 +0200 Subject: [PATCH 1/2] Rimozione canale film / serie TV (cancella strm se unico canale) --- platformcode/config.py | 4 +- platformcode/xbmc_videolibrary.py | 228 +++++++++++++++--------------- specials/backup.py | 4 +- specials/downloads.py | 56 +------- specials/videolibrary.py | 33 ++++- 5 files changed, 151 insertions(+), 174 deletions(-) diff --git a/platformcode/config.py b/platformcode/config.py index da864ace..f8df53a7 100644 --- a/platformcode/config.py +++ b/platformcode/config.py @@ -245,7 +245,9 @@ def open_settings(): if not settings_pre.get("videolibrary_kodi", None) and settings_post.get("videolibrary_kodi", None): xbmc_videolibrary.ask_set_content(silent=True) elif settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None): - xbmc_videolibrary.clean(get_setting('videolibrarypath')) + strm_list = [] + strm_list.append(get_setting('videolibrarypath')) + xbmc_videolibrary.clean(strm_list) def get_setting(name, channel="", server="", default=None): diff --git a/platformcode/xbmc_videolibrary.py b/platformcode/xbmc_videolibrary.py index 6fcd69a8..b6bfa61e 100644 --- a/platformcode/xbmc_videolibrary.py +++ b/platformcode/xbmc_videolibrary.py @@ -878,7 +878,7 @@ def update_db(old_path, new_path, old_movies_folder, new_movies_folder, old_tvsh xbmc.executebuiltin('XBMC.ReloadSkin()') -def clean(path=''): +def clean(path_list=[]): def sql_format(path): if path.startswith("special://"): path = path.replace('/profile/', '/%/').replace('/home/userdata/', '/%/') @@ -894,127 +894,125 @@ def clean(path=''): logger.info() - 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) - 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) - 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) + for path in path_list: - progress.update(28) - 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) + idParentPath = 0 + sql_path = '' + sql_movies_path = '' + sql_tvshows_path = '' + sql_episodes_path = '' - progress.update(46) - 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) + path, sep = sql_format(path) + movies_folder = config.get_setting("folder_movies") + tvshows_folder = config.get_setting("folder_tvshows") - progress.update(64) - 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) + # 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 - progress.update(82) - 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) + 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 + + 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) + + 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) + + 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) + + 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) + + 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) + + 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) diff --git a/specials/backup.py b/specials/backup.py index b004ff5e..f1b28f7f 100644 --- a/specials/backup.py +++ b/specials/backup.py @@ -73,7 +73,9 @@ def import_videolibrary(item): filetools.rmdirtree(videolibrarytools.TVSHOWS_PATH) p_dialog.update(50) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): - xbmc_videolibrary.clean(config.get_setting('videolibrarypath')) + strm_list = [] + strm_list.append(config.get_setting('videolibrarypath')) + xbmc_videolibrary.clean(strm_list) config.verify_directories_created() if filetools.exists(movies_path): diff --git a/specials/downloads.py b/specials/downloads.py index b514affa..efa9eba8 100644 --- a/specials/downloads.py +++ b/specials/downloads.py @@ -410,61 +410,11 @@ def move_to_libray(item): if config.is_xbmc() and config.get_setting("videolibrary_kodi"): from platformcode import xbmc_videolibrary if clean == True: - xbmc_videolibrary.clean(file_strm_path) + strm_list = [] + strm_list.append(file_strm_path) + xbmc_videolibrary.clean(strm_list) 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)): - 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 - logger.info('Delete File: ' + str(filetools.join(config.get_videolibrary_path(), FOLDER, path_title, File))) - filetools.remove(filetools.join(config.get_videolibrary_path(), FOLDER, path_title, File)) - - if config.get_setting("videolibrary_kodi"): - from platformcode import xbmc_videolibrary - xbmc_videolibrary.update(FOLDER) - if clean == True: - import xbmc - while xbmc.getCondVisibility('Library.IsScanningVideo()'): - xbmc.sleep(500) - xbmc_videolibrary.clean() - - if config.get_setting("library_add") == True and config.get_setting("library_move") == False: - if filetools.isfile(final_path): - if item.contentType == "movie" and item.infoLabels["tmdb_id"]: - library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", - action="findvideos", infoLabels=item.infoLabels, url=final_path) - videolibrarytools.save_movie(library_item) - - elif item.contentType == "episode" and item.infoLabels["tmdb_id"]: - library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", - action="findvideos", infoLabels=item.infoLabels, url=final_path) - tvshow = Item(channel="downloads", contentType="tvshow", - infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]}) - videolibrarytools.save_tvshow(tvshow, [library_item])""" - def update_json(path, params): item = Item().fromjson(filetools.read(path)) diff --git a/specials/videolibrary.py b/specials/videolibrary.py index f121d7ea..23f99605 100644 --- a/specials/videolibrary.py +++ b/specials/videolibrary.py @@ -772,7 +772,9 @@ def delete_videolibrary(item): p_dialog.update(80) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): from platformcode import xbmc_videolibrary - xbmc_videolibrary.clean(config.get_setting('videolibrarypath')) + strm_list = [] + strm_list.append(config.get_setting('videolibrarypath')) + xbmc_videolibrary.clean(strm_list) p_dialog.update(90) config.verify_directories_created() @@ -1027,7 +1029,9 @@ def delete(item): if config.is_xbmc() and config.get_setting("videolibrary_kodi"): from platformcode import xbmc_videolibrary - xbmc_videolibrary.clean(_item.extra) + strm_list = [] + strm_list.append(_item.extra) + xbmc_videolibrary.clean(strm_list) logger.info("All links removed") platformtools.itemlist_refresh() @@ -1042,8 +1046,12 @@ def delete(item): if item.multicanal: # Obtener listado de canales if item.dead == '': - opciones = [config.get_localized_string(70086) % k.capitalize() for k in list(item.library_urls.keys()) if - k != "downloads"] + opciones = [] + channels = [] + for k in list(item.library_urls.keys()): + if k != "downloads": + opciones.append(config.get_localized_string(70086) % k.capitalize()) + channels.append(k) opciones.insert(0, heading) index = platformtools.dialog_select(config.get_localized_string(30163), opciones) @@ -1055,16 +1063,33 @@ def delete(item): elif index > 0: # Seleccionado Eliminar canal X canal = opciones[index].replace(config.get_localized_string(70079), "").lower() + channels.remove(canal) else: return else: canal = item.dead num_enlaces = 0 + strm_list = [] for fd in filetools.listdir(item.path): if fd.endswith(canal + '].json') or scrapertools.find_single_match(fd, '%s]_\d+.torrent' % canal): if filetools.remove(filetools.join(item.path, fd)): num_enlaces += 1 + # Remove strm and nfo if no other channel + episode = fd.replace(' [' + canal + '].json', '') + found_ch = False + for ch in channels: + if filetools.exists(filetools.join(item.path, episode + ' [' + ch + '].json')): + found_ch = True + break + if found_ch == False: + filetools.remove(filetools.join(item.path, episode + '.nfo')) + filetools.remove(filetools.join(item.path, episode + '.strm')) + strm_list.append(filetools.join(item.extra, episode + '.strm')) + + if config.is_xbmc() and config.get_setting("videolibrary_kodi") and strm_list: + from platformcode import xbmc_videolibrary + xbmc_videolibrary.clean(strm_list) if num_enlaces > 0: # Actualizar .nfo From bf0e190b0b789e109c53452865814685e6af5dad Mon Sep 17 00:00:00 2001 From: axlt2002 Date: Sat, 18 Apr 2020 02:17:04 +0200 Subject: [PATCH 2/2] Visualizzazione icona KoD nelle notifiche + aggiornato testi --- platformcode/platformtools.py | 6 ++++-- platformcode/updater.py | 4 ++-- platformcode/xbmc_videolibrary.py | 1 - resources/language/English/strings.po | 8 ++++++++ resources/language/Italian/strings.po | 10 +++++++++- specials/autoplay.py | 3 +-- specials/backup.py | 4 ++-- specials/videolibrary.py | 4 ++-- 8 files changed, 28 insertions(+), 12 deletions(-) diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index 2590bf34..b34a5dfa 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -38,6 +38,8 @@ from platformcode import logger from platformcode import config from platformcode import unify +addon = xbmcaddon.Addon('plugin.video.kod') +addon_icon = os.path.join( addon.getAddonInfo( "path" ), "logo.png" ) class XBMCPlayer(xbmc.Player): @@ -60,10 +62,10 @@ def dialog_ok(heading, line1, line2="", line3=""): return dialog.ok(heading, makeMessage(line1, line2, line3)) -def dialog_notification(heading, message, icon=0, time=5000, sound=True): +def dialog_notification(heading, message, icon=3, time=5000, sound=True): dialog = xbmcgui.Dialog() try: - l_icono = xbmcgui.NOTIFICATION_INFO, xbmcgui.NOTIFICATION_WARNING, xbmcgui.NOTIFICATION_ERROR + l_icono = xbmcgui.NOTIFICATION_INFO, xbmcgui.NOTIFICATION_WARNING, xbmcgui.NOTIFICATION_ERROR, addon_icon dialog.notification(heading, message, l_icono[icon], time, sound) except: dialog_ok(heading, message) diff --git a/platformcode/updater.py b/platformcode/updater.py index dbedd772..a9effa93 100644 --- a/platformcode/updater.py +++ b/platformcode/updater.py @@ -174,11 +174,11 @@ def check(background=False): 'w') # il file di tracking viene eliminato, lo ricreo if addon.getSetting("addon_update_message"): if background: - platformtools.dialog_notification(config.get_localized_string(20000), 'Aggiornato fino al commit ' + commits[0]['sha'][:7] + '\napri il menu principale per vedere il changelog', time=3000, sound=False) + platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80040) % commits[0]['sha'][:7], time=3000, sound=False) with open(xbmc.translatePath(changelogFile), 'a+') as fileC: fileC.write(changelog) elif changelog: - platformtools.dialog_ok('Kodi on Demand', 'Aggiornamenti applicati:\n' + changelog) + platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(80041) + changelog) localCommitFile.seek(0) localCommitFile.truncate() diff --git a/platformcode/xbmc_videolibrary.py b/platformcode/xbmc_videolibrary.py index b6bfa61e..a4f41875 100644 --- a/platformcode/xbmc_videolibrary.py +++ b/platformcode/xbmc_videolibrary.py @@ -216,7 +216,6 @@ def sync_trakt_kodi(silent=True): if notificacion: platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60045), - icon=0, time=2000) diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index 41632c2d..0eec9396 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -6219,4 +6219,12 @@ msgstr "" msgctxt "#80039" msgid "The video library has been deleted" +msgstr "" + +msgctxt "#80040" +msgid "Add-on updated to commit %s" +msgstr "" + +msgctxt "#80041" +msgid "Latest updates:\n" msgstr "" \ No newline at end of file diff --git a/resources/language/Italian/strings.po b/resources/language/Italian/strings.po index 0e8b3116..ecdeef54 100644 --- a/resources/language/Italian/strings.po +++ b/resources/language/Italian/strings.po @@ -6219,4 +6219,12 @@ msgstr "Eliminazione videoteca..." msgctxt "#80039" msgid "The video library has been deleted" -msgstr "La videoteca è stata eliminata" \ No newline at end of file +msgstr "La videoteca è stata eliminata" + +msgctxt "#80040" +msgid "Add-on updated to commit %s" +msgstr "Add-on aggiornato al commit %s" + +msgctxt "#80041" +msgid "Latest updates:\n" +msgstr "Ultimi aggiornamenti:\n" \ No newline at end of file diff --git a/specials/autoplay.py b/specials/autoplay.py index 9f46f4ac..5d66b9f9 100644 --- a/specials/autoplay.py +++ b/specials/autoplay.py @@ -450,9 +450,8 @@ def init(channel, list_servers, list_quality, reset=False): if not result: heading = config.get_localized_string(60077) msj = config.get_localized_string(60078) - icon = 1 - platformtools.dialog_notification(heading, msj, icon, sound=False) + platformtools.dialog_notification(heading, msj, sound=False) return result diff --git a/specials/backup.py b/specials/backup.py index f1b28f7f..d46b4a1e 100644 --- a/specials/backup.py +++ b/specials/backup.py @@ -46,7 +46,7 @@ def export_videolibrary(item): p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() - platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80004), icon=0, time=5000, sound=False) + platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80004), time=5000, sound=False) def import_videolibrary(item): @@ -89,7 +89,7 @@ def import_videolibrary(item): p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() - platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80008), icon=0, time=5000, sound=False) + platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80008), time=5000, sound=False) if platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80009)): import service diff --git a/specials/videolibrary.py b/specials/videolibrary.py index 23f99605..580ea044 100644 --- a/specials/videolibrary.py +++ b/specials/videolibrary.py @@ -754,7 +754,7 @@ def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_ xbmc.sleep(1000) 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), time=5000, sound=False) def delete_videolibrary(item): @@ -781,7 +781,7 @@ def delete_videolibrary(item): p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() - platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80039), icon=0, time=5000, sound=False) + platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80039), time=5000, sound=False) # metodos de menu contextual