archive-able
This commit is contained in:
parent
017fa799ce
commit
8ea0d542e3
@ -107,7 +107,7 @@ class grab():
|
|||||||
print("Downloaded MP4 but no thumbnail found.")
|
print("Downloaded MP4 but no thumbnail found.")
|
||||||
|
|
||||||
class dropout():
|
class dropout():
|
||||||
def show(show, season, episode_start):
|
def show(show, season, archive, episode_start):
|
||||||
directory = f'/tv/{show}/Season {season}/'
|
directory = f'/tv/{show}/Season {season}/'
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
@ -167,6 +167,8 @@ class dropout():
|
|||||||
'subtitleslangs': ['en'],
|
'subtitleslangs': ['en'],
|
||||||
'outtmpl': filename_template,
|
'outtmpl': filename_template,
|
||||||
}
|
}
|
||||||
|
if archive:
|
||||||
|
dl_opts['skip_download'] = True
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(dl_opts) as ydl:
|
with yt_dlp.YoutubeDL(dl_opts) as ydl:
|
||||||
ydl.download([entry['webpage_url']])
|
ydl.download([entry['webpage_url']])
|
||||||
|
|||||||
66
app/main.py
66
app/main.py
@ -73,7 +73,7 @@ async def ebookDownload(
|
|||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
url: str = Form(...),
|
url: str = Form(...),
|
||||||
author: str = Form(...)
|
author: str = Form(...)
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
background_tasks.add_task(download.ebook,url,author)
|
background_tasks.add_task(download.ebook,url,author)
|
||||||
# download.dropout.show(show,season,episode)
|
# download.dropout.show(show,season,episode)
|
||||||
@ -126,26 +126,64 @@ def get_latest_season(item):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@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 dropout_download(
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
show: str = Form(...),
|
show: str = Form(...),
|
||||||
season: Optional[int] = Form(None),
|
season: Optional[int] = Form(None),
|
||||||
latest: bool = Form(False)
|
latest: bool = Form(False),
|
||||||
):
|
archive: bool = Form(False)
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
if latest is not False and season is None:
|
# Resolve latest season if requested
|
||||||
item = await get_show_data(show,True)
|
if latest and season is None:
|
||||||
if not item:
|
show_data = await get_show_data(show, True)
|
||||||
return JSONResponse(status_code=404, content={"status": "error", "message": "Show not found"})
|
if not show_data:
|
||||||
season = get_latest_season(item)
|
return JSONResponse(
|
||||||
|
status_code=404,
|
||||||
|
content={"status": "error", "message": "Show not found"}
|
||||||
|
)
|
||||||
|
|
||||||
|
season = get_latest_season(show_data)
|
||||||
if season is None:
|
if season is None:
|
||||||
return JSONResponse(status_code=400, content={"status": "error", "message": "No valid seasons found"})
|
return JSONResponse(
|
||||||
logger.info(f'message=Received download request for season {season} of {show}.')
|
status_code=400,
|
||||||
background_tasks.add_task(download.dropout.show, show, season, None)
|
content={"status": "error", "message": "No valid seasons found"}
|
||||||
return JSONResponse(status_code=200, content={"status": "success", "message": f"Series download started for season {season}."})
|
)
|
||||||
|
|
||||||
|
# Ensure season is specified by now
|
||||||
|
if season is None:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=400,
|
||||||
|
content={"status": "error", "message": "Season is required unless 'latest' is used."}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
task_msg = f"{'Adding to archive' if archive else 'Starting download'} for show '{show}', season {season}."
|
||||||
|
logger.info(f"message={task_msg}")
|
||||||
|
|
||||||
|
# Schedule the background task
|
||||||
|
background_tasks.add_task(download.dropout.show, show, season, archive, None)
|
||||||
|
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=200,
|
||||||
|
content={
|
||||||
|
"status": "success",
|
||||||
|
"message": (
|
||||||
|
f"Series is being added to the completed archive for '{show}', season {season}."
|
||||||
|
if archive else
|
||||||
|
f"Series download started for '{show}', season {season}."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
logger.exception(f"Unhandled exception during /dropout/download: {e}")
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=500,
|
||||||
|
content={"status": "error", "message": "An unexpected error occurred."}
|
||||||
|
)
|
||||||
|
|
||||||
@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(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user