Alcuni fix al download dei torrent

This commit is contained in:
Alhaziel01
2020-05-07 20:21:18 +02:00
parent 50ff2802d9
commit 264f3b7626
8 changed files with 204 additions and 153 deletions
+28 -25
View File
@@ -262,33 +262,36 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
longtitle = title + (s if title and title2 else '') + title2 + '\n' longtitle = title + (s if title and title2 else '') + title2 + '\n'
if sceneTitle: if sceneTitle:
parsedTitle = guessit(title) try:
title = longtitle = parsedTitle.get('title', '') parsedTitle = guessit(title)
log('TITOLO',title) title = longtitle = parsedTitle.get('title', '')
if parsedTitle.get('source'): log('TITOLO',title)
quality = str(parsedTitle.get('source')) if parsedTitle.get('source'):
if parsedTitle.get('screen_size'): quality = str(parsedTitle.get('source'))
quality += ' ' + str(parsedTitle.get('screen_size', '')) if parsedTitle.get('screen_size'):
if not scraped['year']: quality += ' ' + str(parsedTitle.get('screen_size', ''))
infolabels['year'] = parsedTitle.get('year', '') if not scraped['year']:
if parsedTitle.get('episode') and parsedTitle.get('season'): infolabels['year'] = parsedTitle.get('year', '')
longtitle = title + s if parsedTitle.get('episode') and parsedTitle.get('season'):
longtitle = title + s
if type(parsedTitle.get('season')) == list: if type(parsedTitle.get('season')) == list:
longtitle += str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1]) longtitle += str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1])
else: else:
longtitle += str(parsedTitle.get('season')) longtitle += str(parsedTitle.get('season'))
if type(parsedTitle.get('episode')) == list: if type(parsedTitle.get('episode')) == list:
longtitle += 'x' + str(parsedTitle.get('episode')[0]).zfill(2) + '-' + str(parsedTitle.get('episode')[-1]).zfill(2) longtitle += 'x' + str(parsedTitle.get('episode')[0]).zfill(2) + '-' + str(parsedTitle.get('episode')[-1]).zfill(2)
else: else:
longtitle += 'x' + str(parsedTitle.get('episode')).zfill(2) longtitle += 'x' + str(parsedTitle.get('episode')).zfill(2)
elif parsedTitle.get('season') and type(parsedTitle.get('season')) == list: elif parsedTitle.get('season') and type(parsedTitle.get('season')) == list:
longtitle += s + config.get_localized_string(30140) + " " +str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1]) longtitle += s + config.get_localized_string(30140) + " " +str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1])
elif parsedTitle.get('season'): elif parsedTitle.get('season'):
longtitle += s + config.get_localized_string(60027) % str(parsedTitle.get('season')) longtitle += s + config.get_localized_string(60027) % str(parsedTitle.get('season'))
if parsedTitle.get('episode_title'): if parsedTitle.get('episode_title'):
longtitle += s + parsedTitle.get('episode_title') longtitle += s + parsedTitle.get('episode_title')
except:
log('Error')
longtitle = typo(longtitle, 'bold') longtitle = typo(longtitle, 'bold')
lang1, longtitle = scrapeLang(scraped, lang, longtitle) lang1, longtitle = scrapeLang(scraped, lang, longtitle)
+7 -4
View File
@@ -1351,8 +1351,11 @@ def play_torrent(item, xlistitem, mediaurl):
from servers import torrent from servers import torrent
torrent_options = torrent_client_installed(show_tuple=True) torrent_options = torrent_client_installed(show_tuple=True)
if len(torrent_options) == 0:
if len(torrent_options) > 1: from specials import elementum_download
elementum_download.download()
return play_torrent(item, xlistitem, mediaurl)
elif len(torrent_options) > 1:
selection = dialog_select(config.get_localized_string(70193), [opcion[0] for opcion in torrent_options]) selection = dialog_select(config.get_localized_string(70193), [opcion[0] for opcion in torrent_options])
else: else:
selection = 0 selection = 0
@@ -1365,13 +1368,13 @@ def play_torrent(item, xlistitem, mediaurl):
mediaurl = urllib.quote_plus(item.url) mediaurl = urllib.quote_plus(item.url)
torr_client = torrent_options[selection][0] torr_client = torrent_options[selection][0]
if torr_client in ['quasar', 'elementum'] and item.infoLabels['tmdb_id']: if torr_client in ['elementum'] and item.infoLabels['tmdb_id']:
if item.contentType == 'episode' and "elementum" not in torr_client: if item.contentType == 'episode' and "elementum" not in torr_client:
mediaurl += "&episode=%s&library=&season=%s&show=%s&tmdb=%s&type=episode" % (item.infoLabels['episode'], item.infoLabels['season'], item.infoLabels['tmdb_id'], item.infoLabels['tmdb_id']) mediaurl += "&episode=%s&library=&season=%s&show=%s&tmdb=%s&type=episode" % (item.infoLabels['episode'], item.infoLabels['season'], item.infoLabels['tmdb_id'], item.infoLabels['tmdb_id'])
elif item.contentType == 'movie': elif item.contentType == 'movie':
mediaurl += "&library=&tmdb=%s&type=movie" % (item.infoLabels['tmdb_id']) mediaurl += "&library=&tmdb=%s&type=movie" % (item.infoLabels['tmdb_id'])
if torr_client in ['quasar', 'elementum'] and item.downloadFilename: if torr_client in ['elementum'] and item.downloadFilename:
torrent.elementum_download(item) torrent.elementum_download(item)
else: else:
time.sleep(3) time.sleep(3)
+1 -1
View File
@@ -144,7 +144,7 @@ msgid "Internal Client"
msgstr "" msgstr ""
msgctxt "#30034" msgctxt "#30034"
msgid ": Select the video, or 'Cancel' for all" msgid "Select the video, or 'Cancel' for all"
msgstr "" msgstr ""
msgctxt "#30035" msgctxt "#30035"
+2 -2
View File
@@ -144,8 +144,8 @@ msgid "Internal Client"
msgstr "Client Interno" msgstr "Client Interno"
msgctxt "#30034" msgctxt "#30034"
msgid ": Select the video, or 'Cancel' for all" msgid "Select the video, or 'Cancel' for all"
msgstr ": Seleziona il video o 'Annulla' per tutti" msgstr "Seleziona il video o 'Annulla' per tutti"
msgctxt "#30035" msgctxt "#30035"
msgid "ERROR in the Client" msgid "ERROR in the Client"
+87 -63
View File
@@ -23,14 +23,19 @@ from platformcode import config, platformtools
from threading import Thread, currentThread from threading import Thread, currentThread
from torrentool.api import Torrent from torrentool.api import Torrent
from lib.guessit import guessit from lib.guessit import guessit
try:
elementum_setting = xbmcaddon.Addon(id='plugin.video.elementum') elementum_setting = xbmcaddon.Addon(id='plugin.video.elementum')
elementum_host = 'http://127.0.0.1:' + elementum_setting.getSetting('remote_port') + '/torrents/' elementum_host = 'http://127.0.0.1:' + elementum_setting.getSetting('remote_port') + '/torrents/'
TorrentPath = xbmc.translatePath(elementum_setting.getSetting('torrents_path'))
except:
pass
extensions_list = ['.aaf', '.3gp', '.asf', '.avi', '.flv', '.mpeg', '.m1v', '.m2v', '.m4v', '.mkv', '.mov', '.mpg', '.mpe', '.mp4', '.ogg', '.wmv'] extensions_list = ['.aaf', '.3gp', '.asf', '.avi', '.flv', '.mpeg', '.m1v', '.m2v', '.m4v', '.mkv', '.mov', '.mpg', '.mpe', '.mp4', '.ogg', '.wmv']
# Returns an array of possible video url's from the page_url # Returns an array of possible video url's from the page_url
def get_video_url(page_url, premium=False, user='', password='', video_password=''): def get_video_url(page_url, premium=False, user='', password='', video_password=''):
torrent_options = platformtools.torrent_client_installed(show_tuple=True) torrent_options = platformtools.torrent_client_installed(show_tuple=True)
if len(torrent_options) == 0: if len(torrent_options) == 0:
from specials import elementum_download from specials import elementum_download
@@ -71,33 +76,38 @@ def mark_auto_as_watched(item):
elementumHost = 'http://127.0.0.1:65220/torrents/' elementumHost = 'http://127.0.0.1:65220/torrents/'
def elementum_download(item): def elementum_download(item):
sleep = False elementum = False
if elementum_setting.getSetting('logger_silent') == False: while not elementum:
elementum_setting.setSetting('logger_silent', 'true') try:
sleep = True sleep = False
if elementum_setting.getSetting('download_storage') != 0: if elementum_setting.getSetting('logger_silent') == False:
config.set_setting('elementumtype', elementum_setting.getSetting('download_storage')) # Backup Setting elementum_setting.setSetting('logger_silent', 'true')
elementum_setting.setSetting('download_storage', '0') # Set Setting sleep = True
sleep = True if elementum_setting.getSetting('download_storage') != 0:
if elementum_setting.getSetting('download_path') != config.get_setting('downloadpath'): config.set_setting('elementumtype', elementum_setting.getSetting('download_storage')) # Backup Setting
elementum_setting.setSetting('download_path', config.get_setting('downloadpath')) # Backup Setting elementum_setting.setSetting('download_storage', '0') # Set Setting
config.set_setting('elementumdl', elementum_setting.getSetting('download_path')) # Set Setting sleep = True
sleep = True if elementum_setting.getSetting('download_path') != config.get_setting('downloadpath'):
if sleep: time.sleep(3) elementum_setting.setSetting('download_path', config.get_setting('downloadpath')) # Backup Setting
config.set_setting('elementumdl', elementum_setting.getSetting('download_path')) # Set Setting
path = filetools.join(config.get_data_path(),'elementum_torrent.txt') sleep = True
url = urllib.quote_plus(item.url) if sleep: time.sleep(3)
filetools.write(path, url) elementum = True
path = filetools.join(config.get_data_path(),'elementum_torrent.txt')
url = urllib.quote_plus(item.url)
filetools.write(path, url)
except:
pass
def stop_elementum_monitor(): # def stop_elementum_monitor():
config.set_setting('stop_elementum_monitor', True) # config.set_setting('stop_elementum_monitor', True)
time.sleep(2) # time.sleep(2)
def start_elementum_monitor(): # def start_elementum_monitor():
config.set_setting('stop_elementum_monitor', False) # config.set_setting('stop_elementum_monitor', False)
time.sleep(3) # time.sleep(3)
Thread(target=elementum_monitor).start() # Thread(target=elementum_monitor).start()
@@ -106,37 +116,46 @@ def elementum_monitor():
path = filetools.join(config.get_data_path(),'elementum_torrent.txt') path = filetools.join(config.get_data_path(),'elementum_torrent.txt')
partials = [] partials = []
while True: while True:
if filetools.isfile(path): try:
log('Add Torrent') if filetools.isfile(path):
url = filetools.read(path) log('Add Torrent')
TorrentName = match(url, patron=r'btih(?::|%3A)([^&%]+)', string=True).match url = filetools.read(path)
uri = elementum_host + 'add' if url.startswith('/'):
post = 'uri=%s&file=null&all=1' % url requests.get(elementum_host + url)
match(uri, post=post, timeout=5, alfa_s=True, ignore_response_code=True) wait = False
filetools.remove(path) else:
while not filetools.isfile(filetools.join(elementum_setting.getSetting('torrents_path'), TorrentName + '.torrent')): TorrentName = match(url, patron=r'btih(?::|%3A)([^&%]+)', string=True).match
uri = elementum_host + 'add'
post = 'uri=%s&file=null&all=1' % url
match(uri, post=post, timeout=5, alfa_s=True, ignore_response_code=True)
wait = True
filetools.remove(path)
if wait:
while not filetools.isfile(filetools.join(elementum_setting.getSetting('torrents_path'), TorrentName + '.torrent')):
time.sleep(1)
else:
log('Watch')
try:
data = requests.get(elementum_host).json()
except:
data = ''
if data:
json = data['items']
for it in json:
Partial = float(match(it['label'], patron=r'(\d+\.\d+)%').match)
Title = it['info']['title']
TorrentName = match(it['path'], patron=r'resume=([^&]+)').match
File, Json = find_file(TorrentName)
update_download_info(Partial, Title, TorrentName, File, Json)
partials.append(Partial)
partials.sort()
if len(partials) > 0 and partials[0] == 100:
unset_elementum()
time.sleep(1) time.sleep(1)
else: except:
log('Watch')
try:
data = requests.get(elementum_host).json()
except:
data = ''
if data:
json = data['items']
for it in json:
Partial = float(match(it['label'], patron=r'(\d+\.\d+)%').match)
Title = it['info']['title']
TorrentName = match(it['path'], patron=r'resume=([^&]+)').match
File, Json = find_file(TorrentName)
update_download_info(Partial, Title, TorrentName, File, Json)
partials.append(Partial)
partials.sort()
if len(partials) > 0 and partials[0] == 100:
unset_elementum()
time.sleep(1) time.sleep(1)
@@ -155,9 +174,11 @@ def find_file(File):
def update_download_info(Partial, Title, TorrentName, File, Json): def update_download_info(Partial, Title, TorrentName, File, Json):
path = xbmc.translatePath(config.get_setting('downloadlistpath')) path = xbmc.translatePath(config.get_setting('downloadlistpath'))
dlpath = filetools.join(config.get_setting('downloadpath'), Title) dlpath = filetools.join(config.get_setting('downloadpath'), Title)
tpath = filetools.join(xbmc.translatePath(elementum_setting.getSetting('torrents_path')), TorrentName)
if 'TorrentName' not in Json:
jsontools.update_node(TorrentName, File, 'TorrentName', path, silent=True)
if Json['downloadSize'] == 0: if Json['downloadSize'] == 0:
size = Torrent.from_file(tpath + '.torrent').total_size size = Torrent.from_file(filetools.join(TorrentPath, TorrentName + '.torrent')).total_size
jsontools.update_node(size, File, 'downloadSize', path, silent=True) jsontools.update_node(size, File, 'downloadSize', path, silent=True)
if Json['downloadFilename'] != dlpath and 'backupFilename' not in Json: if Json['downloadFilename'] != dlpath and 'backupFilename' not in Json:
jsontools.update_node(Json['downloadFilename'], File, 'backupFilename', path, silent=True) jsontools.update_node(Json['downloadFilename'], File, 'backupFilename', path, silent=True)
@@ -169,14 +190,17 @@ def update_download_info(Partial, Title, TorrentName, File, Json):
jsontools.update_node(Json['downloadSize'], File, 'downloadCompleted', path, silent=True) jsontools.update_node(Json['downloadSize'], File, 'downloadCompleted', path, silent=True)
jsontools.update_node(2, File, 'downloadStatus', path, silent=True) jsontools.update_node(2, File, 'downloadStatus', path, silent=True)
requests.get(elementum_host + 'pause/' + TorrentName) requests.get(elementum_host + 'pause/' + TorrentName)
filetools.remove(tpath + '.torrent') del_torrent(TorrentName)
time.sleep(1) time.sleep(1)
rename(TorrentName, path) rename(TorrentName, path)
# requests.get(elementum_host + 'delete/' + TorrentName + '?files=false') # requests.get(elementum_host + 'delete/' + TorrentName + '?files=false')
def del_torrent(TorrentName):
filetools.remove(filetools.join(TorrentPath, TorrentName + '.torrent'))
def rename(TorrentName, Path): def rename(TorrentName, Path):
# dbg()
File, Json = find_file(TorrentName) File, Json = find_file(TorrentName)
path = Json['downloadFilename'] path = Json['downloadFilename']
if Json['infoLabels']['mediatype'] == 'movie': if Json['infoLabels']['mediatype'] == 'movie':
@@ -191,7 +215,7 @@ def rename(TorrentName, Path):
if ext in extensions_list: extension = ext if ext in extensions_list: extension = ext
filetools.rename(filetools.join(path, f), f.replace(oldName, newName)) filetools.rename(filetools.join(path, f), f.replace(oldName, newName))
filetools.rename(path, newName) filetools.rename(path, newName)
jsontools.update_node(filetools.join(newName,newName + extension), File, 'downloadFilename', Path) jsontools.update_node(filetools.join(newName, newName + extension), File, 'downloadFilename', Path)
else: else:
oldName = filetools.split(path)[-1] oldName = filetools.split(path)[-1]
@@ -227,9 +251,9 @@ def rename(TorrentName, Path):
if not filetools.isdir(NewFolder): if not filetools.isdir(NewFolder):
filetools.mkdir(NewFolder) filetools.mkdir(NewFolder)
from_folder = filetools.join(config.get_setting('downloadpath'), filename) from_folder = filetools.join(config.get_setting('downloadpath'), filename)
to_folder = filetools.join(FolderName, title) to_folder = filetools.join(config.get_setting('downloadpath'), FolderName, title)
filetools.move(from_folder, to_folder) filetools.move(from_folder, to_folder)
jsontools.update_node(filetools.join(config.get_setting('downloadpath'),to_folder), File, 'downloadFilename', Path) jsontools.update_node(filetools.join(FolderName, title), File, 'downloadFilename', Path)
def process_filename(filename, Title, ext=True): def process_filename(filename, Title, ext=True):
extension = os.path.splitext(filename)[-1] extension = os.path.splitext(filename)[-1]
+2 -2
View File
@@ -393,8 +393,8 @@ if __name__ == "__main__":
exit(0) exit(0)
# Copia Custom code a las carpetas de Alfa desde la zona de Userdata # Copia Custom code a las carpetas de Alfa desde la zona de Userdata
from platformcode import custom_code # from platformcode import custom_code
custom_code.init() # custom_code.init()
from threading import Thread from threading import Thread
Thread(target=viewmodeMonitor).start() Thread(target=viewmodeMonitor).start()
from servers import torrent from servers import torrent
+68 -47
View File
@@ -39,10 +39,11 @@ FOLDER_MOVIES = config.get_setting("folder_movies")
FOLDER_TVSHOWS = config.get_setting("folder_tvshows") FOLDER_TVSHOWS = config.get_setting("folder_tvshows")
TITLE_FILE = "[COLOR %s]| %i%% |[/COLOR] - %s" TITLE_FILE = "[COLOR %s]| %i%% |[/COLOR] - %s"
TITLE_TVSHOW = "[COLOR %s]| %i%% |[/COLOR] - %s [%s]" TITLE_TVSHOW = "[COLOR %s]| %i%% |[/COLOR] - %s [%s]"
extensions_list = ['.aaf', '.3gp', '.asf', '.avi', '.flv', '.mpeg', '.m1v', '.m2v', '.m4v', '.mkv', '.mov', '.mpg', '.mpe', '.mp4', '.ogg', '.wmv']
def mainlist(item): def mainlist(item):
logger.info() log()
itemlist = [] itemlist = []
# Lista de archivos # Lista de archivos
@@ -145,7 +146,7 @@ def settings(item):
def browser(item): def browser(item):
logger.info() log()
itemlist = [] itemlist = []
for file in filetools.listdir(item.url): for file in filetools.listdir(item.url):
@@ -179,17 +180,23 @@ def del_dir(item):
def clean_all(item): def clean_all(item):
logger.info() log()
stop_all() stop_all()
removeFiles = False removeFiles = False
if platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(30300)): if platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(30300)):
removeFiles = True removeFiles = True
for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)): for File in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)):
if fichero.endswith(".json"): if File.endswith(".json"):
download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero))) download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, File)))
if download_item.TorrentName:
path = filetools.join(config.get_data_path(),'elementum_torrent.txt')
url = '/pause/' + download_item.TorrentName
filetools.write(path, url)
from servers.torrent import del_torrent
del_torrent(download_item.TorrentName)
if not item.contentType == "tvshow" or ( item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel): if not item.contentType == "tvshow" or ( item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel):
filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, fichero)) filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, File))
if removeFiles: if removeFiles:
filetools.remove(filetools.join(DOWNLOAD_PATH, download_item.downloadFilename)) filetools.remove(filetools.join(DOWNLOAD_PATH, download_item.downloadFilename))
dirName = filetools.join(DOWNLOAD_PATH, filetools.dirname(download_item.downloadFilename)) dirName = filetools.join(DOWNLOAD_PATH, filetools.dirname(download_item.downloadFilename))
@@ -205,11 +212,15 @@ def reload(item):
def stop_all(item=None): def stop_all(item=None):
logger.info() log()
for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)): for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)):
if fichero.endswith(".json"): if fichero.endswith(".json"):
download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero))) download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero)))
if download_item.TorrentName:
path = filetools.join(config.get_data_path(),'elementum_torrent.txt')
url = '/pause/' + download_item.TorrentName
filetools.write(path, url)
if download_item.downloadStatus == 4: if download_item.downloadStatus == 4:
update_json(filetools.join(DOWNLOAD_LIST_PATH, fichero), {"downloadStatus": STATUS_CODES.stoped}) update_json(filetools.join(DOWNLOAD_LIST_PATH, fichero), {"downloadStatus": STATUS_CODES.stoped})
xbmc.sleep(300) xbmc.sleep(300)
@@ -218,7 +229,7 @@ def stop_all(item=None):
def clean_ready(item): def clean_ready(item):
logger.info() log()
for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)): for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)):
if fichero.endswith(".json"): if fichero.endswith(".json"):
download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero))) download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero)))
@@ -230,7 +241,7 @@ def clean_ready(item):
def restart_error(item): def restart_error(item):
logger.info() log()
for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)): for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)):
if fichero.endswith(".json"): if fichero.endswith(".json"):
download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero))) download_item = Item().fromjson(filetools.read(filetools.join(DOWNLOAD_LIST_PATH, fichero)))
@@ -242,8 +253,7 @@ def restart_error(item):
filetools.remove( filetools.remove(
filetools.join(DOWNLOAD_PATH, download_item.downloadFilename)) filetools.join(DOWNLOAD_PATH, download_item.downloadFilename))
update_json(item.path, update_json(item.path, {"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0})
{"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0})
platformtools.itemlist_refresh() platformtools.itemlist_refresh()
@@ -270,7 +280,7 @@ def download_all_background(item):
def menu(item): def menu(item):
logger.info() log()
if item.downloadServer: if item.downloadServer:
servidor = item.downloadServer.get("server", "Auto") servidor = item.downloadServer.get("server", "Auto")
else: else:
@@ -314,7 +324,7 @@ def menu(item):
# -1 es cancelar # -1 es cancelar
if seleccion == -1: return if seleccion == -1: return
logger.info("option=%s" % (opciones[seleccion])) log("option=", opciones[seleccion])
# Opcion Eliminar # Opcion Eliminar
if opciones[seleccion] == op[1]: if opciones[seleccion] == op[1]:
filetools.remove(item.path) filetools.remove(item.path)
@@ -335,21 +345,33 @@ def menu(item):
if filetools.isfile(filetools.join(DOWNLOAD_PATH, item.downloadFilename)): if filetools.isfile(filetools.join(DOWNLOAD_PATH, item.downloadFilename)):
filetools.remove(filetools.join(DOWNLOAD_PATH, item.downloadFilename)) filetools.remove(filetools.join(DOWNLOAD_PATH, item.downloadFilename))
update_json(item.path, {"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0, update_json(item.path, {"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0, "downloadServer": {}})
"downloadServer": {}})
if opciones[seleccion] == op[4]: if opciones[seleccion] == op[4]:
update_json(item.path, {"downloadStatus": STATUS_CODES.stoped}) update_json(item.path, {"downloadStatus": STATUS_CODES.stoped})
if opciones[seleccion] == op[5]: if opciones[seleccion] == op[5]:
xbmc.executebuiltin('PlayMedia(' + filetools.join(DOWNLOAD_PATH, item.downloadFilename) + ',resume)') path = filetools.join(DOWNLOAD_PATH, item.downloadFilename)
if filetools.isdir(path):
videos = []
files = filetools.listdir(path)
for f in files:
if os.path.splitext(f)[-1] in extensions_list:
videos.append(f)
if len(videos) > 1:
selection = platformtools.dialog_select(config.get_localized_string(30034), files)
else:
selection = 0
xbmc.executebuiltin('PlayMedia(' + filetools.join(path, files[selection]) + ',resume)')
else:
xbmc.executebuiltin('PlayMedia(' + path + ',resume)')
if opciones[seleccion] != op[5]: if opciones[seleccion] != op[5]:
platformtools.itemlist_refresh() platformtools.itemlist_refresh()
def move_to_libray(item): def move_to_libray(item):
logger.info() log()
if item.contentType == 'movie': if item.contentType == 'movie':
FOLDER = FOLDER_MOVIES FOLDER = FOLDER_MOVIES
@@ -403,7 +425,7 @@ def move_to_libray(item):
if filename.startswith(name) and (filename.endswith('.strm') or (filename.endswith('.json') and 'downloads' not in filename)): if filename.startswith(name) and (filename.endswith('.strm') or (filename.endswith('.json') and 'downloads' not in filename)):
clean = True clean = True
file_path = filetools.join(config.get_setting("videolibrarypath"), FOLDER, path_title, File) file_path = filetools.join(config.get_setting("videolibrarypath"), FOLDER, path_title, File)
logger.info('Delete File: ' + str(file_path)) log('Delete File:', str(file_path))
filetools.remove(file_path) filetools.remove(file_path)
if file_path.endswith('.strm'): if file_path.endswith('.strm'):
file_strm_path = file_path file_strm_path = file_path
@@ -568,7 +590,7 @@ def sort_method(item):
def download_from_url(url, item): def download_from_url(url, item):
logger.info("Attempting to download: %s" % (url)) log("Attempting to download:", url)
if url.lower().split('|')[0].endswith(".m3u8") or url.lower().startswith("rtmp"): if url.lower().split('|')[0].endswith(".m3u8") or url.lower().startswith("rtmp"):
save_server_statistics(item.server, 0, False) save_server_statistics(item.server, 0, False)
platformtools.dialog_notification('m3u8 Download',config.get_localized_string(60364), sound=False) platformtools.dialog_notification('m3u8 Download',config.get_localized_string(60364), sound=False)
@@ -602,17 +624,17 @@ def download_from_url(url, item):
# Descarga detenida. Obtenemos el estado: # Descarga detenida. Obtenemos el estado:
# Se ha producido un error en la descarga # Se ha producido un error en la descarga
if d.state == d.states.error: if d.state == d.states.error:
logger.info("Error trying to download %s" % (url)) log("Error trying to download", url)
status = STATUS_CODES.error status = STATUS_CODES.error
# La descarga se ha detenifdo # La descarga se ha detenifdo
elif d.state == d.states.stopped: elif d.state == d.states.stopped:
logger.info("Stop download") log("Stop download")
status = STATUS_CODES.canceled status = STATUS_CODES.canceled
# La descarga ha finalizado # La descarga ha finalizado
elif d.state == d.states.completed: elif d.state == d.states.completed:
logger.info("Downloaded correctly") log("Downloaded correctly")
status = STATUS_CODES.completed status = STATUS_CODES.completed
if (item.downloadSize and item.downloadSize != d.size[0]) or d.size[0] < 5000000: # if size don't correspond or file is too little (gounlimited for example send a little video to say the server is overloaded) if (item.downloadSize and item.downloadSize != d.size[0]) or d.size[0] < 5000000: # if size don't correspond or file is too little (gounlimited for example send a little video to say the server is overloaded)
@@ -628,7 +650,7 @@ def download_from_url(url, item):
def download_from_server(item): def download_from_server(item):
logger.info(item.tostring()) log(item.tostring())
unsupported_servers = ["torrent"] unsupported_servers = ["torrent"]
if item.contentChannel == 'local': if item.contentChannel == 'local':
@@ -658,12 +680,11 @@ def download_from_server(item):
item.video_urls = itemlist item.video_urls = itemlist
if not item.server: item.server = "directo" if not item.server: item.server = "directo"
else: else:
logger.info("There is nothing to reproduce") log("There is nothing to reproduce")
return {"downloadStatus": STATUS_CODES.error} return {"downloadStatus": STATUS_CODES.error}
finally: finally:
progreso.close() progreso.close()
logger.info("contentAction: %s | contentChannel: %s | server: %s | url: %s" % ( log("contentAction: %s | contentChannel: %s | server: %s | url: %s" % (item.contentAction, item.contentChannel, item.server, item.url))
item.contentAction, item.contentChannel, item.server, item.url))
if item.server == 'torrent': if item.server == 'torrent':
import xbmcgui import xbmcgui
@@ -683,11 +704,11 @@ def download_from_server(item):
# Si no esta disponible, salimos # Si no esta disponible, salimos
if not puedes: if not puedes:
logger.info("The video is NOT available") log("The video is NOT available")
return {"downloadStatus": STATUS_CODES.error} return {"downloadStatus": STATUS_CODES.error}
else: else:
logger.info("YES Video is available") log("YES Video is available")
result = {} result = {}
@@ -708,15 +729,19 @@ def download_from_server(item):
def download_from_best_server(item): def download_from_best_server(item):
logger.info("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url)) log("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
result = {"downloadStatus": STATUS_CODES.error} result = {"downloadStatus": STATUS_CODES.error}
progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70179)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70179))
try: try:
if item.downloadItemlist: if item.downloadItemlist:
logger.info('using cached servers') log('using cached servers')
play_items = [Item().fromurl(i) for i in item.downloadItemlist] play_items = [Item().fromurl(i) for i in item.downloadItemlist]
elif item.TorrentName:
path = filetools.join(config.get_data_path(),'elementum_torrent.txt')
url = '/resume/' + item.TorrentName
filetools.write(path, url)
else: else:
if item.contentChannel in ['community', 'videolibrary']: if item.contentChannel in ['community', 'videolibrary']:
channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel]) channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel])
@@ -764,12 +789,11 @@ def download_from_best_server(item):
def select_server(item): def select_server(item):
if item.server: if item.server:
return "Auto" return "Auto"
logger.info( log("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
"contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70179)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70179))
try: try:
if item.downloadItemlist: if item.downloadItemlist:
logger.info('using cached servers') log('using cached servers')
play_items = [Item().fromurl(i) for i in item.downloadItemlist] play_items = [Item().fromurl(i) for i in item.downloadItemlist]
else: else:
if item.contentChannel in ['community', 'videolibrary']: if item.contentChannel in ['community', 'videolibrary']:
@@ -811,8 +835,7 @@ def select_server(item):
def start_download(item): def start_download(item):
logger.info( log("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
"contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
# Ya tenemnos server, solo falta descargar # Ya tenemnos server, solo falta descargar
if item.contentAction == "play": if item.contentAction == "play":
ret = download_from_server(item) ret = download_from_server(item)
@@ -832,8 +855,7 @@ def start_download(item):
def get_episodes(item): def get_episodes(item):
logger.info("contentAction: %s | contentChannel: %s | contentType: %s" % ( log("contentAction: %s | contentChannel: %s | contentType: %s" % (item.contentAction, item.contentChannel, item.contentType))
item.contentAction, item.contentChannel, item.contentType))
if 'dlseason' in item: if 'dlseason' in item:
season = True season = True
@@ -910,7 +932,7 @@ def get_episodes(item):
# Cualquier otro resultado no nos vale, lo ignoramos # Cualquier otro resultado no nos vale, lo ignoramos
else: else:
logger.info("Omitiendo item no válido: %s" % episode.tostring()) log("Omitiendo item no válido:", episode.tostring())
# if Multiple Languages or Qualities # if Multiple Languages or Qualities
itemlist = videolibrarytools.filter_list(itemlist) itemlist = videolibrarytools.filter_list(itemlist)
@@ -919,9 +941,9 @@ def get_episodes(item):
def write_json(item): def write_json(item):
logger.info() log()
channel = item.channel channel = item.from_channel if item.from_channel else item.channel
item.action = "menu" item.action = "menu"
item.channel = "downloads" item.channel = "downloads"
item.downloadStatus = STATUS_CODES.stoped item.downloadStatus = STATUS_CODES.stoped
@@ -964,7 +986,7 @@ def save_download(item):
def save_download_background(item): def save_download_background(item):
logger.info() log()
# Menu contextual # Menu contextual
if item.from_action and item.from_channel: if item.from_action and item.from_channel:
item.channel = item.from_channel item.channel = item.from_channel
@@ -1013,7 +1035,7 @@ def save_download_background(item):
def save_download_videolibrary(item): def save_download_videolibrary(item):
logger.info() log()
show_disclaimer() show_disclaimer()
item.contentChannel = 'videolibrary' item.contentChannel = 'videolibrary'
item.channel = "downloads" item.channel = "downloads"
@@ -1022,8 +1044,7 @@ def save_download_videolibrary(item):
def save_download_video(item): def save_download_video(item):
logger.info("contentAction: %s | contentChannel: %s | contentTitle: %s" % ( log("contentAction: %s | contentChannel: %s | contentTitle: %s" % (item.contentAction, item.contentChannel, item.contentTitle))
item.contentAction, item.contentChannel, item.contentTitle))
set_movie_title(item) set_movie_title(item)
@@ -1038,7 +1059,7 @@ def save_download_video(item):
def save_download_movie(item): def save_download_movie(item):
logger.info("contentAction: %s | contentChannel: %s | contentTitle: %s" % ( item.contentAction, item.contentChannel, item.contentTitle)) log("contentAction: %s | contentChannel: %s | contentTitle: %s" % ( item.contentAction, item.contentChannel, item.contentTitle))
progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70191)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70191))
@@ -1073,7 +1094,7 @@ def save_download_movie(item):
def save_download_tvshow(item): def save_download_tvshow(item):
logger.info("contentAction: %s | contentChannel: %s | contentType: %s | contentSerieName: %s" % (item.contentAction, item.contentChannel, item.contentType, item.contentSerieName)) log("contentAction: %s | contentChannel: %s | contentType: %s | contentSerieName: %s" % (item.contentAction, item.contentChannel, item.contentType, item.contentSerieName))
progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70188)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70188))
try: try:
+9 -9
View File
@@ -468,16 +468,16 @@ def check_quickfixes(item):
return False return False
def update_quasar(item): # def update_quasar(item):
logger.info() # logger.info()
from platformcode import custom_code, platformtools # from platformcode import custom_code, platformtools
stat = False # stat = False
stat = custom_code.update_external_addon("quasar") # stat = custom_code.update_external_addon("quasar")
if stat: # if stat:
platformtools.dialog_notification("Actualización Quasar", "Realizada con éxito") # platformtools.dialog_notification("Actualización Quasar", "Realizada con éxito")
else: # else:
platformtools.dialog_notification("Actualización Quasar", "Ha fallado. Consulte el log") # platformtools.dialog_notification("Actualización Quasar", "Ha fallado. Consulte el log")
def conf_tools(item): def conf_tools(item):