INNER CODE UNIT · Python
api_sub
xcodian/youtube-dl-web · server/src/server.py:78
async def api_sub(background_tasks: BackgroundTasks, video_id: str, l: str = "en", f: str = "vtt"):
if f not in ["vtt", "ass", "srt"] and not (l == "live_chat" and f == "json"):
raise HTTPException(
status_code=400,
detail="Invalid subtitle format, valid options are: vtt, ass, srt"
)
sub_file = download_subs(video_id, l, f)
background_tasks.add_task(_remove_file, sub_file)
return FileResponse(
sub_file,
filename=f"{video_id}.{l}.{f}"
)