Ubuntu
commited on
Commit
·
e7a545f
1
Parent(s):
71333d0
update downloading
Browse files
app.py
CHANGED
@@ -11,8 +11,16 @@ from pydub import AudioSegment # Import AudioSegment
|
|
11 |
API_URL = "http://astarwiz.com:9998"
|
12 |
rapid_key = os.environ.get("RAPID_API_KEY")
|
13 |
|
14 |
-
def
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
if output_dir is None:
|
18 |
output_dir = tempfile.gettempdir()
|
@@ -29,7 +37,7 @@ def download_youtube_audio(metadata, output_dir: Optional[str] = None) -> str:
|
|
29 |
'x-rapidapi-key': rapid_key # Replace <key> with your actual API key
|
30 |
}
|
31 |
data = {
|
32 |
-
"url":
|
33 |
}
|
34 |
|
35 |
response = requests.post(url, headers=headers, json=data)
|
@@ -89,16 +97,7 @@ def run_asr(audio_file, youtube_url):
|
|
89 |
def embed_youtube(youtube_url):
|
90 |
if youtube_url:
|
91 |
try:
|
92 |
-
|
93 |
-
print('short' in youtube_url)
|
94 |
-
print('v=' in youtube_url)
|
95 |
-
if 'v=' in youtube_url:
|
96 |
-
video_id = youtube_url.split("v=")[1]
|
97 |
-
elif 'shorts' in youtube_url:
|
98 |
-
video_id = youtube_url.split("/")[-1]
|
99 |
-
else:
|
100 |
-
raise Exception("Unsupported URL format")
|
101 |
-
print(video_id)
|
102 |
embed_html = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'
|
103 |
return gr.update(value=embed_html, visible=True), "", None
|
104 |
except Exception as e:
|
|
|
11 |
API_URL = "http://astarwiz.com:9998"
|
12 |
rapid_key = os.environ.get("RAPID_API_KEY")
|
13 |
|
14 |
+
def fetch_youtube_id(youtube_url: str) -> str:
|
15 |
+
if 'v=' in youtube_url:
|
16 |
+
return youtube_url.split("v=")[1]
|
17 |
+
elif 'shorts' in youtube_url:
|
18 |
+
return youtube_url.split("/")[-1]
|
19 |
+
else:
|
20 |
+
raise Exception("Unsupported URL format")
|
21 |
+
|
22 |
+
def download_youtube_audio(youtube_url: str, output_dir: Optional[str] = None) -> str:
|
23 |
+
video_id = fetch_youtube_id(youtube_url)
|
24 |
|
25 |
if output_dir is None:
|
26 |
output_dir = tempfile.gettempdir()
|
|
|
37 |
'x-rapidapi-key': rapid_key # Replace <key> with your actual API key
|
38 |
}
|
39 |
data = {
|
40 |
+
"url": youtube_url
|
41 |
}
|
42 |
|
43 |
response = requests.post(url, headers=headers, json=data)
|
|
|
97 |
def embed_youtube(youtube_url):
|
98 |
if youtube_url:
|
99 |
try:
|
100 |
+
video_id = fetch_youtube_id(youtube_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
embed_html = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'
|
102 |
return gr.update(value=embed_html, visible=True), "", None
|
103 |
except Exception as e:
|