This commit is contained in:
Helper0x 2024-03-26 10:08:24 +01:00
parent 56e8a45d25
commit ff60f032e1
6 changed files with 49 additions and 63 deletions

View File

@ -123,5 +123,12 @@ def main_dw_film(id_film, title_name, domain):
console.print("[blue]Using m3u8 audio => [red]True")
subtitle_path = os.path.join(config['root_path'], config['movies_folder_name'], mp4_name)
download_m3u8(m3u8_index=m3u8_url, m3u8_audio=m3u8_url_audio, m3u8_subtitle=m3u8_playlist, key=m3u8_key,
output_filename=mp4_path, subtitle_folder=subtitle_path, content_name=mp4_name)
download_m3u8(
m3u8_index = m3u8_url,
m3u8_audio = m3u8_url_audio,
m3u8_subtitle = m3u8_playlist,
key = m3u8_key,
output_filename = mp4_path,
subtitle_folder = subtitle_path,
content_name = mp4_name
)

View File

@ -145,10 +145,10 @@ def dw_single_ep(tv_id, eps, index_ep_select, domain, tv_name, season_select):
m3u8_url = get_m3u8_url(json_win_video, json_win_param, render_quality)
m3u8_key = get_m3u8_key_ep()
mp4_name = f"{tv_name.replace('+', '_')}_S{str(season_select).zfill(2)}E{str(index_ep_select + 1).zfill(2)}"
mp4_name = f"S{str(season_select).zfill(2)}E{str(index_ep_select + 1).zfill(2)}"
mp4_format = f"{mp4_name}.mp4"
season = mp4_name.rsplit("E", 1)[0]
mp4_path = os.path.join(config['root_path'], config['series_folder_name'], tv_name, season, mp4_format)
mp4_path = os.path.join(config['root_path'], config['series_folder_name'], mp4_format)
m3u8_url_audio = get_m3u8_audio(json_win_video, json_win_param, tv_name, season_select, index_ep_select + 1,
encoded_name, token_render)
@ -157,8 +157,15 @@ def dw_single_ep(tv_id, eps, index_ep_select, domain, tv_name, season_select):
console.print("[blue]Using m3u8 audio => [red]True")
subtitle_path = os.path.join(config['root_path'], config['series_folder_name'], tv_name, season)
download_m3u8(m3u8_index=m3u8_url, m3u8_audio=m3u8_url_audio, m3u8_subtitle=m3u8_playlist, key=m3u8_key,
output_filename=mp4_path, subtitle_folder=subtitle_path, content_name=mp4_name)
download_m3u8(
m3u8_index = m3u8_url,
m3u8_audio = m3u8_url_audio,
m3u8_subtitle = m3u8_playlist,
key = m3u8_key,
output_filename = mp4_path,
subtitle_folder = subtitle_path,
content_name = mp4_name
)
def main_dw_tv(tv_id, tv_name, version, domain):

View File

