Skip to content

Commit

Permalink
add audio download
Browse files Browse the repository at this point in the history
  • Loading branch information
Lovi-0 committed Dec 26, 2023
1 parent fb892cc commit 09b6e12
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
26 changes: 23 additions & 3 deletions Stream/api/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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")
9 changes: 9 additions & 0 deletions Stream/util/m3u8.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lxml
tqdm
rich
random-user-agent
ffmpeg-python
ffmpeg-python
moviepy

0 comments on commit 09b6e12

Please sign in to comment.