From 082576061ec2a6951c0ba53f6d1c8e3087d94c60 Mon Sep 17 00:00:00 2001 From: TylerCG <117808427+TylerCG@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:04:37 -0400 Subject: [PATCH] Fixes --- .gitignore | 5 +++-- Dockerfile | 5 +++-- app/download.py | 42 +++++++++++++++++++++++++++++++++++------- app/main.py | 13 +++++++++---- dropout_cookies.txt | 6 ------ 5 files changed, 50 insertions(+), 21 deletions(-) delete mode 100644 dropout_cookies.txt diff --git a/.gitignore b/.gitignore index 93c2964..8513340 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__ -.DS_Store data/* # macOS -.DS_Store \ No newline at end of file +.DS_Store + +dropout_cookies.txt \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ff4372f..f23d43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,8 @@ FROM python:3.11-slim # Install ffmpeg and other dependencies RUN apt-get update && apt-get install -y \ ffmpeg \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && pip install yt_dlp # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 @@ -13,7 +14,7 @@ ENV PYTHONUNBUFFERED=1 # Set work directory WORKDIR /app -RUN mkdir /data /tv /youtube /asmr /nsfw /temp +RUN mkdir /app/data /app/tv /app/youtube /app/asmr /app/nsfw /app/temp # Install dependencies COPY requirements.txt . diff --git a/app/download.py b/app/download.py index 4dddb98..1aa387a 100644 --- a/app/download.py +++ b/app/download.py @@ -56,7 +56,7 @@ class dropout(): 'temp': '/temp', 'home': directory }, - 'cookiefile': '/data/dropout_cookies.txt', + 'cookiefile': '/data/dropout.cookies.txt', 'reject_title': [ r'(?i).*behind.?the.?scenes.*', # Reject titles with "behind the scenes" (case-insensitive) r'(?i).*trailer.*', # Reject titles with "trailer" (case-insensitive) @@ -100,7 +100,7 @@ class dropout(): class youtube(): def ydl(url, location): dl_ops = {'paths': {'temp': '/temp', 'home': location}, 'outtmpl': '%(uploader)s/%(title)s.%(ext)s'} - if location == "/podcasts": + if dl_ops['paths']['home'] == '/podcasts': dl_ops['format'] = 'bestaudio/best[ext=mp3]' dl_ops['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', @@ -110,7 +110,7 @@ class youtube(): 'key': 'FFmpegMetadata', 'add_metadata': True, }] - elif location == "/asmr": + elif dl_ops['paths']['home'] == '/asmr': dl_ops['format'] = 'bestaudio/best[ext=mp3]' dl_ops['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', @@ -120,14 +120,42 @@ class youtube(): 'key': 'FFmpegMetadata', 'add_metadata': True, }] - elif location == "/nsfw": + elif dl_ops['paths']['home'] == '/youtube': + dl_ops['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best' + dl_ops['cookiefile'] = '/data/youtube.cookies.txt' + else: dl_ops['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best' + with yt_dlp.YoutubeDL(dl_ops) as ydl: + ydl.download([url]) + # grab.thumbnail(ydl,url,location) + + def downloadOptions(dl_ops): + if dl_ops['paths']['home'] == "/podcasts": + dl_ops['format'] = 'bestaudio/best[ext=mp3]' + dl_ops['postprocessors'] = [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }, { + 'key': 'FFmpegMetadata', + 'add_metadata': True, + }] + elif dl_ops['paths']['home'] == "/asmr": + dl_ops['format'] = 'bestaudio/best[ext=mp3]' + dl_ops['postprocessors'] = [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }, { + 'key': 'FFmpegMetadata', + 'add_metadata': True, + }] + elif dl_ops['paths']['home'] == "/nsfw": + dl_ops['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best' else: dl_ops = { 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', } - with yt_dlp.YoutubeDL(dl_ops) as ydl: - ydl.download([url]) - # grab.thumbnail(ydl,url,location) \ No newline at end of file + return dl_ops \ No newline at end of file diff --git a/app/main.py b/app/main.py index 019be21..f140460 100644 --- a/app/main.py +++ b/app/main.py @@ -4,12 +4,14 @@ from fastapi.templating import Jinja2Templates # from fastapi.staticfiles import StaticFiles # from fastapi.concurrency import run_in_threadpool from pathlib import Path -import json, download +from functools import partial +import json, download, asyncio app = FastAPI() # app.mount("/static", StaticFiles(directory="/app/app/static"), name="static") templates = Jinja2Templates(directory="templates") +loop = asyncio.get_running_loop() # api @@ -33,7 +35,8 @@ async def dropoutSeries(): @app.post("/dropoutDownload") async def dropoutDownload(show: str, season: str, episode: str = None): try: - download.dropout.show(show,season,episode) + await loop.run_in_executor(None, partial(download.dropout.show,show,season,episode)) + # download.dropout.show(show,season,episode) return JSONResponse(status_code=200, content={"status": "success", "message": "Series downloading."}) except Exception as e: return JSONResponse(status_code=500, content={"status": "error", "message": str(e)}) @@ -41,8 +44,10 @@ async def dropoutDownload(show: str, season: str, episode: str = None): @app.post("/ydl") async def ydl(url: str, location: str): try: - download.youtube.ydl(url,location) - return JSONResponse(status_code=200, content={"status": "success", "message": "Download completed."}) + await loop.run_in_executor(None, partial(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."}) except Exception as e: return JSONResponse(status_code=500, content={"status": "error", "message": str(e)}) diff --git a/dropout_cookies.txt b/dropout_cookies.txt deleted file mode 100644 index ea1b69a..0000000 --- a/dropout_cookies.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Netscape HTTP Cookie File -# This file is generated by yt-dlp. Do not edit. - -www.dropout.tv FALSE / FALSE 2376616194 locale_det en -.dropout.tv TRUE / TRUE 1777000194 _session UElXTTdFemwzenp3RTZPQWx6clJwN3d4WlFkaEV0SXVrd2tnMUNUazJQVldOZEVlVTNOS0ZXS2twUmFHczBuMUlSZXVmTmZIeEFUeFZlajVLRVhrT0VVcm9XYU1jMUZQcTQwQUJNUUhtZ091NWZGS0kwYkMyNmZQelkxbll2QmxXYTFwZlJKNVlmdXFnZkcrVVdld3FCaFB4QnJGb2FLTWxyNlBnOFNCSkNLd1EvTS9OaE1nbTgrcjNmSmR6bE9YLS11M2pSa2VBLzZNZkozeXBXWGF4amhRPT0%3D--9ff14eeca357a6d7d1e8eb3496b039a01b2f92ab -.www.dropout.tv TRUE / TRUE 1745465994 __cf_bm d9dI.ZmTB7AOvOULLAi6gzGen4gtP_wncSkUXNYGV18-1745464194-1.0.1.1-XU86MNGfB8sthsX_dgFr7z0XBFSuYt7yiI60jsNbL2WbD.SbKI57sVTLGBl8xYhDiD.bBN7pJRYJjKXKsn80n8C8RujDnn_55c_6rxwvcoo_pbexZbMpHbzcjc_SHxKH