From 09b6e1203c3f4ca31b9c85bbe11df4cd7795cff7 Mon Sep 17 00:00:00 2001 From: Ghost6446 <62809003+Ghost6446@users.noreply.github.com> Date: Tue, 26 Dec 2023 11:28:01 +0100 Subject: [PATCH] add audio download --- Stream/api/tv.py | 26 +++++++++++++++++++++++--- Stream/util/m3u8.py | 9 +++++++++ requirements.txt | 3 ++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Stream/api/tv.py b/Stream/api/tv.py index e1e1c13..361204a 100644 --- a/Stream/api/tv.py +++ b/Stream/api/tv.py @@ -3,10 +3,10 @@ # Class import from Stream.util.headers import get_headers from Stream.util.console import console, msg, console_print -from Stream.util.m3u8 import dw_m3u8 +from Stream.util.m3u8 import dw_m3u8, join_audio_to_video # General import -import requests, sys, re, json +import requests, os, re, json from bs4 import BeautifulSoup # [func] @@ -64,6 +64,18 @@ def get_m3u8_key_ep(json_win_video, json_win_param, tv_name, n_stagione, n_ep, e return "".join(["{:02x}".format(c) for c in req_key]) +def get_m3u8_audio(json_win_video, json_win_param, tv_name, n_stagione, n_ep, ep_title): + + response = requests.get('https://vixcloud.co/playlist/175967', 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] + + def main_dw_tv(tv_id, tv_name, version, domain): token = get_token(tv_id, domain) @@ -81,6 +93,14 @@ def main_dw_tv(tv_id, tv_name, version, domain): 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']) - + dw_m3u8(m3u8_url, requests.get(m3u8_url, headers={"User-agent": get_headers()}).text, "", m3u8_key, tv_name.replace("+", "_") + "_"+str(season_select)+"__"+str(index_ep_select+1) + ".mp4") + is_down_audio = msg.ask("[blue]Download audio [red](!!! Only for recent upload, !!! Use all CPU) [blue][y \ n]").strip() + if str(is_down_audio) == "y": + 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']) + dw_m3u8(m3u8_url_audio, requests.get(m3u8_url_audio, headers={"User-agent": get_headers()}).text, "", m3u8_key, "audio.mp4") + + join_audio_to_video("videos//audio.mp4", "videos//" + tv_name.replace("+", "_") + "_"+str(season_select)+"__"+str(index_ep_select+1) + ".mp4", "videos//" + tv_name.replace("+", "_") + "_"+str(season_select)+"__"+str(index_ep_select+1) + "_audio.mp4") + os.remove("videos//audio.mp4") + os.remove("videos//" + tv_name.replace("+", "_") + "_"+str(season_select)+"__"+str(index_ep_select+1) + ".mp4") \ No newline at end of file diff --git a/Stream/util/m3u8.py b/Stream/util/m3u8.py index dab1782..54fd0f1 100644 --- a/Stream/util/m3u8.py +++ b/Stream/util/m3u8.py @@ -5,6 +5,7 @@ import re, os, sys, glob, time, requests, shutil, ffmpeg, subprocess from functools import partial from multiprocessing.dummy import Pool from tqdm.rich import tqdm +import moviepy.editor as mp # Class import #from Stream.util.console import console @@ -289,3 +290,11 @@ def dw_vvt_sub(url, headers, folder_id) -> (None): else: console.log("[red]Cant find info of subtitle [SKIP]") + +def join_audio_to_video(audio_path, video_path, out_path): + + audio = mp.AudioFileClip(audio_path) + video1 = mp.VideoFileClip(video_path) + final = video1.set_audio(audio) + + final.write_videofile(out_path) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1c313fa..396fedd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ lxml tqdm rich random-user-agent -ffmpeg-python \ No newline at end of file +ffmpeg-python +moviepy \ No newline at end of file