Neon-AI commited on
Commit
e2d0f6c
·
verified ·
1 Parent(s): d346a0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -49
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
- # Otherwise, try to fetch page and extract
28
- try:
29
- r = requests.get(catbox_url, timeout=10)
30
- r.raise_for_status()
31
- text = r.text
32
-
33
- match = re.search(r'src="([^"]+\.(mp4|png|jpg|jpeg|gif|webm))"', text, re.IGNORECASE)
34
- if match:
35
- return {"ok": True, "direct_link": match.group(1)}
36
- else:
37
- return {"ok": False, "error": "Could not find raw file link"}
38
- except Exception as e:
39
- return {"ok": False, "error": str(e)}
40
-
41
- # Gradio API interface
42
- with gr.Blocks(server_name="0.0.0.0") as demo:
43
- gr.Markdown("## Catbox / Litterbox Raw File Extractor API")
44
- input_url = gr.Textbox(label="Paste Catbox/Litterbox URL")
45
- output_json = gr.JSON(label="API Response")
46
- extract_btn = gr.Button("Get Direct Link")
47
- extract_btn.click(fn=get_direct_link, inputs=input_url, outputs=output_json)
48
-
49
- # Mount Gradio app onto FastAPI
50
- app = gr.mount_gradio_app(app, demo, path="/api")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()