Update modules/app.py
Browse files- modules/app.py +21 -2
modules/app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, Request
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
-
from pytubefix import YouTube
|
4 |
-
from pytubefix.exceptions import PytubeFixError
|
5 |
from concurrent.futures import ThreadPoolExecutor
|
|
|
6 |
import asyncio
|
7 |
import aiohttp
|
8 |
import aiofiles
|
@@ -207,6 +206,26 @@ async def get_youtube_audio(request: Request):
|
|
207 |
print(f"An error occurred: {str(e)}")
|
208 |
print(traceback.format_exc())
|
209 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
@app.post("/whisper")
|
212 |
async def whisper(request: Request):
|
|
|
1 |
from fastapi import FastAPI, HTTPException, Request
|
2 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
3 |
from concurrent.futures import ThreadPoolExecutor
|
4 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
5 |
import asyncio
|
6 |
import aiohttp
|
7 |
import aiofiles
|
|
|
206 |
print(f"An error occurred: {str(e)}")
|
207 |
print(traceback.format_exc())
|
208 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
|
209 |
+
|
210 |
+
@app.get("/get_youtube_transcript")
|
211 |
+
async def get_youtube_transcript(request: Request):
|
212 |
+
try:
|
213 |
+
# Get the video ID from the query parameters
|
214 |
+
video_id = request.query_params.get("video_id")
|
215 |
+
if not video_id:
|
216 |
+
raise HTTPException(status_code=400, detail="video_id parameter is required")
|
217 |
+
|
218 |
+
# Get the transcript for the video
|
219 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
220 |
+
|
221 |
+
# Format the transcript into a single string
|
222 |
+
transcript_text = " ".join([i["text"] for i in transcript])
|
223 |
+
|
224 |
+
return {"transcript": transcript_text}
|
225 |
+
except Exception as e:
|
226 |
+
print(f"An error occurred: {str(e)}")
|
227 |
+
print(traceback.format_exc())
|
228 |
+
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
|
229 |
|
230 |
@app.post("/whisper")
|
231 |
async def whisper(request: Request):
|