Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,19 +76,19 @@ class YouTubeTranscriptTool(Tool):
|
|
| 76 |
output_type = "string"
|
| 77 |
|
| 78 |
def forward(self, url: str) -> str:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
|
| 94 |
class FileDownloadTool(Tool):
|
|
|
|
| 76 |
output_type = "string"
|
| 77 |
|
| 78 |
def forward(self, url: str) -> str:
|
| 79 |
+
try:
|
| 80 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 81 |
+
if "v=" in url:
|
| 82 |
+
video_id = url.split("v=")[1].split("&")[0]
|
| 83 |
+
elif "youtu.be/" in url:
|
| 84 |
+
video_id = url.split("youtu.be/")[1].split("?")[0]
|
| 85 |
+
else:
|
| 86 |
+
video_id = url.strip()
|
| 87 |
+
ytt = YouTubeTranscriptApi()
|
| 88 |
+
transcript = ytt.fetch(video_id)
|
| 89 |
+
return " ".join([t.text for t in transcript])[:5000]
|
| 90 |
+
except Exception as e:
|
| 91 |
+
return f"Transcript error: {e}"
|
| 92 |
|
| 93 |
|
| 94 |
class FileDownloadTool(Tool):
|