Spaces:
Runtime error
Runtime error
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() | |
def read_root(request:Request): | |
print(request.headers) | |
print(request.client.host) | |
print(request.client.port) | |
return {"Hello": "World!"} | |
def read_json(): | |
return JSONResponse(content={"Hello": "World!"}) | |
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) | |
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) |