From e8486ba1408067747e01739d2d1efe3218338883 Mon Sep 17 00:00:00 2001 From: Alhaziel01 Date: Fri, 1 May 2020 22:17:58 +0200 Subject: [PATCH 1/2] Fix Il Corsaro Nero --- channels/ilcorsaronero.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/channels/ilcorsaronero.py b/channels/ilcorsaronero.py index 4e31b8a7..de8b8502 100644 --- a/channels/ilcorsaronero.py +++ b/channels/ilcorsaronero.py @@ -7,9 +7,11 @@ from core import support def findhost(): data = support.httptools.downloadpage('https://lagazzettadelcorsaro.com/').data - return support.scrapertools.find_single_match(data, '
  • Date: Fri, 1 May 2020 22:19:26 +0200 Subject: [PATCH 2/2] Prima implementazione del Download Torrent: - Solo Film - Non Supporta Resume automatico - Solo con Elementum --- platformcode/platformtools.py | 15 +----- resources/settings.xml | 7 ++- servers/torrent.py | 91 +++++++++++++++++++++++++++++++++++ specials/downloads.py | 6 ++- 4 files changed, 104 insertions(+), 15 deletions(-) diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index a011eec0..2719d38a 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -1505,18 +1505,8 @@ def play_torrent(item, xlistitem, mediaurl): mediaurl += "&library=&tmdb=%s&type=movie" % (item.infoLabels['tmdb_id']) if torr_client in ['quasar', 'elementum'] and item.downloadFilename: - # if torr_client == 'elementum': - # config.set_setting('elementumtype', torr_setting.getSetting('download_storage')) - # config.set_setting('elementumdl', torr_setting.getSetting('download_path')) - # torr_setting.setSetting('download_storage', '0') - # torr_setting.setSetting('download_path', config.get_setting('downloadpath')) - # xbmc.sleep(1000) - torrent.call_torrent_via_web(urllib.quote_plus(item.url), torr_client) + torrent.elementum_monitor(item, torr_client) else: - # if torr_client == 'elementum': - # if config.get_setting('elementumtype'): torr_setting.setSetting('download_storage', config.get_setting('elementumtype')) - # if config.get_setting('elementumdl'): torr_setting.setSetting('download_path', config.get_setting('elementumdl')) - # xbmc.sleep(1000) xbmc.executebuiltin("PlayMedia(" + torrent_options[selection][1] % mediaurl + ")") # Si es un archivo RAR, monitorizamos el cliente Torrent hasta que haya descargado el archivo, @@ -1568,5 +1558,4 @@ def play_torrent(item, xlistitem, mediaurl): def log(texto): - xbmc.log(texto, xbmc.LOGNOTICE) - + xbmc.log(texto, xbmc.LOGNOTICE) \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index 8f9a97fb..edcf5530 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -96,14 +96,19 @@ - + + + + + + diff --git a/servers/torrent.py b/servers/torrent.py index 7e6413f6..8c26a9fd 100755 --- a/servers/torrent.py +++ b/servers/torrent.py @@ -1349,6 +1349,97 @@ def import_libtorrent(LIBTORRENT_PATH): return lt, e, e1, e2 +########################## ELEMENTUM MONITOR TEST ########################## + +def elementum_monitor(item, torr_client): + host = 'http://127.0.0.1:65220/torrents/' + torr_setting = xbmcaddon.Addon(id="plugin.video.elementum") + # from core.support import dbg;dbg() + data = httptools.downloadpage(host, alfa_s=True).data + items = jsontools.load(data)['items'] + if not items: + set_elementum() + call_torrent_via_web(urllib.quote_plus(item.url), torr_client) + + result = 0 + while result < 100: + data = httptools.downloadpage(host, alfa_s=True).data + items = jsontools.load(data)['items'] + + partials = [] + files = [] + titles = [] + + for it in items: + p = scrapertools.find_single_match(it['label'], r'(\d+\.\d+)%') + f = scrapertools.find_single_match(it['path'], r'resume=([^&]+)') + t = it['info']['title'] + partials.append(p) + files.append(f) + titles.append(t) + + partial = 0 + for i, p in enumerate(partials): + partial += float(p) + update_download_info(files[i], p, titles[i]) + + result = partial / len(items) + xbmc.sleep(5000) + + log('All Torrent downloaded.') + xbmc.sleep(1000) + unset_elementum() + + +def update_download_info(file, partial, title): + extensions_list = ['aaf', '3gp', 'asf', 'avi', 'flv', 'mpeg', 'm1v', 'm2v', 'm4v', 'mkv', 'mov', 'mpg', 'mpe', 'mp4', 'ogg', 'wmv'] + path = xbmc.translatePath(config.get_setting('downloadlistpath')) + dlpath = filetools.join(config.get_setting('downloadpath'), title) + log('DL PATH: ' + dlpath) + sep = '/' if dlpath.startswith('smb') else os.sep + if filetools.isdir(dlpath) and partial > 0: + dlfiles = filetools.listdir(dlpath) + for f in dlfiles: + log('FILE TYPE: ' + f.split('.')[-1]) + if f.split('.')[-1] in extensions_list: + dlpath = filetools.join(dlpath.split(sep)[-1], f) + else: + dlpath = dlpath.split(sep)[-1] + + files = filetools.listdir(path) + for f in files: + json = jsontools.load(filetools.read(filetools.join(path, f))) + if 'downloadServer' in json and file in json['downloadServer']['url'] or \ + 'url' in json and file in json['url']: + jsontools.update_node(dlpath, f, "downloadFilename", path) + jsontools.update_node(float(partial), f, "downloadProgress", path) + if float(partial) == 100: + jsontools.update_node(2, f, "downloadStatus", path) + +def set_elementum(): + log('SET Elementum') + torr_setting = xbmcaddon.Addon(id="plugin.video.elementum") + config.set_setting('elementumtype', torr_setting.getSetting('download_storage')) + config.set_setting('elementumdl', torr_setting.getSetting('download_path')) + torr_setting.setSetting('download_storage', '0') + torr_setting.setSetting('download_path', config.get_setting('downloadpath')) + xbmc.sleep(3000) + +def unset_elementum(): + log('UNSET Elementum') + torr_setting = xbmcaddon.Addon(id="plugin.video.elementum") + Sleep = False + if config.get_setting('elementumtype'): + torr_setting.setSetting('download_storage', str(config.get_setting('elementumtype'))) + Sleep = True + if config.get_setting('elementumdl'): + torr_setting.setSetting('download_path', config.get_setting('elementumdl')) + Sleep = True + if Sleep: + xbmc.sleep(3000) + +########################## ELEMENTUM MONITOR TEST ########################## + def log(texto): try: xbmc.log(texto, xbmc.LOGNOTICE) diff --git a/specials/downloads.py b/specials/downloads.py index 63e63f03..c45f02f4 100644 --- a/specials/downloads.py +++ b/specials/downloads.py @@ -152,7 +152,11 @@ def browser(item): if filetools.isdir(filetools.join(item.url, file)): itemlist.append(Item(channel=item.channel, title=file, action=item.action, url=filetools.join(item.url, file), context=[{ 'title': config.get_localized_string(30037), 'channel': 'downloads', 'action': "del_dir"}])) else: - itemlist.append(Item(channel=item.channel, title=file, action="play", url=filetools.join(item.url, file), context=[{ 'title': config.get_localized_string(30039), 'channel': 'downloads', 'action': "del_file"}])) + if not item.infoLabels: + infoLabels = {"mediatype":"video"} + else: + infoLabels = item.infoLabels + itemlist.append(Item(channel=item.channel, title=file, action="play", infoLabels=infoLabels, url=filetools.join(item.url, file), context=[{ 'title': config.get_localized_string(30039), 'channel': 'downloads', 'action': "del_file"}])) return itemlist