Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,36 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import re
|
| 4 |
-
from fastapi import FastAPI
|
| 5 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
-
|
| 7 |
-
# Gradio + FastAPI backend
|
| 8 |
-
app = FastAPI(title="Catbox Raw File Extractor API")
|
| 9 |
-
|
| 10 |
-
# Allow all origins (for frontend)
|
| 11 |
-
app.add_middleware(
|
| 12 |
-
CORSMiddleware,
|
| 13 |
-
allow_origins=["*"],
|
| 14 |
-
allow_methods=["*"],
|
| 15 |
-
allow_headers=["*"],
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
def get_direct_link(catbox_url: str):
|
| 19 |
-
"""Extract direct raw file from a Catbox/Litterbox URL"""
|
| 20 |
-
if not catbox_url.startswith("http"):
|
| 21 |
-
return {"ok": False, "error": "Invalid URL"}
|
| 22 |
-
|
| 23 |
-
# If it already ends with a raw file extension, return as-is
|
| 24 |
-
if re.search(r'\.(mp4|png|jpg|jpeg|gif|webm)$', catbox_url, re.IGNORECASE):
|
| 25 |
-
return {"ok": True, "direct_link": catbox_url}
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
# app.py
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import yt_dlp
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def download_anime(url, ep_start=1, ep_end=None):
|
| 8 |
+
ydl_opts = {
|
| 9 |
+
'format': 'best',
|
| 10 |
+
'outtmpl': '%(title)s - Episode %(episode_num)02d.%(ext)s',
|
| 11 |
+
'quiet': False,
|
| 12 |
+
'no_warnings': False,
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if ep_end:
|
| 16 |
+
ydl_opts['playliststart'] = ep_start
|
| 17 |
+
ydl_opts['playlistend'] = ep_end
|
| 18 |
+
|
| 19 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 20 |
+
try:
|
| 21 |
+
info = ydl.extract_info(url, download=True)
|
| 22 |
+
title = info.get('title', 'Unknown')
|
| 23 |
+
return f"Downloaded: {title}"
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"Error: {str(e)}"
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("# Anime Downloader (yt-dlp)")
|
| 29 |
+
url = gr.Textbox(label="Anime Page URL (e.g., animewave episode or series)")
|
| 30 |
+
start = gr.Number(label="Start Episode", value=1, precision=0)
|
| 31 |
+
end = gr.Number(label="End Episode (optional)", value=None)
|
| 32 |
+
btn = gr.Button("Download")
|
| 33 |
+
output = gr.Textbox(label="Status")
|
| 34 |
+
btn.click(download_anime, inputs=[url, start, end], outputs=output)
|
| 35 |
+
|
| 36 |
+
demo.launch()
|