lanbogao's picture
Add get subtitle with type support.
d030b89
raw
history blame
639 Bytes
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fetchYoutubeSubtitle import fetchSubtitle, fetchSubtitleUrls
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World!"}
@app.get("/json")
def read_json():
return JSONResponse(content={"Hello": "World!"})
@app.get("/subtitle/")
async def get_subtitle(url: str, subtype: str="srt"):
subtitle = await fetchSubtitle(url,subType=subtype)
return JSONResponse(content=subtitle)
@app.get("/subtitle-urls/")
async def get_subtitleUrls(url: str):
subtitles = await fetchSubtitleUrls(url)
return JSONResponse(content=subtitles)