Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -8,15 +8,16 @@ app = FastAPI()
|
|
| 8 |
# Enable CORS so your Vercel frontend can call this API
|
| 9 |
app.add_middleware(
|
| 10 |
CORSMiddleware,
|
| 11 |
-
allow_origins=["*"],
|
| 12 |
allow_credentials=True,
|
| 13 |
allow_methods=["*"],
|
| 14 |
allow_headers=["*"],
|
| 15 |
)
|
| 16 |
|
| 17 |
def extract_video_id(url: str) -> str:
|
|
|
|
| 18 |
pattern = r'(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})'
|
| 19 |
-
match = re.
|
| 20 |
if match:
|
| 21 |
return match.group(1)
|
| 22 |
return None
|
|
@@ -69,9 +70,7 @@ async def get_transcript(request: dict):
|
|
| 69 |
except Exception as e:
|
| 70 |
raise HTTPException(status_code=500, detail=f"Failed to fetch transcript: {str(e)}")
|
| 71 |
|
| 72 |
-
# ========================================================
|
| 73 |
# KEEP-ALIVE ENDPOINT
|
| 74 |
-
# ========================================================
|
| 75 |
@app.get("/api/health")
|
| 76 |
async def health_check():
|
| 77 |
return {"status": "ok", "message": "Transcript API is running!"}
|
|
|
|
| 8 |
# Enable CORS so your Vercel frontend can call this API
|
| 9 |
app.add_middleware(
|
| 10 |
CORSMiddleware,
|
| 11 |
+
allow_origins=["*"],
|
| 12 |
allow_credentials=True,
|
| 13 |
allow_methods=["*"],
|
| 14 |
allow_headers=["*"],
|
| 15 |
)
|
| 16 |
|
| 17 |
def extract_video_id(url: str) -> str:
|
| 18 |
+
# The fix: Changed re.match to re.search so it finds the ID even with https:// in front
|
| 19 |
pattern = r'(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})'
|
| 20 |
+
match = re.search(pattern, url)
|
| 21 |
if match:
|
| 22 |
return match.group(1)
|
| 23 |
return None
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
raise HTTPException(status_code=500, detail=f"Failed to fetch transcript: {str(e)}")
|
| 72 |
|
|
|
|
| 73 |
# KEEP-ALIVE ENDPOINT
|
|
|
|
| 74 |
@app.get("/api/health")
|
| 75 |
async def health_check():
|
| 76 |
return {"status": "ok", "message": "Transcript API is running!"}
|