Merge pull request #10 from EmanueleSpadaro/main

feat: download all episodes at once
This commit is contained in:
Ghost 2024-01-10 18:11:27 +01:00 committed by GitHub
commit 4f35a4c4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 22 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
bin
lib
lib64
*__pycache__
pyvenv.cfg
# Project specific
videos/
tmp/
Src/Util/file_list.txt

View File

@ -8,6 +8,7 @@ from Src.Util.m3u8 import dw_m3u8
# General import # General import
import requests, os, re, json, sys import requests, os, re, json, sys
from enum import Enum
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# [func] # [func]
@ -23,7 +24,7 @@ def get_info_tv(id_film, title_name, site_version, domain):
'User-Agent': get_headers() 'User-Agent': get_headers()
}) })
if req.ok(): if req.ok:
return req.json()['props']['title']['seasons_count'] return req.json()['props']['title']['seasons_count']
else: else:
console.log(f"[red]Error: {req.status_code}") console.log(f"[red]Error: {req.status_code}")
@ -97,20 +98,7 @@ def get_m3u8_audio(json_win_video, json_win_param, tv_name, n_stagione, n_ep, ep
sys.exit(0) sys.exit(0)
def main_dw_tv(tv_id, tv_name, version, domain): def actually_dw(tv_id, eps, index_ep_select, domain, token, tv_name, season_select, lower_tv_name):
token = get_token(tv_id, domain)
lower_tv_name = str(tv_name).lower()
tv_name = convert_utf8_name(lower_tv_name) # ERROR LATIN 1 IN REQ WITH ò à ù ...
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 = int(msg.ask("\n[green]Insert ep number: ")) - 1
embed_content = get_iframe(tv_id, eps[index_ep_select]['id'], domain, token) embed_content = get_iframe(tv_id, eps[index_ep_select]['id'], domain, token)
json_win_video, json_win_param = parse_content(embed_content) json_win_video, json_win_param = parse_content(embed_content)
m3u8_url = get_m3u8_url(json_win_video, json_win_param) m3u8_url = get_m3u8_url(json_win_video, json_win_param)
@ -126,3 +114,34 @@ def main_dw_tv(tv_id, tv_name, version, domain):
console.print("[red]=> Use m3u8 audio") console.print("[red]=> Use m3u8 audio")
dw_m3u8(m3u8_url, m3u8_url_audio, m3u8_key, mp4_path) dw_m3u8(m3u8_url, m3u8_url_audio, m3u8_key, mp4_path)
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)
lower_tv_name = str(tv_name).lower()
tv_name = convert_utf8_name(lower_tv_name) # ERROR LATIN 1 IN REQ WITH ò à ù ...
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: ")
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)
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)

3
run.py
View File

@ -34,7 +34,8 @@ def main():
else: else:
console.print(f"[green]\nTv select: {db_title[index_select]['name']}") 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") console.print("\n[red]Done")