sofzcc commited on
Commit
3e5eaad
1 Parent(s): f4d52ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -226,25 +226,25 @@ def generate_valid_filename(query):
226
  import whisper
227
  import time
228
  from pytube import YouTube
229
- from pytube.exceptions import PytubeError
230
-
231
 
232
  def download_video(url):
 
 
 
 
 
233
  try:
234
- video = YouTube(url)
235
- stream = video.streams.filter(file_extension='mp4').first()
236
- if stream:
237
- return stream.download()
238
- else:
239
- raise ValueError("No suitable stream found.")
240
- except PytubeError as e:
241
- print(f"PytubeError: {e}")
242
- raise
243
  except Exception as e:
244
- print(f"Unexpected error: {e}")
245
  raise
246
 
247
 
 
248
  def video_to_text(filename):
249
  clip = VideoFileClip(filename)
250
  audio_filename = filename[:-4] + ".mp3"
 
226
  import whisper
227
  import time
228
  from pytube import YouTube
229
+ import yt_dlp
 
230
 
231
  def download_video(url):
232
+ print(f"Attempting to download video from URL: {url}")
233
+ ydl_opts = {
234
+ 'format': 'bestvideo+bestaudio/best',
235
+ 'outtmpl': 'downloads/%(title)s.%(ext)s',
236
+ }
237
  try:
238
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
239
+ info_dict = ydl.extract_info(url, download=True)
240
+ print(f"Downloaded: {info_dict['title']}")
241
+ return info_dict['title'] # Or return other relevant info
 
 
 
 
 
242
  except Exception as e:
243
+ print(f"Error: {e}")
244
  raise
245
 
246
 
247
+
248
  def video_to_text(filename):
249
  clip = VideoFileClip(filename)
250
  audio_filename = filename[:-4] + ".mp3"