63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse, JSONResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
# from fastapi.staticfiles import StaticFiles
|
|
# from fastapi.concurrency import run_in_threadpool
|
|
from pathlib import Path
|
|
from functools import partial
|
|
import json, download, asyncio
|
|
|
|
app = FastAPI()
|
|
|
|
# app.mount("/static", StaticFiles(directory="/app/app/static"), name="static")
|
|
templates = Jinja2Templates(directory="templates")
|
|
loop = asyncio.get_running_loop()
|
|
|
|
|
|
# api
|
|
@app.get("/dropoutUpdate")
|
|
async def dropoutUpdate():
|
|
try:
|
|
download.dropout.series()
|
|
return JSONResponse(status_code=200, content={"status": "success", "message": "Series grab complete."})
|
|
except Exception as e:
|
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
|
|
|
@app.get("/dropoutSeries")
|
|
async def dropoutSeries():
|
|
file_path = Path("/data/dropout.json")
|
|
if file_path.exists():
|
|
with file_path.open("r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
return JSONResponse(content=data)
|
|
return JSONResponse(content={"error": "File not found"}, status_code=404)
|
|
|
|
@app.post("/dropoutDownload")
|
|
async def dropoutDownload(show: str, season: str, episode: str = None):
|
|
try:
|
|
await loop.run_in_executor(None, partial(download.dropout.show,show,season,episode))
|
|
# download.dropout.show(show,season,episode)
|
|
return JSONResponse(status_code=200, content={"status": "success", "message": "Series downloading."})
|
|
except Exception as e:
|
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
|
|
|
@app.post("/ydl")
|
|
async def ydl(url: str, location: str):
|
|
try:
|
|
await loop.run_in_executor(None, partial(download.youtube.ydl, url, location))
|
|
# download.youtube.ydl(url,location)
|
|
# grab.thumbnail(ydl,url,location)
|
|
return JSONResponse(status_code=200, content={"status": "success", "message": "Video download completed."})
|
|
except Exception as e:
|
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
|
|
|
# html
|
|
@app.get("/", include_in_schema=False, response_class=HTMLResponse)
|
|
async def index(request: Request):
|
|
apps = [
|
|
{"name": "Notes", "url": "/notes"},
|
|
{"name": "Todo List", "url": "/todos"},
|
|
{"name": "Weather", "url": "/weather"},
|
|
# Add more apps here
|
|
]
|
|
return templates.TemplateResponse("index.html", {"request": request, "apps": apps, "title": "Welcome to My App Hub"}) |