گل زیر رو برام توضیح بده import ytdlp def getdownloadurls(videoparams: dict): url =…
- User
گل زیر رو برام توضیح بده import yt_dlp
def get_download_urls(video_params: dict): url = video_params[‘url’] # video url:str
ydl_opts = { ‘format’: ‘bestvideo[ext=mp4]+bestaudio[ext=m4a]/best’, ‘quiet’: True, # جلوگیری از چاپ خروجیهای اضافی }
with yt_dlp.YoutubeDL(ydl_opts) as ydl: info_dict = ydl.extract_info(url, download=False) formats = info_dict.get(‘formats’, [])
best_video_url = “” best_audio_url = “”
for format in formats: ext = format.get(‘ext’, ‘Unknown’) download_url = format.get(‘url’, ‘Unknown’)
if ‘video’ in format.get(‘vcodec’, ‘’) and ext == ‘mp4’: best_video_url = download_url elif ‘audio’ in format.get(‘acodec’, ‘’) and ext == ‘m4a’: best_audio_url = download_url
return best_video_url, best_audio_url
def generate_html(video_url, audio_url): html_content = f"“”
var mediaSource = new MediaSource(); video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener(‘sourceopen’, function() { var videoSourceBuffer = mediaSource.addSourceBuffer(‘video/mp4; codecs=“avc1.64001E, mp4a.40.2”’);
fetch(videoSrc) .then(response => response.arrayBuffer()) .then(data => { videoSourceBuffer.appendBuffer(data); });
videoSourceBuffer.addEventListener(‘updateend’, function() { var audioSourceBuffer = mediaSource.addSourceBuffer(‘audio/mp4; codecs=“mp4a.40.2”’);
fetch(audioSrc) .then(response => response.arrayBuffer()) .then(data => { audioSourceBuffer.appendBuffer(data); }); }); }); } else { console.error(‘MSE not supported or no compatible codecs’); }
with open(‘video_with_audio.html’, ‘w’, encoding=‘utf-8’) as file: file.write(html_content)
print(‘HTML file generated: video_with_audio.html’)
video_params = { ‘user_type’: ‘free’, ‘subtitles’: True, ‘subtitles_lang’: ‘fa’, ‘url’: ‘https://www.youtube.com/watch?v=Fdb03SrloHE’ }
video_url, audio_url = get_download_urls(video_params) generate_html(video_url, audio_url)
- Assistant
- User
چطوری میتونم اینو روی جنگو پیادهسازیش کنم به طوری که وقتی که یو آر ال رو از طریق یک ریکوئست به سمت سرور ارسال میکنه یک تمپلیت به سمت کلاینت برگردونه که داخل اون تمپلیت ویدیو یوتیوب نمایش داده بشه به همراه صدا
- Assistant