Fix Download
This commit is contained in:
@@ -407,23 +407,23 @@ def getfilefromtitle(url, title):
|
||||
logger.info("title=" + title)
|
||||
logger.info("url=" + url)
|
||||
plataforma = config.get_system_platform()
|
||||
logger.info("plataforma=" + plataforma)
|
||||
logger.info("platform=" + plataforma)
|
||||
|
||||
# nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
|
||||
import scrapertools
|
||||
|
||||
nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
|
||||
logger.info("nombrefichero=%s" % nombrefichero)
|
||||
logger.info("filename=%s" % nombrefichero)
|
||||
if "videobb" in url or "videozer" in url or "putlocker" in url:
|
||||
nombrefichero = title + ".flv"
|
||||
if "videobam" in url:
|
||||
nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]
|
||||
|
||||
logger.info("nombrefichero=%s" % nombrefichero)
|
||||
logger.info("filename=%s" % nombrefichero)
|
||||
|
||||
nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)
|
||||
|
||||
logger.info("nombrefichero=%s" % nombrefichero)
|
||||
logger.info("filename=%s" % nombrefichero)
|
||||
|
||||
fullpath = os.path.join(config.get_setting("downloadpath"), nombrefichero)
|
||||
logger.info("fullpath=%s" % fullpath)
|
||||
@@ -450,7 +450,7 @@ def downloadbest(video_urls, title, continuar=False):
|
||||
for elemento in invertida:
|
||||
# videotitle = elemento[0]
|
||||
url = elemento[1]
|
||||
logger.info("Descargando opción " + title + " " + url.encode('ascii', 'ignore'))
|
||||
logger.info("Downloading option " + title + " " + url.encode('ascii', 'ignore'))
|
||||
|
||||
# Calcula el fichero donde debe grabar
|
||||
try:
|
||||
@@ -476,17 +476,17 @@ def downloadbest(video_urls, title, continuar=False):
|
||||
else:
|
||||
# El fichero ni siquiera existe
|
||||
if not os.path.exists(fullpath):
|
||||
logger.info("-> No ha descargado nada, probando con la siguiente opción si existe")
|
||||
logger.info("-> You have not downloaded anything, testing with the following option if there is")
|
||||
# El fichero existe
|
||||
else:
|
||||
tamanyo = os.path.getsize(fullpath)
|
||||
|
||||
# Tiene tamaño 0
|
||||
if tamanyo == 0:
|
||||
logger.info("-> Descargado un fichero con tamaño 0, probando con la siguiente opción si existe")
|
||||
logger.info("-> Download a file with size 0, testing with the following option if it exists")
|
||||
os.remove(fullpath)
|
||||
else:
|
||||
logger.info("-> Descargado un fichero con tamaño %d, lo da por bueno" % tamanyo)
|
||||
logger.info("-> Download a file with size %d, he takes it for good" % tamanyo)
|
||||
return 0
|
||||
|
||||
return -2
|
||||
@@ -494,7 +494,7 @@ def downloadbest(video_urls, title, continuar=False):
|
||||
|
||||
def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False, resumir=True):
|
||||
logger.info("url=" + url)
|
||||
logger.info("nombrefichero=" + nombrefichero)
|
||||
logger.info("filename=" + nombrefichero)
|
||||
|
||||
if headers is None:
|
||||
headers = []
|
||||
@@ -516,7 +516,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
nombrefichero = xbmc.makeLegalFilename(nombrefichero)
|
||||
except:
|
||||
pass
|
||||
logger.info("nombrefichero=" + nombrefichero)
|
||||
logger.info("filename=" + nombrefichero)
|
||||
|
||||
# El fichero existe y se quiere continuar
|
||||
if os.path.exists(nombrefichero) and continuar:
|
||||
@@ -528,7 +528,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
f = open(nombrefichero, 'r+b')
|
||||
if resumir:
|
||||
exist_size = os.path.getsize(nombrefichero)
|
||||
logger.info("el fichero existe, size=%d" % exist_size)
|
||||
logger.info("the file exists, size=%d" % exist_size)
|
||||
grabado = exist_size
|
||||
f.seek(exist_size)
|
||||
else:
|
||||
@@ -537,13 +537,13 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
|
||||
# el fichero ya existe y no se quiere continuar, se aborta
|
||||
elif os.path.exists(nombrefichero) and not continuar:
|
||||
logger.info("el fichero existe, no se descarga de nuevo")
|
||||
logger.info("the file exists, it does not download again")
|
||||
return -3
|
||||
|
||||
# el fichero no existe
|
||||
else:
|
||||
exist_size = 0
|
||||
logger.info("el fichero no existe")
|
||||
logger.info("the file does not exist")
|
||||
|
||||
# try:
|
||||
# import xbmcvfs
|
||||
@@ -554,7 +554,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
|
||||
# Crea el diálogo de progreso
|
||||
if not silent:
|
||||
progreso = platformtools.dialog_progress("plugin", "Descargando...", url, nombrefichero)
|
||||
progreso = platformtools.dialog_progress("plugin", "Downloading...", url, nombrefichero)
|
||||
|
||||
# Si la plataforma no devuelve un cuadro de diálogo válido, asume modo silencio
|
||||
if progreso is None:
|
||||
@@ -621,7 +621,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
blocksize = 100 * 1024
|
||||
|
||||
bloqueleido = connexion.read(blocksize)
|
||||
logger.info("Iniciando descarga del fichero, bloqueleido=%s" % len(bloqueleido))
|
||||
logger.info("Starting downloading the file, blocked=%s" % len(bloqueleido))
|
||||
|
||||
maxreintentos = 10
|
||||
|
||||
@@ -659,14 +659,14 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
break
|
||||
except:
|
||||
reintentos += 1
|
||||
logger.info("ERROR en la descarga del bloque, reintento %d" % reintentos)
|
||||
logger.info("ERROR in block download, retry %d" % reintentos)
|
||||
import traceback
|
||||
logger.error(traceback.print_exc())
|
||||
|
||||
# El usuario cancelo la descarga
|
||||
try:
|
||||
if progreso.iscanceled():
|
||||
logger.info("Descarga del fichero cancelada")
|
||||
logger.info("Download of file canceled")
|
||||
f.close()
|
||||
progreso.close()
|
||||
return -1
|
||||
@@ -675,7 +675,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
|
||||
# Ha habido un error en la descarga
|
||||
if reintentos > maxreintentos:
|
||||
logger.info("ERROR en la descarga del fichero")
|
||||
logger.info("ERROR in the file download")
|
||||
f.close()
|
||||
if not silent:
|
||||
progreso.close()
|
||||
@@ -721,7 +721,7 @@ def downloadfile(url, nombrefichero, headers=None, silent=False, continuar=False
|
||||
except:
|
||||
pass
|
||||
|
||||
logger.info("Fin descarga del fichero")
|
||||
logger.info("End of file download")
|
||||
|
||||
|
||||
def downloadfileRTMP(url, nombrefichero, silent):
|
||||
@@ -783,16 +783,16 @@ def downloadfileRTMP(url, nombrefichero, silent):
|
||||
def downloadfileGzipped(url, pathfichero):
|
||||
logger.info("url=" + url)
|
||||
nombrefichero = pathfichero
|
||||
logger.info("nombrefichero=" + nombrefichero)
|
||||
logger.info("filename=" + nombrefichero)
|
||||
|
||||
import xbmc
|
||||
nombrefichero = xbmc.makeLegalFilename(nombrefichero)
|
||||
logger.info("nombrefichero=" + nombrefichero)
|
||||
logger.info("filename=" + nombrefichero)
|
||||
patron = "(http://[^/]+)/.+"
|
||||
matches = re.compile(patron, re.DOTALL).findall(url)
|
||||
|
||||
if len(matches):
|
||||
logger.info("URL principal :" + matches[0])
|
||||
logger.info("Main URL: " + matches[0])
|
||||
url1 = matches[0]
|
||||
else:
|
||||
url1 = url
|
||||
@@ -843,7 +843,7 @@ def downloadfileGzipped(url, pathfichero):
|
||||
|
||||
nombre_fichero_base = os.path.basename(nombrefichero)
|
||||
if len(nombre_fichero_base) == 0:
|
||||
logger.info("Buscando nombre en el Headers de respuesta")
|
||||
logger.info("Searching for name in the answer Headers")
|
||||
nombre_base = connexion.headers["Content-Disposition"]
|
||||
logger.info(nombre_base)
|
||||
patron = 'filename="([^"]+)"'
|
||||
@@ -853,15 +853,15 @@ def downloadfileGzipped(url, pathfichero):
|
||||
titulo = GetTitleFromFile(titulo)
|
||||
nombrefichero = os.path.join(pathfichero, titulo)
|
||||
else:
|
||||
logger.info("Nombre del fichero no encontrado, Colocando nombre temporal :sin_nombre.txt")
|
||||
titulo = "sin_nombre.txt"
|
||||
logger.info("Name of the file not found, Placing temporary name: no_name.txt")
|
||||
titulo = "no_name.txt"
|
||||
nombrefichero = os.path.join(pathfichero, titulo)
|
||||
totalfichero = int(connexion.headers["Content-Length"])
|
||||
|
||||
# despues
|
||||
f = open(nombrefichero, 'w')
|
||||
|
||||
logger.info("fichero nuevo abierto")
|
||||
logger.info("new file open")
|
||||
|
||||
grabado = 0
|
||||
logger.info("Content-Length=%s" % totalfichero)
|
||||
@@ -877,9 +877,9 @@ def downloadfileGzipped(url, pathfichero):
|
||||
gzipper = gzip.GzipFile(fileobj=compressedstream)
|
||||
bloquedata = gzipper.read()
|
||||
gzipper.close()
|
||||
logger.info("Iniciando descarga del fichero, bloqueleido=%s" % len(bloqueleido))
|
||||
logger.info("Starting downloading the file, blocked=%s" % len(bloqueleido))
|
||||
except:
|
||||
logger.error("ERROR : El archivo a descargar no esta comprimido con Gzip")
|
||||
logger.error("ERROR: The file to be downloaded is not compressed with Gzip")
|
||||
f.close()
|
||||
progreso.close()
|
||||
return -2
|
||||
@@ -922,27 +922,27 @@ def downloadfileGzipped(url, pathfichero):
|
||||
break
|
||||
except:
|
||||
reintentos += 1
|
||||
logger.info("ERROR en la descarga del bloque, reintento %d" % reintentos)
|
||||
logger.info("ERROR in block download, retry %d" % reintentos)
|
||||
for line in sys.exc_info():
|
||||
logger.error("%s" % line)
|
||||
|
||||
# El usuario cancelo la descarga
|
||||
if progreso.iscanceled():
|
||||
logger.info("Descarga del fichero cancelada")
|
||||
logger.info("Download of file canceled")
|
||||
f.close()
|
||||
progreso.close()
|
||||
return -1
|
||||
|
||||
# Ha habido un error en la descarga
|
||||
if reintentos > maxreintentos:
|
||||
logger.info("ERROR en la descarga del fichero")
|
||||
logger.info("ERROR in the file download")
|
||||
f.close()
|
||||
progreso.close()
|
||||
|
||||
return -2
|
||||
|
||||
except:
|
||||
logger.info("ERROR en la descarga del fichero")
|
||||
logger.info("ERROR in the file download")
|
||||
for line in sys.exc_info():
|
||||
logger.error("%s" % line)
|
||||
f.close()
|
||||
@@ -953,15 +953,15 @@ def downloadfileGzipped(url, pathfichero):
|
||||
|
||||
# print data
|
||||
progreso.close()
|
||||
logger.info("Fin descarga del fichero")
|
||||
logger.info("End download of the file)
|
||||
return nombrefichero
|
||||
|
||||
|
||||
def GetTitleFromFile(title):
|
||||
# Imprime en el log lo que va a descartar
|
||||
logger.info("titulo=" + title)
|
||||
logger.info("title=" + title)
|
||||
plataforma = config.get_system_platform()
|
||||
logger.info("plataforma=" + plataforma)
|
||||
logger.info("platform=" + plataforma)
|
||||
|
||||
# nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
|
||||
nombrefichero = title
|
||||
@@ -979,7 +979,7 @@ def downloadIfNotModifiedSince(url, timestamp):
|
||||
|
||||
# Convierte la fecha a GMT
|
||||
fecha_formateada = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(timestamp))
|
||||
logger.info("fechaFormateada=%s" % fecha_formateada)
|
||||
logger.info("DateFormat=%s" % fecha_formateada)
|
||||
|
||||
# Comprueba si ha cambiado
|
||||
inicio = time.clock()
|
||||
@@ -1003,9 +1003,9 @@ def downloadIfNotModifiedSince(url, timestamp):
|
||||
except urllib2.URLError, e:
|
||||
# Si devuelve 304 es que no ha cambiado
|
||||
if hasattr(e, 'code'):
|
||||
logger.info("Codigo de respuesta HTTP : %d" % e.code)
|
||||
logger.info("HTTP response code: %d" % e.code)
|
||||
if e.code == 304:
|
||||
logger.info("No ha cambiado")
|
||||
logger.info("It has not changed")
|
||||
updated = False
|
||||
# Agarra los errores con codigo de respuesta del servidor externo solicitado
|
||||
else:
|
||||
@@ -1014,7 +1014,7 @@ def downloadIfNotModifiedSince(url, timestamp):
|
||||
data = ""
|
||||
|
||||
fin = time.clock()
|
||||
logger.info("Descargado en %d segundos " % (fin - inicio + 1))
|
||||
logger.info("Downloaded in %d seconds " % (fin - inicio + 1))
|
||||
|
||||
return updated, data
|
||||
|
||||
@@ -1086,6 +1086,11 @@ def download_all_episodes(item, channel, first_episode="", preferred_server="vid
|
||||
for mirror_item in mirrors_itemlist:
|
||||
|
||||
# Si está en español va al principio, si no va al final
|
||||
if "(Italiano)" in mirror_item.title:
|
||||
if best_server in mirror_item.title.lower():
|
||||
new_mirror_itemlist_1.append(mirror_item)
|
||||
else:
|
||||
new_mirror_itemlist_2.append(mirror_item)
|
||||
if "(Español)" in mirror_item.title:
|
||||
if best_server in mirror_item.title.lower():
|
||||
new_mirror_itemlist_1.append(mirror_item)
|
||||
@@ -1112,7 +1117,9 @@ def download_all_episodes(item, channel, first_episode="", preferred_server="vid
|
||||
|
||||
for mirror_item in mirrors_itemlist:
|
||||
logger.info("mirror=" + mirror_item.title)
|
||||
|
||||
if "(Italiano)" in mirror_item.title:
|
||||
idioma = "(Italiano)"
|
||||
codigo_idioma = "it"
|
||||
if "(Español)" in mirror_item.title:
|
||||
idioma = "(Español)"
|
||||
codigo_idioma = "es"
|
||||
@@ -1177,7 +1184,7 @@ def download_all_episodes(item, channel, first_episode="", preferred_server="vid
|
||||
logger.info("downloading mirror not available... trying next")
|
||||
|
||||
if not descargado:
|
||||
logger.info("EPISODIO NO DESCARGADO " + episode_title)
|
||||
logger.info("UNDOWNLOADED EPISODE " + episode_title)
|
||||
|
||||
|
||||
def episodio_ya_descargado(show_title, episode_title):
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
"SD"
|
||||
],
|
||||
"default": 0,
|
||||
"enabled": "eq(-2,'Reordenar')",
|
||||
"enabled": "eq(-2,'@70245')",
|
||||
"visible": true
|
||||
},
|
||||
{
|
||||
@@ -167,7 +167,7 @@
|
||||
"type": "bool",
|
||||
"label": "@70242",
|
||||
"default": true,
|
||||
"enabled": "eq(-3,'Reordenar')",
|
||||
"enabled": "eq(-3,'@70245')",
|
||||
"visible": true
|
||||
}
|
||||
]
|
||||
|
||||
@@ -237,7 +237,7 @@ def menu(item):
|
||||
# -1 es cancelar
|
||||
if seleccion == -1: return
|
||||
|
||||
logger.info("opcion=%s" % (opciones[seleccion]))
|
||||
logger.info("option=%s" % (opciones[seleccion]))
|
||||
# Opcion Eliminar
|
||||
if opciones[seleccion] == op[1]:
|
||||
filetools.remove(item.path)
|
||||
@@ -407,10 +407,10 @@ def sort_method(item):
|
||||
@rtype: int
|
||||
"""
|
||||
lang_orders = {}
|
||||
lang_orders[0] = ["ES", "LAT", "SUB", "ENG", "VOSE"]
|
||||
lang_orders[1] = ["ES", "SUB", "LAT", "ENG", "VOSE"]
|
||||
lang_orders[2] = ["ENG", "SUB", "VOSE", "ESP", "LAT"]
|
||||
lang_orders[3] = ["VOSE", "ENG", "SUB", "ESP", "LAT"]
|
||||
lang_orders[0] = ["IT", "SUB", "VOSI", "ENG"]
|
||||
lang_orders[1] = ["IT", "ENG", "VOSI", "SUB"]
|
||||
lang_orders[2] = ["ENG", "SUB", "IT", "VOSI"]
|
||||
lang_orders[3] = ["ENG", "SUB", "VOSI", "IT"]
|
||||
|
||||
quality_orders = {}
|
||||
quality_orders[0] = ["BLURAY", "FULLHD", "HD", "480P", "360P", "240P"]
|
||||
@@ -419,20 +419,19 @@ def sort_method(item):
|
||||
quality_orders[3] = ["480P", "360P", "240P", "BLURAY", "FULLHD", "HD"]
|
||||
|
||||
order_list_idiomas = lang_orders[int(config.get_setting("language", "downloads"))]
|
||||
match_list_idimas = {"ES": ["CAST", "ESP", "Castellano", "Español", "Audio Español"],
|
||||
"LAT": ["LAT", "Latino"],
|
||||
"SUB": ["Subtitulo Español", "Subtitulado", "SUB"],
|
||||
match_list_idimas = {"IT": ["ITA", "IT", "Italiano", "italiano", "ITALIANO"],
|
||||
"SUB": ["Sottotitolato", "SUB", "sub-ita", "SUB-ITA", "Sub-ITA", "Sub-Ita"],
|
||||
"ENG": ["EN", "ENG", "Inglés", "Ingles", "English"],
|
||||
"VOSE": ["VOSE"]}
|
||||
"VOSI": ["VOSI"]}
|
||||
|
||||
order_list_calidad = ["BLURAY", "FULLHD", "HD", "480P", "360P", "240P"]
|
||||
order_list_calidad = quality_orders[int(config.get_setting("quality", "downloads"))]
|
||||
match_list_calidad = {"BLURAY": ["BR", "BLURAY"],
|
||||
"FULLHD": ["FULLHD", "FULL HD", "1080", "HD1080", "HD 1080"],
|
||||
"HD": ["HD", "HD REAL", "HD 720", "720", "HDTV"],
|
||||
"480P": ["SD", "480P"],
|
||||
"360P": ["360P"],
|
||||
"240P": ["240P"]}
|
||||
"FULLHD": ["FULLHD", "FULL HD", "1080", "HD1080", "HD 1080", "1080p"],
|
||||
"HD": ["HD", "HD REAL", "HD 720", "720", "HDTV", "720p"],
|
||||
"480P": ["SD", "480P", '480'],
|
||||
"360P": ["360P", "360"],
|
||||
"240P": ["240P", "240"]}
|
||||
|
||||
value = (get_match_list(item.title, match_list_idimas, order_list_idiomas, ignorecase=True, only_ascii=True).index, \
|
||||
get_match_list(item.title, match_list_calidad, order_list_calidad, ignorecase=True, only_ascii=True).index)
|
||||
@@ -444,7 +443,7 @@ def sort_method(item):
|
||||
|
||||
|
||||
def download_from_url(url, item):
|
||||
logger.info("Intentando descargar: %s" % (url))
|
||||
logger.info("Attempting to download: %s" % (url))
|
||||
if url.lower().endswith(".m3u8") or url.lower().startswith("rtmp"):
|
||||
save_server_statistics(item.server, 0, False)
|
||||
return {"downloadStatus": STATUS_CODES.error}
|
||||
@@ -470,17 +469,17 @@ def download_from_url(url, item):
|
||||
# Descarga detenida. Obtenemos el estado:
|
||||
# Se ha producido un error en la descarga
|
||||
if d.state == d.states.error:
|
||||
logger.info("Error al intentar descargar %s" % (url))
|
||||
logger.info("Error trying to download %s" % (url))
|
||||
status = STATUS_CODES.error
|
||||
|
||||
# La descarga se ha detenifdo
|
||||
elif d.state == d.states.stopped:
|
||||
logger.info("Descarga detenida")
|
||||
logger.info("Stop download")
|
||||
status = STATUS_CODES.canceled
|
||||
|
||||
# La descarga ha finalizado
|
||||
elif d.state == d.states.completed:
|
||||
logger.info("Descargado correctamente")
|
||||
logger.info("Downloaded correctly")
|
||||
status = STATUS_CODES.completed
|
||||
|
||||
if item.downloadSize and item.downloadSize != d.size[0]:
|
||||
@@ -510,7 +509,7 @@ def download_from_server(item):
|
||||
try:
|
||||
itemlist = getattr(channel, "play")(item.clone(channel=item.contentChannel, action=item.contentAction))
|
||||
except:
|
||||
logger.error("Error en el canal %s" % item.contentChannel)
|
||||
logger.error("Error in the channel %s" % item.contentChannel)
|
||||
else:
|
||||
if len(itemlist) and isinstance(itemlist[0], Item):
|
||||
download_item = item.clone(**itemlist[0].__dict__)
|
||||
@@ -521,14 +520,14 @@ def download_from_server(item):
|
||||
item.video_urls = itemlist
|
||||
if not item.server: item.server = "directo"
|
||||
else:
|
||||
logger.info("No hay nada que reproducir")
|
||||
logger.info("There is nothing to reproduce")
|
||||
return {"downloadStatus": STATUS_CODES.error}
|
||||
progreso.close()
|
||||
logger.info("contentAction: %s | contentChannel: %s | server: %s | url: %s" % (
|
||||
item.contentAction, item.contentChannel, item.server, item.url))
|
||||
|
||||
if not item.server or not item.url or not item.contentAction == "play" or item.server in unsupported_servers:
|
||||
logger.error("El Item no contiene los parametros necesarios.")
|
||||
logger.error("The Item does not contain the necessary parameters.")
|
||||
return {"downloadStatus": STATUS_CODES.error}
|
||||
|
||||
if not item.video_urls:
|
||||
@@ -539,11 +538,11 @@ def download_from_server(item):
|
||||
|
||||
# Si no esta disponible, salimos
|
||||
if not puedes:
|
||||
logger.info("El vídeo **NO** está disponible")
|
||||
logger.info("The video is NOT available")
|
||||
return {"downloadStatus": STATUS_CODES.error}
|
||||
|
||||
else:
|
||||
logger.info("El vídeo **SI** está disponible")
|
||||
logger.info("YES Video is available")
|
||||
|
||||
result = {}
|
||||
|
||||
@@ -723,7 +722,7 @@ def get_episodes(item):
|
||||
itemlist.append(episode)
|
||||
# Cualquier otro resultado no nos vale, lo ignoramos
|
||||
else:
|
||||
logger.info("Omitiendo item no válido: %s" % episode.tostring())
|
||||
logger.info("Omitting invalid item: %s" % episode.tostring())
|
||||
|
||||
return itemlist
|
||||
|
||||
|
||||
Reference in New Issue
Block a user