diff --git a/Src/Api/film.py b/Src/Api/film.py index f9a022c..8f43f47 100644 --- a/Src/Api/film.py +++ b/Src/Api/film.py @@ -3,21 +3,26 @@ # Class import from Src.Util.Helper.headers import get_headers from Src.Util.Helper.util import convert_utf8_name +from Src.Util.Helper.console import console from Src.Util.m3u8 import dw_m3u8 # General import -import requests, os, re, json +import requests, os, re, json, sys from bs4 import BeautifulSoup # [func] def get_iframe(id_title, domain): - req_iframe = requests.get(url = f"https://streamingcommunity.{domain}/iframe/{id_title}", headers = { + req = requests.get(url = f"https://streamingcommunity.{domain}/iframe/{id_title}", headers = { "User-agent": get_headers() }) - url_embed = BeautifulSoup(req_iframe.text, "lxml").find("iframe").get("src") - req_embed = requests.get(url_embed, headers = {"User-agent": get_headers()}).text - return BeautifulSoup(req_embed, "lxml").find("body").find("script").text + if req.ok: + url_embed = BeautifulSoup(req.text, "lxml").find("iframe").get("src") + req_embed = requests.get(url_embed, headers = {"User-agent": get_headers()}).text + return BeautifulSoup(req_embed, "lxml").find("body").find("script").text + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def parse_content(embed_content): @@ -35,12 +40,16 @@ def get_m3u8_url(json_win_video, json_win_param): return f"https://vixcloud.co/playlist/{json_win_video['id']}?type=video&rendition=720p&token={json_win_param['token720p']}&expires={json_win_param['expires']}" def get_m3u8_key(json_win_video, json_win_param, title_name): - req_key = requests.get('https://vixcloud.co/storage/enc.key', headers={ + req = requests.get('https://vixcloud.co/storage/enc.key', headers={ 'referer': f'https://vixcloud.co/embed/{json_win_video["id"]}?token={json_win_param["token720p"]}&title={title_name.replace(" ", "+")}&referer=1&expires={json_win_param["expires"]}', - }).content - - return "".join(["{:02x}".format(c) for c in req_key]) + }) + if req.ok: + return "".join(["{:02x}".format(c) for c in req.content]) + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) + def main_dw_film(id_film, title_name, domain): lower_title_name = str(title_name).lower() diff --git a/Src/Api/page.py b/Src/Api/page.py index 2b0a235..0eeed5d 100644 --- a/Src/Api/page.py +++ b/Src/Api/page.py @@ -28,9 +28,13 @@ def get_version(domain): def search(title_search, domain): title_search = str(title_search).replace(" ", "+") - r = requests.get( + req = requests.get( url = f"https://streamingcommunity.{domain}/api/search?q={title_search}", headers = {"User-agent": get_headers()} ) - return [{'name': title['name'], 'type': title['type'], 'id': title['id']} for title in r.json()['data']] + if req.ok: + return [{'name': title['name'], 'type': title['type'], 'id': title['id']} for title in req.json()['data']] + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) \ No newline at end of file diff --git a/Src/Api/tv.py b/Src/Api/tv.py index 4578a38..4ab1c7c 100644 --- a/Src/Api/tv.py +++ b/Src/Api/tv.py @@ -7,7 +7,7 @@ from Src.Util.Helper.console import console, msg from Src.Util.m3u8 import dw_m3u8 # General import -import requests, os, re, json +import requests, os, re, json, sys from bs4 import BeautifulSoup # [func] @@ -17,31 +17,43 @@ def get_token(id_tv, domain): return session.cookies['XSRF-TOKEN'] def get_info_tv(id_film, title_name, site_version, domain): - r = requests.get(f"https://streamingcommunity.{domain}/titles/{id_film}-{title_name}", headers={ + req = requests.get(f"https://streamingcommunity.{domain}/titles/{id_film}-{title_name}", headers={ 'X-Inertia': 'true', 'X-Inertia-Version': site_version, 'User-Agent': get_headers() }) - return r.json()['props']['title']['seasons_count'] + if req.ok(): + return req.json()['props']['title']['seasons_count'] + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def get_info_season(tv_id, tv_name, domain, version, token, n_stagione): - r = requests.get(f'https://streamingcommunity.{domain}/titles/{tv_id}-{tv_name}/stagione-{n_stagione}', headers={ + req = requests.get(f'https://streamingcommunity.{domain}/titles/{tv_id}-{tv_name}/stagione-{n_stagione}', headers={ 'authority': f'streamingcommunity.{domain}', 'referer': f'https://streamingcommunity.broker/titles/{tv_id}-{tv_name}', 'user-agent': get_headers(), 'x-inertia': 'true', 'x-inertia-version': version, 'x-xsrf-token': token, }) - return [{'id': ep['id'], 'n': ep['number'], 'name': ep['name']} for ep in r.json()['props']['loadedSeason']['episodes']] + if req.ok: + return [{'id': ep['id'], 'n': ep['number'], 'name': ep['name']} for ep in req.json()['props']['loadedSeason']['episodes']] + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def get_iframe(tv_id, ep_id, domain, token): - r = requests.get(f'https://streamingcommunity.{domain}/iframe/{tv_id}', params={'episode_id': ep_id, 'next_episode': '1'}, cookies={'XSRF-TOKEN': token}, headers={ + req = requests.get(f'https://streamingcommunity.{domain}/iframe/{tv_id}', params={'episode_id': ep_id, 'next_episode': '1'}, cookies={'XSRF-TOKEN': token}, headers={ 'referer': f'https://streamingcommunity.{domain}/watch/{tv_id}?e={ep_id}', 'user-agent': get_headers() }) - url_embed = BeautifulSoup(r.text, "lxml").find("iframe").get("src") - req_embed = requests.get(url_embed, headers = {"User-agent": get_headers()}).text - return BeautifulSoup(req_embed, "lxml").find("body").find("script").text + if req.ok: + url_embed = BeautifulSoup(req.text, "lxml").find("iframe").get("src") + req_embed = requests.get(url_embed, headers = {"User-agent": get_headers()}).text + return BeautifulSoup(req_embed, "lxml").find("body").find("script").text + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def parse_content(embed_content): @@ -59,22 +71,30 @@ def get_m3u8_url(json_win_video, json_win_param): return f"https://vixcloud.co/playlist/{json_win_video['id']}?type=video&rendition=720p&token={json_win_param['token720p']}&expires={json_win_param['expires']}" def get_m3u8_key_ep(json_win_video, json_win_param, tv_name, n_stagione, n_ep, ep_title): - req_key = requests.get('https://vixcloud.co/storage/enc.key', headers={ + req = requests.get('https://vixcloud.co/storage/enc.key', headers={ 'referer': f'https://vixcloud.co/embed/{json_win_video["id"]}?token={json_win_param["token720p"]}&title={tv_name.replace("-", "+")}&referer=1&expires={json_win_param["expires"]}&description=S{n_stagione}%3AE{n_ep}+{ep_title.replace(" ", "+")}&nextEpisode=1', - }).content + }) - return "".join(["{:02x}".format(c) for c in req_key]) + if req.ok: + return "".join(["{:02x}".format(c) for c in req.content]) + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def get_m3u8_audio(json_win_video, json_win_param, tv_name, n_stagione, n_ep, ep_title): - response = requests.get(f'https://vixcloud.co/playlist/{json_win_video["id"]}', params={'token': json_win_param['token'], 'expires': json_win_param["expires"] }, headers={ + req = requests.get(f'https://vixcloud.co/playlist/{json_win_video["id"]}', params={'token': json_win_param['token'], 'expires': json_win_param["expires"] }, headers={ 'referer': f'https://vixcloud.co/embed/{json_win_video["id"]}?token={json_win_param["token720p"]}&title={tv_name.replace("-", "+")}&referer=1&expires={json_win_param["expires"]}&description=S{n_stagione}%3AE{n_ep}+{ep_title.replace(" ", "+")}&nextEpisode=1' }) - m3u8_cont = response.text.split() - for row in m3u8_cont: - if "audio" in str(row) and "ita" in str(row): - return row.split(",")[-1].split('"')[-2] + if req.ok: + m3u8_cont = req.text.split() + for row in m3u8_cont: + if "audio" in str(row) and "ita" in str(row): + return row.split(",")[-1].split('"')[-2] + else: + console.log(f"[red]Error: {req.status_code}") + sys.exit(0) def actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name): diff --git a/Src/Util/m3u8.py b/Src/Util/m3u8.py index a10a38c..de58b20 100644 --- a/Src/Util/m3u8.py +++ b/Src/Util/m3u8.py @@ -92,12 +92,10 @@ class M3U8Downloader: if response.ok: m3u8_content = response.text self.parse_m3u8(m3u8_content) - else: console.log("[red]Wrong m3u8 url") sys.exit(0) - if self.m3u8_audio != None: # Check there is audio in first ts file @@ -206,15 +204,3 @@ def dw_m3u8(url, audio_url=None, key=None, output_filename="output.mp4"): downloader.download_m3u8() downloader.download_and_save_ts() downloader.join_ts_files() - -def join_audio_to_video(audio_path, video_path, out_path): - - # Get audio and video - audio = mp.AudioFileClip(audio_path) - video1 = mp.VideoFileClip(video_path) - - # Add audio - final = video1.set_audio(audio) - - # Join all - final.write_videofile(out_path)