diff --git a/app/download.py b/app/download.py index 7683f2e..0808147 100644 --- a/app/download.py +++ b/app/download.py @@ -1,6 +1,4 @@ -import os, yt_dlp, json, requests, re, time -from selenium import webdriver -from selenium.webdriver.common.keys import Keys +import os, yt_dlp, json, requests, re from bs4 import BeautifulSoup from urllib.parse import urlsplit @@ -178,13 +176,6 @@ class dropout(): def series(): json_data=[] - # driver = webdriver.Chrome(executable_path='/path/to/chromedriver') - # driver.get('https://www.dropout.tv/series') - # for _ in range(5): # Adjust the range as needed - # driver.find_element_by_tag_name('body').send_keys(Keys.END) - # time.sleep(2) # Wait for new content to load - # html = driver.page_source - html=requests.get('https://www.dropout.tv/series').text # If you want to parse the HTML diff --git a/app/main.py b/app/main.py index d26c78e..6f6f440 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ from fastapi import FastAPI, Request, Form from fastapi.responses import HTMLResponse, JSONResponse from fastapi.templating import Jinja2Templates from fastapi.staticfiles import StaticFiles +from fastapi import BackgroundTasks from functools import partial import json, download, asyncio from typing import Optional @@ -40,11 +41,12 @@ async def dropoutSeries(): @app.post("/dropout/download", description="Download an entire season from episode 1. Ignores behind the scenes and trailers.") async def dropoutDownload( + background_tasks: BackgroundTasks, show: str = Form(...), - season: int = Form(...), + season: int = Form(...) ): try: - await loop.run_in_executor(None, partial(download.dropout.show,show,season,None)) + background_tasks.add_task(download.dropout.show,show,season,None) # download.dropout.show(show,season,episode) return JSONResponse(status_code=200, content={"status": "success", "message": "Series downloaded."}) except Exception as e: @@ -52,21 +54,22 @@ async def dropoutDownload( @app.post("/dropout/download/specials", description="Downloads a seasons behind the scenes and trailers, ignores main episodes.") async def dropoutDownload( + background_tasks: BackgroundTasks, show: str = Form(...), season: int = Form(...), episode: Optional[int] = Form(None) ): try: - await loop.run_in_executor(None, partial(download.dropout.specials,show,season,episode)) + background_tasks.add_task(download.dropout.specials,show,season,episode) # download.dropout.show(show,season,episode) return JSONResponse(status_code=200, content={"status": "success", "message": "Series downloaded."}) except Exception as e: return JSONResponse(status_code=500, content={"status": "error", "message": str(e)}) @app.post("/ydl") -async def ydl(url: str = Form(...), location: str = Form(...)): +async def ydl(background_tasks: BackgroundTasks, url: str = Form(...), location: str = Form(...)): try: - await loop.run_in_executor(None, partial(download.youtube.ydl, url, location)) + background_tasks.add_task(download.youtube.ydl, url, location) # download.youtube.ydl(url,location) # grab.thumbnail(ydl,url,location) return JSONResponse(status_code=200, content={"status": "success", "message": "Video download completed."}) @@ -93,8 +96,9 @@ async def index(request: Request, show = str): try: for item in cached_data: if show == item['LINK']: - show_data = item - return templates.TemplateResponse("show.html", {"request": request, "show": show_data}) + 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: diff --git a/app/templates/show.html b/app/templates/show.html index ec93488..99bdff4 100644 --- a/app/templates/show.html +++ b/app/templates/show.html @@ -3,32 +3,86 @@