ebook add

This commit is contained in:
TylerCG 2025-04-30 22:08:13 -04:00
parent 2c7a3cf605
commit f02582b835
2 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,28 @@ import os, yt_dlp, json, requests, re
from bs4 import BeautifulSoup
from urllib.parse import urlsplit
def ebook(url, author):
destination = f"/ebooks/{author}"
os.makedirs(destination, exist_ok=True) # Create the folder if it doesn't exist
response = requests.get(url, stream=True)
response.raise_for_status() # Good practice to raise error on bad status
# Try to extract filename from the headers
cd = response.headers.get('Content-Disposition')
if cd and 'filename=' in cd:
filename = cd.split('filename=')[1].strip('";')
else:
# Fallback: get the last part of the URL
filename = os.path.basename(url)
file_path = os.path.join(destination, filename)
with open(file_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
class grab():
def season(url):
page_html=requests.get(url)

View File

@ -20,6 +20,19 @@ loop = asyncio.get_running_loop()
cached_data = None
# 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.get("/dropout/update")
async def dropoutUpdate(force: bool = False):
global cached_data