From bfd30bb6b16f5fcbfff6572b5ee37d2532ccdc54 Mon Sep 17 00:00:00 2001 From: pipcat Date: Tue, 3 Apr 2018 11:23:05 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adidas=20funciones=20para=20comprobar=20?= =?UTF-8?q?links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Una función principal: check_list_links y un par de funciones auxiliares: check_video_link, get_url_play. Para los canales dónde se quiera implementar la verificación de enlaces, llamar a check_list_links después de obtener la lista de enlaces itemlist, en la función findvideos del canal. --- plugin.video.alfa/core/servertools.py | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/plugin.video.alfa/core/servertools.py b/plugin.video.alfa/core/servertools.py index da799696..c59ad44a 100644 --- a/plugin.video.alfa/core/servertools.py +++ b/plugin.video.alfa/core/servertools.py @@ -705,3 +705,54 @@ def filter_servers(servers_list): servers_list = servers_list_filter return servers_list + +def check_list_links(itemlist): + """ + Comprueba una lista de enlaces a videos y la devuelve modificando el titulo con la verificacion. + """ + for it in itemlist: + if it.server != '' and it.url != '': + verificacion = check_video_link(it.url, it.server) + it.title = verificacion + ', ' + it.title.strip() + return itemlist + +def check_video_link(url, server): + """ + Comprueba si el enlace a un video es valido y devuelve un string de 2 posiciones con la verificacion. + :param url, server: Link y servidor + :return: str(2) '??':No se ha podido comprobar. 'Ok':Parece que el link funciona. 'NO':Parece que no funciona. + """ + try: + server = server.lower() + server_module = __import__('servers.%s' % server, None, None, ["servers.%s" % server]) + except: + server_module = None + logger.info("[check_video_link] No se puede importar el servidor! %s" % server) + return "??" + + if hasattr(server_module, 'test_video_exists'): + try: + urlcheck = url if server == 'netutv' else get_url_play(url, server) + video_exists, message = server_module.test_video_exists(page_url=urlcheck) + if not video_exists: + logger.info("[check_video_link] No existe! %s %s %s" % (message, server, url)) + return "NO" + else: + logger.info("[check_video_link] comprovacion OK %s %s" % (server, url)) + return "Ok" + except: + logger.info("[check_video_link] No se puede comprobar ahora! %s %s" % (server, url)) + return "??" + + logger.info("[check_video_link] No hay test_video_exists para servidor: %s" % server) + return "??" + +def get_url_play(url, server): + """ + Obtener url que sirva para comprobar si el video existe + """ + url = url.replace("http://miracine.tv/n/?etu=", "http://hqq.tv/player/embed_player.php?vid=") + url = url.replace("streamcloud.eu/embed-", "streamcloud.eu/") + enlaces = findvideosbyserver(url, server)[0] + + return enlaces[1]