'
- next_page = scrapertools.find_single_match(data, patron)
- if next_page != "":
- item.url = next_page
- itemlist = episodios(item, itemlist)
- else:
- item.url = item.originalUrl
- support.videolibrary(itemlist, item, 'bold color kod')
-
- return itemlist
-
-
-# ================================================================================================================
-
-# ----------------------------------------------------------------------------------------------------------------
-def peliculas_tv(item):
- log()
- itemlist = []
-
- patron = '
\s*
'
-
- matches, data = support.match(item, patron, headers=headers)
-
- for scrapedurl, scrapedtitle in matches:
- if scrapedtitle in ["FACEBOOK", "RAPIDGATOR", "WELCOME!"]:
- continue
-
- scrapedthumbnail = ""
- scrapedplot = ""
- scrapedtitle = cleantitle(scrapedtitle)
- infoLabels = {}
- episode = scrapertools.find_multiple_matches(scrapedtitle, r'((\d*)x(\d*))')
- if episode: # workaround per quando mettono le serie intere o altra roba, sarebbero da intercettare TODO
- episode = episode[0]
- title = scrapedtitle.split(" S0")[0].strip()
- title = title.split(" S1")[0].strip()
- title = title.split(" S2")[0].strip()
-
- infoLabels['season'] = episode[1]
- infoLabels['episode'] = episode[2].zfill(2)
-
- itemlist.append(
- Item(channel=item.channel,
- action="findvideos",
- fulltitle=scrapedtitle,
- show=scrapedtitle,
- title=title + " - " + episode[0] + " " + support.typo("Sub-ITA", '_ [] color kod'),
- url=scrapedurl,
- thumbnail=scrapedthumbnail,
- contentSerieName=title,
- contentLanguage='Sub-ITA',
- plot=scrapedplot,
- infoLabels=infoLabels,
- folder=True))
-
- tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True)
-
- # Paginazione
- patron = r'
\d+\s
\d+'
- support.nextPage(itemlist, item, data, patron)
-
- return itemlist
-
-
-# ================================================================================================================
-
-
-# ----------------------------------------------------------------------------------------------------------------
-def newest(categoria):
- log(categoria)
- itemlist = []
- item = Item()
- item.url = host
- item.extra = 'serie'
- try:
- if categoria == "series":
- itemlist = peliculas_tv(item)
-
- except:
- import sys
- for line in sys.exc_info():
- logger.error("{0}".format(line))
- return []
-
- return itemlist
-
-
-# ================================================================================================================
-
-# ----------------------------------------------------------------------------------------------------------------
-def search(item, texto):
- log(texto)
- itemlist = []
-
- patron = '
([^<]+)'
- matches = support.match(item, patron, headers=headers)[0]
-
- for i, (scrapedurl, scrapedtitle) in enumerate(matches):
- if texto.upper() in scrapedtitle.upper():
- scrapedthumbnail = ""
- scrapedplot = ""
- title = cleantitle(scrapedtitle)
- itemlist.append(
- Item(channel=item.channel,
- extra=item.extra,
- action="episodios",
- title=title,
- url=scrapedurl,
- thumbnail=scrapedthumbnail,
- fulltitle=title,
- show=title,
- plot=scrapedplot,
- contentType='episode',
- originalUrl=scrapedurl,
- folder=True))
- tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True)
-
- return itemlist
-
-
-# ================================================================================================================
-
-# ----------------------------------------------------------------------------------------------------------------
-
-
-def list_az(item):
- log()
- itemlist = []
-
- alphabet = dict()
- patron = '([^<]+)'
- matches = support.match(item, patron, headers=headers)[0]
-
- for i, (scrapedurl, scrapedtitle) in enumerate(matches):
- letter = scrapedtitle[0].upper()
- if letter not in alphabet:
- alphabet[letter] = []
- alphabet[letter].append(scrapedurl + '||' + scrapedtitle)
-
- for letter in sorted(alphabet):
- itemlist.append(
- Item(channel=item.channel,
- action="lista_serie",
- url='\n\n'.join(alphabet[letter]),
- title=letter,
- fulltitle=letter))
-
- return itemlist
-
-# ================================================================================================================
diff --git a/channelselector.py b/channelselector.py
index dfc099b7..72443fa7 100644
--- a/channelselector.py
+++ b/channelselector.py
@@ -19,11 +19,9 @@ def getmainlist(view="thumb_"):
################################################################
################################################################
# Questa voce è per TESTING e NON DOVRà MAI andare in stable
-## itemlist.append(Item(title="KDICC", channel="checkhost", action="check",
-## thumbnail='',
-## category=config.get_localized_string(30119), viewmode="thumbnails",
-## context=[{"title": config.get_localized_string(70285), "channel": "checkhost", "action": "menu_opciones",
-## "goto": True}]))
+ itemlist.append(Item(title="Redirect", channel="checkhost", action="check_channels",
+ thumbnail='',
+ category=config.get_localized_string(30119), viewmode="thumbnails"))
################################################################
################################################################
# Añade los canales que forman el menú principal
diff --git a/platformcode/launcher.py b/platformcode/launcher.py
index 9107cdd9..8ca1ec6f 100644
--- a/platformcode/launcher.py
+++ b/platformcode/launcher.py
@@ -34,11 +34,16 @@ def start():
# se lo ha: non lo fa entrare nell'addon
# se ha problemi di DNS avvia ma lascia entrare
# se tutto ok: entra nell'addon
- from specials.checkhost import test_conn
- test_conn(is_exit = True, check_dns = True, view_msg = True,
+ from specials.checkhost import test_conn, check_channels
+ check_adsl = test_conn(is_exit = True, check_dns = True, view_msg = True,
lst_urls = [], lst_site_check_dns = [], in_addon = True)
-
+ # Permette di scrivere il file channels.json
+ # controllando gli url del file solo se tutti i check
+ # della connessione sono andati a buon fine
+## if check_adsl:
+## check_channels()
+
def run(item=None):
logger.info()
if not item:
diff --git a/specials/checkhost.py b/specials/checkhost.py
index dd6432b3..aa2ca959 100644
--- a/specials/checkhost.py
+++ b/specials/checkhost.py
@@ -5,6 +5,8 @@ import json
from platformcode import config, logger
import requests
from requests.exceptions import HTTPError
+import httplib2
+import socket
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
@@ -19,7 +21,7 @@ LST_SITE_CHCK_DNS = ['https://www.italia-film.pw', 'https://casacinema.space',
class Kdicc():
-
+
def __init__(self, is_exit = True, check_dns = True, view_msg = True,
lst_urls = [], lst_site_check_dns = [], in_addon = False):
@@ -60,7 +62,7 @@ class Kdicc():
"""
controllo se il device raggiunge i siti
"""
-
+
urls = LIST_SITE
r = self.rqst(urls)
http_errr = 0
@@ -104,10 +106,10 @@ class Kdicc():
return : (esito, sito, url, code, reurl)
"""
rslt_final = []
-
+
if lst_urls == []:
lst_urls = self.lst_urls
-
+
for sito in lst_urls:
rslt = {}
try:
@@ -125,7 +127,7 @@ class Kdicc():
rslt['isRedirect'] = is_redirect
rslt['history'] = r.history
xbmc.log("Risultato nel try: %s" % (r,), level=xbmc.LOGNOTICE)
-
+
except requests.exceptions.ConnectionError as conn_errr:
# Errno 10061 per s.o. win
# gli Errno 10xxx e 11xxx saranno da compattare in qualche modo?
@@ -135,7 +137,6 @@ class Kdicc():
or 'ConnectTimeoutError' in str(conn_errr) \
or 'Errno 11002' in str(conn_errr) or 'ReadTimeout' in str(conn_errr) \
or 'Errno 11001' in str(conn_errr): # questo errore è anche nel code: -2
- # nei casi in cui vogliamo raggiungere certi siti...
rslt['code'] = '111'
rslt['url'] = str(sito)
rslt['http_err'] = 'Connection refused'
@@ -148,6 +149,30 @@ class Kdicc():
return rslt_final
+ def http_Resp(self):
+ rslt = {}
+ for sito in self.lst_urls:
+ try:
+ s = httplib2.Http()
+ code, resp = s.request(sito, body=None)
+ if code.previous:
+ xbmc.log("r1 http_Resp: %s %s %s %s" %
+ (code.status, code.reason, code.previous['status'],
+ code.previous['-x-permanent-redirect-url']), level=xbmc.LOGNOTICE)
+ rslt['code'] = code.previous['status']
+ rslt['redirect'] = code.previous['-x-permanent-redirect-url']
+ rslt['status'] = code.status
+ else:
+ rslt['code'] = code.status
+ except httplib2.ServerNotFoundError as msg:
+ # sia per mancanza di ADSL che per i siti non esistenti
+ rslt['code'] = -2
+ except socket.error as msg:
+ # per siti irraggiungibili senza DNS corretti
+ #[Errno 111] Connection refused
+ rslt['code'] = 111
+ return rslt
+
def view_Advise(self, txt = '' ):
"""
Avviso per utente
@@ -174,50 +199,34 @@ def test_conn(is_exit, check_dns, view_msg,
ktest = Kdicc(is_exit, check_dns, view_msg, lst_urls, lst_site_check_dns, in_addon)
# se non ha l'ip lo comunico all'utente
- # è utile nelle richieste di aiuto per l'addon che non funziona
- # If you don't have an ip, I'll let you know.
- # Is useful in requests for help for the addon that does not work
- risultato = []
-
if not ktest.check_Ip():
# non permetto di entrare nell'addon
# I don't let you get into the addon
# inserire codice lingua
if view_msg == True:
- # inserire codice lingua
ktest.view_Advise(config.get_localized_string(70720))
if ktest.is_exit == True:
exit()
-
+ # se non ha connessione ADSL lo comunico all'utente
elif not ktest.check_Adsl():
if view_msg == True:
- # inserire codice lingua
ktest.view_Advise(config.get_localized_string(70721))
if ktest.is_exit == True:
exit()
-
+ # se ha i DNS filtrati lo comunico all'utente
elif ktest.check_dns:
if not ktest.check_Dns():
if view_msg == True:
- # inserire codice lingua
ktest.view_Advise(config.get_localized_string(70722))
-## if ktest.is_exit == True:
-## exit()
-## else:
- # Lasciando solo else al posto dell'if sotto, l'else non viene considerato!
-## if ktest.check_Ip() and ktest.check_Adsl() and ktest.check_Dns():
-## # tutto ok! entro nell'addon
-## if view_msg == True and in_addon == False:
-## ktest.view_Advise('Configurazione rete OK!\n')
-
-## for ris in ktest.rqst(lst_urls):
-## risultato.append(ris)
-
- return risultato
+ if ktest.check_Ip() and ktest.check_Adsl() and ktest.check_Dns():
+ return True
+ else:
+ return False
# def per la creazione del file channels.json
-"""
+def check_channels(inutile=''):
+ """
leggo gli host dei canali dal file channels.json
li controllo
scrivo il file channels-test.json
@@ -232,8 +241,7 @@ def test_conn(is_exit, check_dns, view_msg,
Nel caso accada un problema, il controllo e relativa scrittura del file viene interrotto
con messaggio di avvertimento
-"""
-def check(item):
+ """
logger.info()
folderJson = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('path')).decode('utf-8')
@@ -241,36 +249,41 @@ def check(item):
with open(folderJson+'/'+fileJson) as f:
data = json.load(f)
-## logger.info("DATA :%s" % data)
risultato = {}
-
+
for chann, host in sorted(data.items()):
+
ris = []
+ # per avere un'idea della tempistica
+ # utile solo se si controllano tutti i canali
+ # per i canali con error 522 si perdono circa 40 sec...
logger.info("check #### INIZIO #### channel - host :%s - %s " % (chann, host))
- #lst_host = []
- #lst_host.append(host)
- lst_host = [host]
+ rslt = Kdicc(lst_urls = [host]).http_Resp()
- rslt = test_conn(is_exit = True, check_dns = False, view_msg = True,
- lst_urls = lst_host, lst_site_check_dns = [], in_addon = True)
-
- logger.info("check #### FINE #### rslt :%s " % (rslt))
- rslt = rslt[0]
# tutto ok
- if rslt['code'] == 200 and rslt['isRedirect'] == False:
+ if rslt['code'] == 200:
risultato[chann] = host
# redirect
- elif rslt['code'] == 200 and rslt['isRedirect'] == True:
- risultato[chann] = str(rslt['code']) +' - '+ rslt['rdrcturl']
+ elif str(rslt['code']).startswith('3'):
+ #risultato[chann] = str(rslt['code']) +' - '+ rslt['redirect'][:-1]
+ if rslt['redirect'].endswith('/'):
+ rslt['redirect'] = rslt['redirect'][:-1]
+ risultato[chann] = rslt['redirect']
# sito inesistente
elif rslt['code'] == -2:
risultato[chann] = 'Host Sconosciuto - '+ str(rslt['code']) +' - '+ host
+ # sito non raggiungibile - probabili dns non settati
+ elif rslt['code'] == 111:
+ risultato[chann] = ['Host non raggiungibile - '+ str(rslt['code']) +' - '+ host]
else:
# altri tipi di errore
- risultato[chann] = 'Errore Sconosciuto - '+str(rslt['code']) +' - '+ host
+ #risultato[chann] = 'Errore Sconosciuto - '+str(rslt['code']) +' - '+ host
+ risultato[chann] = host
+ logger.info("check #### FINE #### rslt :%s " % (rslt))
+
fileJson_test = 'channels-test.json'
# scrivo il file aggiornato
with open(folderJson+'/'+fileJson_test, 'w') as f: