added latest season support
This commit is contained in:
parent
31bd8871b4
commit
50890e6dc7
@ -7,7 +7,7 @@ logger = logging.getLogger("syllabus")
|
|||||||
# Global or outer-scope tracking dictionary
|
# Global or outer-scope tracking dictionary
|
||||||
last_logged_percent = {}
|
last_logged_percent = {}
|
||||||
|
|
||||||
def my_hook(d):
|
def my_hook(d): #logging hook
|
||||||
status = d.get('status')
|
status = d.get('status')
|
||||||
filename = d.get('filename')
|
filename = d.get('filename')
|
||||||
|
|
||||||
@ -39,26 +39,26 @@ def my_hook(d):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ebook(url, author):
|
# def ebook(url, author):
|
||||||
destination = f"/ebooks/{author}"
|
# destination = f"/ebooks/{author}"
|
||||||
os.makedirs(destination, exist_ok=True) # Create the folder if it doesn't exist
|
# os.makedirs(destination, exist_ok=True) # Create the folder if it doesn't exist
|
||||||
|
|
||||||
response = requests.get(url, stream=True)
|
# response = requests.get(url, stream=True)
|
||||||
response.raise_for_status() # Good practice to raise error on bad status
|
# response.raise_for_status() # Good practice to raise error on bad status
|
||||||
|
|
||||||
# Try to extract filename from the headers
|
# # Try to extract filename from the headers
|
||||||
cd = response.headers.get('Content-Disposition')
|
# cd = response.headers.get('Content-Disposition')
|
||||||
if cd and 'filename=' in cd:
|
# if cd and 'filename=' in cd:
|
||||||
filename = cd.split('filename=')[1].strip('";')
|
# filename = cd.split('filename=')[1].strip('";')
|
||||||
else:
|
# else:
|
||||||
# Fallback: get the last part of the URL
|
# # Fallback: get the last part of the URL
|
||||||
filename = os.path.basename(url)
|
# filename = os.path.basename(url)
|
||||||
|
|
||||||
file_path = os.path.join(destination, filename)
|
# file_path = os.path.join(destination, filename)
|
||||||
|
|
||||||
with open(file_path, 'wb') as f:
|
# with open(file_path, 'wb') as f:
|
||||||
for chunk in response.iter_content(chunk_size=8192):
|
# for chunk in response.iter_content(chunk_size=8192):
|
||||||
f.write(chunk)
|
# f.write(chunk)
|
||||||
|
|
||||||
class grab():
|
class grab():
|
||||||
def season(url):
|
def season(url):
|
||||||
|
|||||||
74
app/main.py
74
app/main.py
@ -42,6 +42,31 @@ loop = asyncio.get_event_loop()
|
|||||||
# Optional cache
|
# Optional cache
|
||||||
cached_data = None
|
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
|
# Middleware
|
||||||
@app.middleware("http")
|
@app.middleware("http")
|
||||||
async def log_requests(request: Request, call_next):
|
async def log_requests(request: Request, call_next):
|
||||||
@ -60,7 +85,11 @@ async def log_requests(request: Request, call_next):
|
|||||||
f"status_code={response.status_code}"
|
f"status_code={response.status_code}"
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# api
|
# api
|
||||||
@app.post("/ebook/download", description="Download an ebook via a url.")
|
@app.post("/ebook/download", description="Download an ebook via a url.")
|
||||||
async def ebookDownload(
|
async def ebookDownload(
|
||||||
@ -96,17 +125,26 @@ async def dropoutSeries():
|
|||||||
|
|
||||||
@app.post("/dropout/download", description="Download an entire season from episode 1. Ignores behind the scenes and trailers.")
|
@app.post("/dropout/download", description="Download an entire season from episode 1. Ignores behind the scenes and trailers.")
|
||||||
async def dropoutDownload(
|
async def dropoutDownload(
|
||||||
# request: Request,
|
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
show: str = Form(...),
|
show: str = Form(...),
|
||||||
season: int = Form(...)
|
season: Optional[int] = Form(None),
|
||||||
):
|
latest: bool = Form(False)
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
background_tasks.add_task(download.dropout.show,show,season,None)
|
if latest is not False and season is None:
|
||||||
# download.dropout.show(show,season,episode)
|
item = await get_show_data(show)
|
||||||
return JSONResponse(status_code=200, content={"status": "success", "message": "Series downloaded."})
|
if not item:
|
||||||
|
return JSONResponse(status_code=404, content={"status": "error", "message": "Show not found"})
|
||||||
|
season = get_latest_season(item)
|
||||||
|
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)
|
||||||
|
return JSONResponse(status_code=200, content={"status": "success", "message": f"Series download started for season {season}."})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(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.")
|
@app.post("/dropout/download/specials", description="Downloads a seasons behind the scenes and trailers, ignores main episodes.")
|
||||||
async def dropoutDownload(
|
async def dropoutDownload(
|
||||||
@ -132,6 +170,10 @@ async def ydl(background_tasks: BackgroundTasks, url: str = Form(...), location:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#web ui
|
#web ui
|
||||||
@app.get("/", include_in_schema=False, response_class=HTMLResponse)
|
@app.get("/", include_in_schema=False, response_class=HTMLResponse)
|
||||||
async def index(request: Request):
|
async def index(request: Request):
|
||||||
@ -144,19 +186,13 @@ async def index(request: Request):
|
|||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||||
|
|
||||||
@app.get("/show/{show}", include_in_schema=False, response_class=HTMLResponse)
|
@app.get("/show/{show}", include_in_schema=False, response_class=HTMLResponse)
|
||||||
async def index(request: Request, show = str):
|
async def index(request: Request, show: str):
|
||||||
try:
|
try:
|
||||||
global cached_data
|
item = await get_show_data(show)
|
||||||
if cached_data is None:
|
if item:
|
||||||
await dropoutUpdate()
|
return templates.TemplateResponse("show.html", {"request": request, "show": item})
|
||||||
try:
|
else:
|
||||||
for item in cached_data:
|
return JSONResponse(status_code=404, content={"status": "error", "message": "Show not found"})
|
||||||
if show == item['LINK']:
|
|
||||||
if "SEASONS" not in item:
|
|
||||||
item['SEASONS'] = download.grab.season(item['URL'])
|
|
||||||
return templates.TemplateResponse("show.html", {"request": request, "show": item})
|
|
||||||
except Exception as e:
|
|
||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user