@ -21,9 +21,10 @@ warnings.filterwarnings("ignore", category=UserWarning, module="cryptography")
# Variable
MAX_WORKER = config['max_worker']
DOWNLOAD_PATH = config['root_path']
DOWNLOAD_SUB = config['download_subtitles']
DOWNLOAD_DEFAULT_LANGUAGE = config['download_default_language'] # True to select default language, False to select language
SELECTED_LANGUAGE = config['selected_language'] # Ex. "English" if DOWNLOAD_DEFAULT_LANGUAGE is False
DOWNLOAD_DEFAULT_LANGUAGE = config['download_default_language']
SELECTED_LANGUAGE = config['selected_language']
failed_segments = []
@ -319,13 +320,13 @@ class M3U8_Segments:
relative_path = os.path.relpath(os.path.join(self.temp_folder, ts_file))
f.write(f"file '{relative_path}'\n")
console.log("[cyan]Joining all files...")
#console.log("[cyan]Joining all files...")
try:
ffmpeg.input(file_list_path, format='concat', safe=0).output(output_filename, map_metadata='-1', c='copy', loglevel='error').run()
except ffmpeg.Error as e:
console.log(f"[red]Error saving MP4: {e.stdout}")
console.log(f"[cyan]Clean ...")
#console.log(f"[cyan]Clean ...")
os.remove(file_list_path)
shutil.rmtree("tmp", ignore_errors=True)
@ -335,25 +336,23 @@ class M3U8_Downloader:
self.m3u8_audio = m3u8_audio
self.key = key
self.video_path = output_filename
self.audio_path = os.path.join("videos", "audio.mp4")
self.audio_path = os.path.join(DOWNLOAD_PATH, "audio.mp4")
def start(self):
video_m3u8 = M3U8_Segments(self.m3u8_url, self.key)
console.log("[green]Downloading video ts")
console.log("[purple]Downloading video ts")
video_m3u8.get_info()
video_m3u8.download_ts()
video_m3u8.join(self.video_path)
print_duration_table(self.video_path)
print("\n")
if self.m3u8_audio is not None:
audio_m3u8 = M3U8_Segments(self.m3u8_audio, self.key)
console.log("[green]Downloading audio ts")
console.log("[purple]Downloading audio ts")
audio_m3u8.get_info()
audio_m3u8.download_ts()
audio_m3u8.join(self.audio_path)
print_duration_table(self.audio_path)
print("\n")
self.join_audio()
@ -361,7 +360,7 @@ class M3U8_Downloader:
os.renames(f"{self.video_path}.mp4", self.video_path)
def join_audio(self):
console.log("[cyan]Join audio and video")
console.log("[purple]Join audio and video")
try:
video_stream = ffmpeg.input(self.video_path)
@ -404,13 +403,24 @@ def df_make_req(url):
sys.exit(0)
def download_subtitle(url, name_language):
path = os.path.join("videos", "subtitle")
path = os.path.join(DOWNLOAD_PATH, "subtitle")
os.makedirs(path, exist_ok=True)
console.log(f"[green]Downloading subtitle: [red]{name_language}")
open(os.path.join(path, name_language + ".vtt"), "wb").write(requests.get(url).content)
def download_m3u8(m3u8_playlist=None, m3u8_index = None, m3u8_audio=None, m3u8_subtitle=None, key=None, output_filename=os.path.join("videos", "output.mp4"), log=False, subtitle_folder="subtitles", content_name=""):
def download_m3u8(
m3u8_playlist=None,
m3u8_index = None,
m3u8_audio=None,
m3u8_subtitle=None,
key=None,
output_filename=os.path.join(DOWNLOAD_PATH, "output.mp4"),
log=False,
subtitle_folder="subtitles",
content_name=""
):
m3u8_audio_url=None
# m3u8_playlist never use in this version
@ -443,7 +453,6 @@ def download_m3u8(m3u8_playlist=None, m3u8_index = None, m3u8_audio=None, m3u8_s
parse_class_m3u8_sub.download_subtitle(subtitle_path=subtitle_folder, content_name=content_name)
# Download m3u8 index, with segments
# os.makedirs("videos", exist_ok=True)
path = os.path.dirname(output_filename)
os.makedirs(path, exist_ok=True)

View File

@ -3,7 +3,7 @@ bs4
lxml
tqdm
rich
fake-useragent==1.1.3
ffmpeg-python
cryptography==3.4.8 # Problem with new version
m3u8
cryptography==3.4.8
fake-useragent==1.1.3

10
run.py
View File

@ -1,4 +1,4 @@
# 10.12.23 -> 31.01.24
# 10.12.23 -> 1.02.24
# Class
import Src.Api.page as Page
@ -118,9 +118,9 @@ if __name__ == '__main__':
main()
while 1:
cmd_insert = input("Quit the script [yes/no]: ")
cmd_insert = str(msg.ask("[red]Quit the script ? [red][[yellow]yes[red] / [yellow]no[red]]"))
if cmd_insert == "y" or cmd_insert == "yes":
main()
else:
if cmd_insert in ['y', 'yes', 'ye']:
break
else:
main()

View File

@ -1,37 +0,0 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['run.py'],
pathex=[],
binaries=[],
datas=[('./Src/upload/__version__.py', 'Src/upload')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='run',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)