From 7ab66fbb8aca38e417cde7eac38f919285aa8f03 Mon Sep 17 00:00:00 2001 From: marco <10120390+mac12m99@users.noreply.github.com> Date: Wed, 4 May 2022 19:57:21 +0200 Subject: [PATCH] Fix alternativo a redirect --- channels.json | 2 +- channels/streamingcommunity.py | 18 ++++++++---------- core/httptools.py | 8 +++++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/channels.json b/channels.json index b25f044f..af74aeca 100644 --- a/channels.json +++ b/channels.json @@ -32,7 +32,7 @@ "raiplay": "https://www.raiplay.it", "serietvu": "https://www.serietvu.live", "streamingcommunity": "https://streamingcommunity.top", - "streamingita": "https://eurostreaming.vote", + "streamingita": "https://www.streamingita.life", "streamtime": "https://t.me/s/StreamTime", "tantifilm": "https://www.tantifilm.zone", "toonitalia": "https://toonitalia.co", diff --git a/channels/streamingcommunity.py b/channels/streamingcommunity.py index feac1f13..b1f2972d 100644 --- a/channels/streamingcommunity.py +++ b/channels/streamingcommunity.py @@ -17,8 +17,6 @@ else: host = support.config.get_channel_url() -session = requests.Session() -session.request = functools.partial(session.request, timeout=httptools.HTTPTOOLS_DEFAULT_DOWNLOAD_TIMEOUT) headers = {} @@ -28,10 +26,10 @@ def getHeaders(forced=False): if not headers: # try: headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'} - response = session.get(host, headers=headers) + response = httptools.downloadpage(host, headers=headers) # if not response.url.startswith(host): # host = support.config.get_channel_url(findhost, forceFindhost=True) - csrf_token = support.match(response.text, patron='name="csrf-token" content="([^"]+)"').match + csrf_token = support.match(response.data, patron='name="csrf-token" content="([^"]+)"').match headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14', 'content-type': 'application/json;charset=UTF-8', 'Referer': host, @@ -92,10 +90,10 @@ def newest(category): item.args = 1 item.newest = True if category == 'peliculas': - item.contentType == 'movie' + item.contentType = 'movie' item.url = host + '/film' else: - item.contentType == 'tvshow' + item.contentType = 'tvshow' item.url = host + '/serie-tv' try: @@ -133,10 +131,10 @@ def peliculas(item): records = json.loads(support.match(data, patron=r'slider-title titles-json="(.*?)"\s*slider-name="').matches[item.args]) elif not item.search: payload = json.dumps({'type': videoType, 'offset':offset, 'genre':item.args}) - records = session.post(host + '/api/browse', headers=headers, data=payload).json()['records'] + records = httptools.downloadpage(host + '/api/browse', headers=headers, post=payload).json['records'] else: payload = json.dumps({'q': item.search}) - records = session.post(host + '/api/search', headers=headers, data=payload).json()['records'] + records = httptools.downloadpage(host + '/api/search', headers=headers, post=payload).json['records'] if records and type(records[0]) == list: @@ -171,8 +169,8 @@ def peliculas(item): return itemlist def makeItem(n, it, item): - info = session.post(host + '/api/titles/preview/{}'.format(it['id']), headers=headers).json() - logger.debug(jsontools.dump(it)) + info = httptools.downloadpage(host + '/api/titles/preview/{}'.format(it['id']), headers=headers, post={}).json + logger.debug(it) title = info['name'] lang = 'Sub-ITA' if 'sub-ita' in title.lower() else 'ITA' title = support.cleantitle(re.sub('\[|\]|[Ss][Uu][Bb]-[Ii][Tt][Aa]', '', title)) diff --git a/core/httptools.py b/core/httptools.py index 73293d29..807dda0a 100755 --- a/core/httptools.py +++ b/core/httptools.py @@ -375,8 +375,14 @@ def downloadpage(url, **opt): timeout=opt['timeout']) else: # Makes the request with POST method - req = session.post(url, data=payload, allow_redirects=opt.get('follow_redirects', True), + req = session.post(url, data=payload, allow_redirects=False, files=files, timeout=opt['timeout']) + # Make sure it follows redirects + i = 10 + while opt.get('follow_redirects', True) and i > 0 and req.status_code == 301: + req = session.post(req.headers['Location'], data=payload, allow_redirects=False, + files=files, timeout=opt['timeout']) + i -= 1 elif opt.get('only_headers', False): info_dict = fill_fields_pre(url, opt, proxy_data, file_name)