ruslanmv commited on
Commit
f538f45
·
verified ·
1 Parent(s): e510193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -31,16 +31,26 @@ def download_video(url):
31
  return local_file
32
 
33
  def validate_youtube(url):
34
- #This creates a youtube objet
35
  try:
36
  yt = YouTube(url)
37
- except Exception:
38
- print("Hi there URL seems invalid")
 
 
 
 
 
 
 
 
 
39
  return True
40
- #This will return the length of the video in sec as an int
41
- video_length = yt.length
42
- if video_length > 600:
43
- print("Your video is larger than 10 minutes")
 
44
  return True
45
  else:
46
  print("Your video is less than 10 minutes")
 
31
  return local_file
32
 
33
  def validate_youtube(url):
34
+ # This creates a YouTube object
35
  try:
36
  yt = YouTube(url)
37
+ except Exception as e:
38
+ print("Invalid URL or network issue:", e)
39
+ return True
40
+
41
+ # Fetch video details safely
42
+ video_details = yt.vid_info.get('videoDetails', {})
43
+ length_seconds = video_details.get('lengthSeconds')
44
+
45
+ # Ensure lengthSeconds is not None before converting to int
46
+ if length_seconds is None:
47
+ print("Error: Could not retrieve video length.")
48
  return True
49
+
50
+ video_length = int(length_seconds)
51
+
52
+ if video_length > 600:
53
+ print("Your video is longer than 10 minutes")
54
  return True
55
  else:
56
  print("Your video is less than 10 minutes")