added custom download
This commit is contained in:
parent
9e1c32a123
commit
6b32f18ad5
@ -88,7 +88,6 @@ class grab():
|
||||
|
||||
return filepath
|
||||
|
||||
|
||||
def thumbnail(ydl,url,location):
|
||||
# Extracting video information
|
||||
video_info = ydl.extract_info(url, download=False)
|
||||
@ -133,6 +132,28 @@ class dropout():
|
||||
|
||||
with ArchiveOnlyYDL(dl_opts) as ydl:
|
||||
ydl.download([playlist_url])
|
||||
|
||||
def custom(url, directory, prefix):
|
||||
filename_template = f"{prefix}%(title)s.%(ext)s" if prefix else "%(title)s.%(ext)s"
|
||||
|
||||
dl_opts = {
|
||||
'progress_hooks': [my_hook],
|
||||
'download_archive': '/data/logs/dropout.archive.log',
|
||||
'format': 'bestvideo+bestaudio/best',
|
||||
'audio_quality': '256K',
|
||||
'paths': {
|
||||
'temp': '/temp',
|
||||
'home': directory,
|
||||
},
|
||||
'cookiefile': '/data/dropout.cookies.txt',
|
||||
'writesubtitles': True,
|
||||
'subtitleslangs': ['en'],
|
||||
'outtmpl': filename_template,
|
||||
}
|
||||
|
||||
with yt_dlp.YoutubeDL(dl_opts) as ydl:
|
||||
ydl.download([url] if isinstance(url, str) else url)
|
||||
|
||||
|
||||
def show(show, season, specials=False, episode_start=None):
|
||||
season_str = f"{int(season):02}" if not specials else "00"
|
||||
@ -196,7 +217,6 @@ class dropout():
|
||||
with yt_dlp.YoutubeDL(dl_opts) as ydl:
|
||||
ydl.download([entry['webpage_url']])
|
||||
|
||||
|
||||
def series(force_download):
|
||||
json_data=[]
|
||||
html=requests.get('https://www.dropout.tv/series').text
|
||||
|
||||
53
app/main.py
53
app/main.py
@ -23,8 +23,8 @@ logger.handlers = []
|
||||
handler = TimedRotatingFileHandler(
|
||||
filename="/data/logs/syllabus.log",
|
||||
when="midnight", # Rotate at midnight
|
||||
interval=1, # Every 1 day
|
||||
backupCount=30, # Keep last 7 logs
|
||||
interval=30, # Every 30 day
|
||||
backupCount=12, # Keep last 7 logs
|
||||
encoding="utf-8",
|
||||
utc=False # Use UTC for time reference
|
||||
)
|
||||
@ -68,18 +68,19 @@ async def log_requests(request: Request, call_next):
|
||||
|
||||
|
||||
# api
|
||||
@app.post("/ebook/download", description="Download an ebook via a url.")
|
||||
async def ebookDownload(
|
||||
background_tasks: BackgroundTasks,
|
||||
url: str = Form(...),
|
||||
author: str = Form(...)
|
||||
):
|
||||
try:
|
||||
background_tasks.add_task(download.ebook,url,author)
|
||||
# download.dropout.show(show,season,episode)
|
||||
return JSONResponse(status_code=200, content={"status": "success", "message": "Book downloaded."})
|
||||
except Exception as e:
|
||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||
|
||||
# @app.post("/ebook/download", description="Download an ebook via a url.")
|
||||
# async def ebookDownload(
|
||||
# background_tasks: BackgroundTasks,
|
||||
# url: str = Form(...),
|
||||
# author: str = Form(...)
|
||||
# ):
|
||||
# try:
|
||||
# background_tasks.add_task(download.ebook,url,author)
|
||||
# # download.dropout.show(show,season,episode)
|
||||
# return JSONResponse(status_code=200, content={"status": "success", "message": "Book downloaded."})
|
||||
# except Exception as e:
|
||||
# return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||
|
||||
@app.get("/dropout/update")
|
||||
async def dropoutUpdate(force: bool = False):
|
||||
@ -125,12 +126,28 @@ def get_latest_season(item):
|
||||
logging.error(f"Error getting latest season: {e}")
|
||||
return None
|
||||
|
||||
@app.post("/dropout/custom", description="")
|
||||
async def dropout_download(
|
||||
background_tasks: BackgroundTasks,
|
||||
url: str = Form(...),
|
||||
directory: Optional[int] = Form(None),
|
||||
prefix: Optional[str] = Form(None)
|
||||
):
|
||||
# Ensure output directory exists
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
try:
|
||||
background_tasks.add_task(download.dropout.custom, url, directory, prefix)
|
||||
return {"status": "success", "message": "Download started"}
|
||||
except Exception as e:
|
||||
raise JSONResponse(status_code=500, content=f"Download failed: {str(e)}")
|
||||
|
||||
@app.post("/dropout/download", description="Download an entire season from episode 1. Ignores behind the scenes and trailers.")
|
||||
async def dropout_download(
|
||||
background_tasks: BackgroundTasks,
|
||||
show: str = Form(...),
|
||||
season: Optional[int] = Form(None),
|
||||
latest: bool = Form(False),
|
||||
latest: bool = Form(True),
|
||||
archive: bool = Form(False),
|
||||
specials: bool = Form(False),
|
||||
episode_start: Optional[int] = Form(None)
|
||||
@ -172,11 +189,7 @@ async def dropout_download(
|
||||
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}{' specials' if specials else ''}."
|
||||
)
|
||||
"message": (task_msg)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user