diff --git a/channels/altadefinizione.py b/channels/altadefinizione.py index 427db2c3..8b38fc68 100644 --- a/channels/altadefinizione.py +++ b/channels/altadefinizione.py @@ -4,8 +4,9 @@ # ------------------------------------------------------------ -from core import httptools, support +from core import httptools, support, tmdb, scrapertools from platformcode import config, logger +import re def findhost(url): host = support.match(url, patron=r']+>.*?)".*?alt="(?P.*?)".*?<a href="(?P<url>.*?)"']).matches: - itemlist.append(item.clone(action='peliculas', thumbnail = it[0].replace(' ','%20'), title = it[1], url= host + it[2])) - - for it in support.match(item, patron=['buttonn button2"><a href="(?P<url>.*?)"><img src="(?P<thumb>.*?)".*?>(?P<title>.*?)(>|<)']).matches: - itemlist.append(item.clone(action='peliculas', thumbnail = it[1].replace(' ','%20'), title = it[2], url = host + it[0])) - - return itemlist - @support.scrape def genres(item): action = 'peliculas' blacklist = ['Scegli il Genere', 'Film', 'Serie Tv', 'Sub-Ita', 'Anime', "Non reperibile", 'Anime Sub-ITA', 'Prossimamente',] - patronBlock = r'(?<=<ul class="listSubCat" id="Film">)(?P<block>.*?)(?=<\/ul>)' - patron = r'<a href=\"(?P<url>https:\/\/.*?)\"> (?P<title>.*?) </a>' + wantSaga = True if item.args == 'saghe' else False + patronBlock = r'<div class=\"categories-buttons-container\"(?P<block>.*?)</div>' + if not wantSaga: # se non richiedo le sage carico le icone in automatico + patronMenu = r'<a href=\"(?P<url>https:\/\/.*?)\".*?>(?P<title>.*?)</a>' + else: # mantengo l'icona del padre + patron = r'<a href=\"(?P<url>https:\/\/.*?)\".*?>(?P<title>.*?)</a>' + def itemlistHook(itemlist): itl = [] for item in itemlist: + isSaga = item.fulltitle.startswith('Saga') + if len(item.fulltitle) != 3: - itl.append(item) + if (isSaga and wantSaga) or (not isSaga and not wantSaga): + itl.append(item) return itl return locals() def search(item, text): - logger.debug(text) item.url = "{}/?{}".format(host, support.urlencode({'s': text})) item.args = 'search' @@ -77,31 +68,76 @@ def search(item, text): logger.error("search except: %s" % line) return [] - -@support.scrape def peliculas(item): - item.contentType = "undefined" - action = 'check' - patron = r'<h2 class=\"titleFilm\"><a href=\"(?P<url>[^\"]+)\">(?P<title>[^<[(]+)\s*\(?(?P<lang>[a-zA-Z-]*)\)?\s*\[?(?P<quality>[a-zA-Z]*)\]?\s*\(?(?P<year>[0-9]*)\)?' + data = httptools.downloadpage(item.url).data - if item.args == 'search': - patron = r'<div class="col-lg-3 col-md-3 [^>]*> <a href=\"(?P<url>[^\"]+)\">.*?(?=<h5).*?(?=>)>(?P<title>[^<[(]+)\s*\(?(?P<lang>[a-zA-Z-]*)\)?\s*\[?(?P<quality>[a-zA-Z]*)\]?\s*\(?(?P<year>[0-9]*)\)?' - patronNext = r'href="([^"]+)[^>]+>Successivo' - return locals() + if not item.nextpage: + item.page = 1 + else: + item.page = item.nextpage + itemlist = [] + for it in support.match(data, patron=[r'<article class=\"elementor-post.*?<img .*?src=\"(?P<thumb>[^\"]+).*?<h1 class=\"elementor-post__title\".*?<a href=\"(?P<url>[^\"]+)\" >\s*(?P<title>[^<]+?)\s*(\((?P<lang>Sub-[a-zA-Z]+)*\))?\s*(\[(?P<quality>[A-Z]*)\])?\s*(\((?P<year>[0-9]{4})\))?\s+<']).matches: + infoLabels = dict() + infoLabels['fanart'] = it[0] + infoLabels['title'] = support.cleantitle(it[2]) + infoLabels['mediatype'] = 'undefined' + infoLabels['year'] = it[8] + itemlist.append(item.clone(contentType = 'undefined', + action='check', + thumbnail = item.thumbnail, + fulltitle = support.cleantitle(it[2]), + title = support.format_longtitle(support.cleantitle(it[2]), quality = it[6], lang = it[4]), + url = it[1], + infoLabels = infoLabels) + ) + + tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True) + + if not item.args == 'search' and not len(itemlist) < 10: # pagination not works + if not item.parent_url: + item.parent_url = item.url + + item.nextpage = item.page + 1 + item.url = "{}/page/{}".format(item.parent_url, item.nextpage) + + resp = httptools.downloadpage(item.url, only_headers = True) + if (resp.code < 399): # no more elements + support.nextPage(itemlist = itemlist, item = item, next_page=item.url) + + return itemlist -@support.scrape def episodios(item): item.quality = '' data = item.data - action='findvideos' - patron = r'<div class="episode-wrap".*?(?=<li class="season-no">).*?(?=>)>(?P<episode>[^<]+).*?(?=<a)<a href="(?P<url>[^\"]+).*?(?=>)>(?P<title>[^<[(]+)' - return locals() + itemlist = [] + + for it in support.match(data, patron=[r'div class=\"single-season.*?(?P<id>season_[0-9]+).*?>Stagione:\s(?P<season>[0-9]+).*?</div']).matches: + logger.debug(it) + block = support.match(data, patron = r'div id=\"season_0\".*?</div').match + for ep in support.match(block, patron=[r'<li><a href=\"(?P<url>[^\"]+).*?img\" src=\"(?P<thumb>[^\"]+).*?title\">(?P<episode>[0-9]+)\.\s+(?P<title>.*?)</span>']).matches: + logger.debug(ep) + infoLabels = dict() + infoLabels['tvshowtitle'] = support.cleantitle(item.fulltitle) + infoLabels['season'] = int(it[1]) + infoLabels['episode'] = int(ep[2]) + infoLabels['episodeName'] = support.cleantitle(ep[3]) + itemlist.append(item.clone(contentType = 'tvshow', + action='findvideos', + thumb = ep[1], + title = support.format_longtitle(support.cleantitle(ep[3]), season = it[1], episode = ep[2]), + url = ep[0], + infoLabels = infoLabels) + ) + + tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True) + + return itemlist def check(item): item.data = httptools.downloadpage(item.url).data - if 'stagione' in item.data.lower(): + if 'season-details' in item.data.lower(): item.contentType = 'tvshow' return episodios(item) else: @@ -112,7 +148,8 @@ def findvideos(item): video_url = item.url if item.contentType == 'movie': - video_url = support.match(item, patron=r'<div class="embed-player" data-id=\"(https://.*?)\"').match + video_url = support.match(item, patron=[r'<div class="video-wrapper">.*?<iframe src=\"(https://.*?)\"', + r'window.open\(\'([^\']+).*?_blank']).match itemlist = [item.clone(action="play", url=srv) for srv in support.match(video_url, patron='<div class="megaButton" meta-type="v" meta-link="([^"]+).*?(?=>)>').matches] itemlist = support.server(item,itemlist=itemlist) diff --git a/core/support.py b/core/support.py index 4b104599..95200207 100644 --- a/core/support.py +++ b/core/support.py @@ -215,6 +215,16 @@ def cleantitle(title): cleantitle = title.replace('"', "'").replace('×', 'x').replace('–', '-').strip().strip('-').strip() return cleantitle +def format_longtitle(title, season = None, episode = None, quality = None, lang = None): + if season and episode: + longtitle = season + 'x' + episode.zfill(2) + ' ' + title + else: + longtitle = title + longtitle = typo(longtitle, 'bold') + longtitle += typo(lang, '_ [] color kod') if lang else '' + longtitle += typo(quality, '_ [] color kod') if quality else '' + + return longtitle def unifyEp(ep): # ep = re.sub(r'\s-\s|-|–|×|×', 'x', scraped['episode']) @@ -1676,4 +1686,4 @@ def callAds(url, host): requests.get(url, headers=headers) Thread(target=requests.get, args=(url, headers)).start() except: - pass \ No newline at end of file + pass