Manasa1 commited on
Commit
9b66583
·
verified ·
1 Parent(s): e799555

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -41,16 +41,42 @@ def initialize_agent():
41
  multimodal_Agent = initialize_agent()
42
 
43
  # Function to download YouTube video using yt-dlp
 
 
 
44
  def download_youtube_video(youtube_url):
 
 
 
 
 
 
 
 
 
 
45
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
46
- ydl_opts = {
47
- 'format': 'bestvideo+bestaudio/best',
48
- 'outtmpl': temp_video.name,
49
- 'quiet': True,
50
- }
 
 
 
 
 
 
 
 
51
  with YoutubeDL(ydl_opts) as ydl:
52
  ydl.download([youtube_url])
53
- return temp_video.name
 
 
 
 
 
54
 
55
  # YouTube video URL input
56
  youtube_url = st.text_input(
 
41
  multimodal_Agent = initialize_agent()
42
 
43
  # Function to download YouTube video using yt-dlp
44
+ from yt_dlp import YoutubeDL
45
+ import tempfile
46
+
47
  def download_youtube_video(youtube_url):
48
+ """
49
+ Downloads a YouTube video using yt-dlp with cookies for authentication.
50
+
51
+ Parameters:
52
+ - youtube_url: The URL of the YouTube video.
53
+
54
+ Returns:
55
+ - The path to the downloaded video file.
56
+ """
57
+ # Temporary file for the video
58
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
59
+ temp_video_path = temp_video.name
60
+
61
+ # yt-dlp options
62
+ ydl_opts = {
63
+ 'format': 'bestvideo+bestaudio/best', # Download best video and audio
64
+ 'outtmpl': temp_video_path, # Output file path
65
+ 'merge_output_format': 'mp4', # Merge into MP4 format
66
+ 'cookies': 'cookies.txt', # Path to the cookies file
67
+ 'quiet': True, # Suppress yt-dlp output
68
+ }
69
+
70
+ try:
71
+ # Download the video
72
  with YoutubeDL(ydl_opts) as ydl:
73
  ydl.download([youtube_url])
74
+
75
+ return temp_video_path # Return the video file path
76
+
77
+ except Exception as e:
78
+ raise RuntimeError(f"An error occurred while downloading the video: {str(e)}")
79
+
80
 
81
  # YouTube video URL input
82
  youtube_url = st.text_input(