ztoolx commited on
Commit
fa29869
·
verified ·
1 Parent(s): 3980cd9

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -4
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=["*"], # In production, you can change "*" to your Vercel URL
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.match(pattern, url)
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!"}