Spaces:
Sleeping
Sleeping
File size: 1,178 Bytes
5d322d8 093a866 5d322d8 c2eed51 093a866 4bfa0b3 093a866 5d322d8 093a866 d8804e5 5d322d8 d8804e5 ba9fae4 d8804e5 5d322d8 d8804e5 ba9fae4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import os
from fastapi import FastAPI, Header, Request
from fastapi.responses import JSONResponse
from typing import Annotated
from fetchYoutubeSubtitle import fetchSubtitle, fetchSubtitleUrls
token = os.getenv("HF_X_TOKEN")
app = FastAPI()
@app.get("/")
def read_root(request:Request):
print(request.headers)
print(request.client.host)
print(request.client.port)
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", lang:str='en', proxy: str=None, x_token: Annotated[str | None, Header()] = None):
if token != x_token:
return JSONResponse({"error": "Invalid token"})
subtitle = await fetchSubtitle(url, lang=lang, subType=subtype, proxy=proxy)
return JSONResponse(content=subtitle)
@app.get("/subtitle-urls/")
async def get_subtitleUrls(url: str, proxy: str=None, x_token: Annotated[str | None, Header()] = None):
if token != x_token:
return JSONResponse({"error": "Invalid token"})
subtitles = await fetchSubtitleUrls(url, proxy=proxy)
return JSONResponse(content=subtitles) |