Update main.py

This commit is contained in:
TylerCG 2025-05-12 17:52:20 -04:00
parent 50890e6dc7
commit b6b76cd9d3

View File

@ -43,29 +43,6 @@ loop = asyncio.get_event_loop()
cached_data = None
async def get_show_data(show: str):
global cached_data
if cached_data is None:
await dropoutUpdate()
for item in cached_data:
if show == item['LINK']:
if "SEASONS" not in item:
item['SEASONS'] = download.grab.season(item['URL'])
return item
return None
def get_latest_season(item):
if item and item.get("SEASONS"):
try:
seasons = item["SEASONS"].keys()
numeric_seasons = [int(s) for s in seasons if str(s).isdigit()]
if numeric_seasons:
return max(numeric_seasons)
except Exception as e:
logger.info(f"Error getting latest season: {e}")
return None
# Middleware
@app.middleware("http")
@ -123,6 +100,29 @@ async def dropoutSeries():
return JSONResponse(content=cached_data)
return JSONResponse(content={"error": "File not found"}, status_code=404)
async def get_show_data(show: str):
global cached_data
if cached_data is None:
await dropoutUpdate()
for item in cached_data:
if show == item['LINK']:
if "SEASONS" not in item:
item['SEASONS'] = download.grab.season(item['URL'])
return item
return None
def get_latest_season(item):
if item and item.get("SEASONS"):
try:
seasons = item["SEASONS"].keys()
numeric_seasons = [int(s) for s in seasons if str(s).isdigit()]
if numeric_seasons:
return max(numeric_seasons)
except Exception as e:
logger.info(f"Error getting latest season: {e}")
return None
@app.post("/dropout/download", description="Download an entire season from episode 1. Ignores behind the scenes and trailers.")
async def dropoutDownload(
background_tasks: BackgroundTasks,
@ -139,12 +139,11 @@ async def dropoutDownload(
if season is None:
return JSONResponse(status_code=400, content={"status": "error", "message": "No valid seasons found"})
background_tasks.add_task(download.dropout.show, show, season, None)
background_tasks.add_task(download.dropout.show, show, season, latest, None)
return JSONResponse(status_code=200, content={"status": "success", "message": f"Series download started for season {season}."})
except Exception as e:
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
@app.post("/dropout/download/specials", description="Downloads a seasons behind the scenes and trailers, ignores main episodes.")
async def dropoutDownload(