From b4c4db69beed45a011c44a539d027b36bba2e420 Mon Sep 17 00:00:00 2001 From: Emanuele Spadaro Date: Mon, 8 Jan 2024 00:26:13 +0100 Subject: [PATCH 1/2] feat: download all episodes at once now you can insert * as episode number to download all the available episodes for a given series season --- .gitignore | 5 +++++ Src/Api/tv.py | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9d6f36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin +lib +lib64 +*__pycache__ +pyvenv.cfg \ No newline at end of file diff --git a/Src/Api/tv.py b/Src/Api/tv.py index e674967..4578a38 100644 --- a/Src/Api/tv.py +++ b/Src/Api/tv.py @@ -76,7 +76,26 @@ def get_m3u8_audio(json_win_video, json_win_param, tv_name, n_stagione, n_ep, ep if "audio" in str(row) and "ita" in str(row): return row.split(",")[-1].split('"')[-2] - + +def actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name): + embed_content = get_iframe(tv_id, eps[index_ep_select]['id'], domain, token) + json_win_video, json_win_param = parse_content(embed_content) + m3u8_url = get_m3u8_url(json_win_video, json_win_param) + m3u8_key = get_m3u8_key_ep(json_win_video, json_win_param, tv_name, season_select, index_ep_select+1, eps[index_ep_select]['name']) + + mp4_name = f"{lower_tv_name.replace('+', '_')}_{str(season_select)}_{str(index_ep_select+1)}" + mp4_format = mp4_name + ".mp4" + mp4_path = os.path.join("videos", mp4_format) + + m3u8_url_audio = get_m3u8_audio(json_win_video, json_win_param, tv_name, season_select, index_ep_select+1, eps[index_ep_select]['name']) + + if m3u8_url_audio != None: + console.print("[red]=> Use m3u8 audio") + + dw_m3u8(m3u8_url, m3u8_url_audio, m3u8_key, mp4_path) + + + def main_dw_tv(tv_id, tv_name, version, domain): token = get_token(tv_id, domain) @@ -89,20 +108,13 @@ def main_dw_tv(tv_id, tv_name, version, domain): eps = get_info_season(tv_id, tv_name, domain, version, token, season_select) for ep in eps: console.print(f"[green]Ep: [blue]{ep['n']} [green]=> [purple]{ep['name']}") - index_ep_select = int(msg.ask("\n[green]Insert ep number: ")) - 1 - - embed_content = get_iframe(tv_id, eps[index_ep_select]['id'], domain, token) - json_win_video, json_win_param = parse_content(embed_content) - m3u8_url = get_m3u8_url(json_win_video, json_win_param) - m3u8_key = get_m3u8_key_ep(json_win_video, json_win_param, tv_name, season_select, index_ep_select+1, eps[index_ep_select]['name']) + index_ep_select = msg.ask("\n[green]Insert ep number (use * for all episodes): ") - mp4_name = f"{lower_tv_name.replace('+', '_')}_{str(season_select)}_{str(index_ep_select+1)}" - mp4_format = mp4_name + ".mp4" - mp4_path = os.path.join("videos", mp4_format) - - m3u8_url_audio = get_m3u8_audio(json_win_video, json_win_param, tv_name, season_select, index_ep_select+1, eps[index_ep_select]['name']) - - if m3u8_url_audio != None: - console.print("[red]=> Use m3u8 audio") - - dw_m3u8(m3u8_url, m3u8_url_audio, m3u8_key, mp4_path) + if(index_ep_select == '*'): + for ep in eps: + index_ep_select = int(ep['n']) - 1 + actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name) + return + + index_ep_select = int(index_ep_select) - 1 + actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name) \ No newline at end of file From 8fd490cb30121f444ed7bd9f96b2448a29149e2e Mon Sep 17 00:00:00 2001 From: Emanuele Spadaro Date: Tue, 9 Jan 2024 18:43:20 +0100 Subject: [PATCH 2/2] feat: download all episodes at once --- .gitignore | 7 ++++++- Src/Api/tv.py | 29 ++++++++++++++++++----------- run.py | 3 ++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f9d6f36..9f08978 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,9 @@ bin lib lib64 *__pycache__ -pyvenv.cfg \ No newline at end of file +pyvenv.cfg + +# Project specific +videos/ +tmp/ +Src/Util/file_list.txt \ No newline at end of file diff --git a/Src/Api/tv.py b/Src/Api/tv.py index 4ab1c7c..008f693 100644 --- a/Src/Api/tv.py +++ b/Src/Api/tv.py @@ -8,6 +8,7 @@ from Src.Util.m3u8 import dw_m3u8 # General import import requests, os, re, json, sys +from enum import Enum from bs4 import BeautifulSoup # [func] @@ -23,7 +24,7 @@ def get_info_tv(id_film, title_name, site_version, domain): 'User-Agent': get_headers() }) - if req.ok(): + if req.ok: return req.json()['props']['title']['seasons_count'] else: console.log(f"[red]Error: {req.status_code}") @@ -116,7 +117,11 @@ def actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_sele -def main_dw_tv(tv_id, tv_name, version, domain): +class TvDownloadBehaviour(Enum): + DOWNLOAD_EPISODE = 0 + DOWNLOAD_SEASON = 1 + +def main_dw_tv(tv_id, tv_name, version, domain, tv_download_behaviour): token = get_token(tv_id, domain) @@ -125,16 +130,18 @@ def main_dw_tv(tv_id, tv_name, version, domain): console.print(f"[blue]Season find: [red]{get_info_tv(tv_id, tv_name, version, domain)}") season_select = msg.ask("\n[green]Insert season number: ") - eps = get_info_season(tv_id, tv_name, domain, version, token, season_select) - for ep in eps: - console.print(f"[green]Ep: [blue]{ep['n']} [green]=> [purple]{ep['name']}") - index_ep_select = msg.ask("\n[green]Insert ep number (use * for all episodes): ") - if(index_ep_select == '*'): + console.print(tv_download_behaviour) + + eps = get_info_season(tv_id, tv_name, domain, version, token, season_select) + + if (tv_download_behaviour == TvDownloadBehaviour.DOWNLOAD_SEASON.value): for ep in eps: + console.print(f"[green]Ep: [blue]{ep['n']} [green]=> [purple]{ep['name']}") index_ep_select = int(ep['n']) - 1 actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name) - return - - index_ep_select = int(index_ep_select) - 1 - actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name) \ No newline at end of file + else: + for ep in eps: + console.print(f"[green]Ep: [blue]{ep['n']} [green]=> [purple]{ep['name']}") + index_ep_select = int(msg.ask("\n[green]Insert ep number: ")) - 1 + actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name) \ No newline at end of file diff --git a/run.py b/run.py index d2fbf56..e3a0986 100644 --- a/run.py +++ b/run.py @@ -34,7 +34,8 @@ def main(): else: console.print(f"[green]\nTv select: {db_title[index_select]['name']}") - download_tv(db_title[index_select]['id'], db_title[index_select]['name'].replace(" ", "+"), site_version, domain) + tv_download_behaviour = int(msg.ask(f"\n[blue]Do you want to download specific episodes or an entire season? (0-> Specific | 1 -> Entire season): ", choices=['0', '1'])) + download_tv(db_title[index_select]['id'], db_title[index_select]['name'].replace(" ", "+"), site_version, domain, tv_download_behaviour) console.print("\n[red]Done")