Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,9 @@ from moviepy.editor import *
|
|
18 |
from pytube import YouTube
|
19 |
from youtube_transcript_api import YouTubeTranscriptApi
|
20 |
from utils import *
|
21 |
-
|
|
|
|
|
22 |
def download_video(url):
|
23 |
print("Downloading...")
|
24 |
local_file = (
|
@@ -29,33 +31,36 @@ def download_video(url):
|
|
29 |
)
|
30 |
print("Downloaded")
|
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:
|
39 |
return True
|
40 |
|
41 |
-
# Fetch video details
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
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")
|
57 |
return False
|
58 |
-
|
59 |
def validate_url(url):
|
60 |
import validators
|
61 |
if not validators.url(url):
|
@@ -63,8 +68,6 @@ def validate_url(url):
|
|
63 |
return True
|
64 |
else:
|
65 |
return False
|
66 |
-
|
67 |
-
|
68 |
def cleanup():
|
69 |
import pathlib
|
70 |
import glob
|
|
|
18 |
from pytube import YouTube
|
19 |
from youtube_transcript_api import YouTubeTranscriptApi
|
20 |
from utils import *
|
21 |
+
import json
|
22 |
+
import re
|
23 |
+
from pytube import YouTube
|
24 |
def download_video(url):
|
25 |
print("Downloading...")
|
26 |
local_file = (
|
|
|
31 |
)
|
32 |
print("Downloaded")
|
33 |
return local_file
|
|
|
34 |
def validate_youtube(url):
|
|
|
35 |
try:
|
36 |
+
yt = YouTube(url)
|
37 |
except Exception as e:
|
38 |
+
print(f"Invalid URL or network issue: {e}")
|
39 |
return True
|
40 |
|
41 |
+
# Fetch video details using multiple fallback methods
|
42 |
+
try:
|
43 |
+
# Try getting length from `yt.length`
|
44 |
+
video_length = yt.length
|
45 |
+
if video_length is None:
|
46 |
+
raise ValueError("yt.length returned None")
|
47 |
|
48 |
+
except:
|
49 |
+
# Fallback: Extract video details from `yt.watch_html`
|
50 |
+
match = re.search(r'"lengthSeconds":"(\d+)"', yt.watch_html)
|
51 |
+
if match:
|
52 |
+
video_length = int(match.group(1))
|
53 |
+
else:
|
54 |
+
print("Error: Could not retrieve video length.")
|
55 |
+
return True
|
56 |
|
57 |
+
# Check video length limit
|
58 |
if video_length > 600:
|
59 |
print("Your video is longer than 10 minutes")
|
60 |
return True
|
61 |
else:
|
62 |
print("Your video is less than 10 minutes")
|
63 |
return False
|
|
|
64 |
def validate_url(url):
|
65 |
import validators
|
66 |
if not validators.url(url):
|
|
|
68 |
return True
|
69 |
else:
|
70 |
return False
|
|
|
|
|
71 |
def cleanup():
|
72 |
import pathlib
|
73 |
import glob
|