Update app.py
Browse files41 unmodified lines4243444546474849505152535455565758596061626364656667681 unmodified line7071727374757677787941 unmodified linesimport tempfilefrom yt_dlp import YoutubeDLdef download_youtube_video(youtube_url):"""Downloads a YouTube video using yt-dlp with cookies for authentication.Parameters:- youtube_url: The URL of the YouTube video.Returns:- The path to the downloaded video file."""# Temporary file for the videowith tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:temp_video_path = temp_video.name# yt-dlp optionsydl_opts = {'format': 'bestvideo+bestaudio/best', # Download best video and audio'outtmpl': temp_video_path, # Output file path'merge_output_format': 'mp4', # Merge into MP4 format'cookies': 'testing/cookies.txt', # Path to the cookies file'quiet': True, # Suppress yt-dlp output}try:1 unmodified linewith YoutubeDL(ydl_opts) as ydl:ydl.download([youtube_url])return temp_video_path # Return the video file pathexcept Exception as e:raise RuntimeError(f"An error occurred while downloading the video: {str(e)}")# YouTube video URL input41 unmodified lines424344454647484950515253545556575859601 unmodified line626364656667686970717241 unmodified linesimport tempfilefrom yt_dlp import YoutubeDLimport browser_cookie3from yt_dlp import YoutubeDLdef download_youtube_video(youtube_url):# Extract cookies from browser (Chrome, Firefox, etc.)cookies = browser_cookie3.load()# yt-dlp optionsydl_opts = {'format': 'bestvideo+bestaudio/best', # Download best video and audio'outtmpl': 'downloaded_video.mp4', # Output file path'cookies': cookies, # Use cookies directly from browser'quiet': True, # Suppress yt-dlp output}try:1 unmodified linewith YoutubeDL(ydl_opts) as ydl:ydl.download([youtube_url])print("Download successful!")except Exception as e:print(f"An error occurred: {str(e)}")# YouTube video URL input
app.py+11-18