learningai commited on
Commit
85f0d62
·
1 Parent(s): 526decc

invalid url exception handled

Browse files
Files changed (1) hide show
  1. utils.py +7 -3
utils.py CHANGED
@@ -12,7 +12,7 @@ def get_video_from_yt(video_url : str, save_file_dir : str, video_name : str="yt
12
  downloaded file as string
13
  """
14
 
15
- logging.info(f"Attempting youtube video download : \nURL : {video_url}")
16
 
17
  try :
18
  # create directory if not exists
@@ -23,9 +23,13 @@ def get_video_from_yt(video_url : str, save_file_dir : str, video_name : str="yt
23
  # download the file
24
  os.system(f'yt-dlp --quiet -o {filepath} -x --audio-format "wav" {video_url}')
25
 
26
- logging.info(f"Download successful. \nAudio file path : {filepath}")
 
27
 
28
- return f"{filepath}.wav"
 
 
 
29
  except Exception as e:
30
  logging.info("Download unsuccessful.")
31
  logging.exception(e)
 
12
  downloaded file as string
13
  """
14
 
15
+ logging.info(f"Attempting youtube video download for URL : {video_url}")
16
 
17
  try :
18
  # create directory if not exists
 
23
  # download the file
24
  os.system(f'yt-dlp --quiet -o {filepath} -x --audio-format "wav" {video_url}')
25
 
26
+ if os.path.exists(f"{filepath}.wav"):
27
+ logging.info(f"Download successful. Audio file path : {filepath}.wav")
28
 
29
+ return f"{filepath}.wav"
30
+ else:
31
+ logging.info("Download unsuccessful. Please check logs.")
32
+ return None
33
  except Exception as e:
34
  logging.info("Download unsuccessful.")
35
  logging.exception(e)