Spaces:
Paused
Paused
Commit
·
c9f8e3c
1
Parent(s):
a6e6b00
add cors
Browse files- README.md +292 -12
- app.py +2 -0
- hf_scrapper.py +6 -6
- requirements.txt +1 -4
README.md
CHANGED
|
@@ -11,18 +11,298 @@ pinned: false
|
|
| 11 |
|
| 12 |
|
| 13 |
## Scripts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
### hf_scrapper.py -> script for interacting with huggingface
|
| 17 |
-
### indexer.py script to index the repo structure
|
| 18 |
-
### tvdb.py script to interact with TheTVDB
|
| 19 |
|
| 20 |
-
##
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
## Scripts
|
| 14 |
+
```
|
| 15 |
+
app.py -> main script that run flask server
|
| 16 |
+
hf_scrapper.py -> script for interacting with huggingface
|
| 17 |
+
indexer.py -> script to index the repo structure
|
| 18 |
+
tvdb.py -> script to interact with TheTVDB
|
| 19 |
+
```
|
| 20 |
+
## Film and TV API
|
| 21 |
|
| 22 |
+
This API provides endpoints for accessing and managing film and TV show data, including downloading, caching, and retrieving metadata.
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
## Table of Contents
|
| 25 |
|
| 26 |
+
|
| 27 |
+
- [Base URL](#base-url)
|
| 28 |
+
- [Endpoints](#endpoints)
|
| 29 |
+
- [Film Endpoints](#film-endpoints)
|
| 30 |
+
- [TV Show Endpoints](#tv-show-endpoints)
|
| 31 |
+
- [Cache Endpoints](#cache-endpoints)
|
| 32 |
+
- [Metadata Endpoints](#metadata-endpoints)
|
| 33 |
+
- [Miscellaneous Endpoints](#miscellaneous-endpoints)
|
| 34 |
+
- [Error Handling](#error-handling)
|
| 35 |
+
- [Running the Server](#running-the-server)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
## Base URL
|
| 39 |
+
|
| 40 |
+
All endpoints are accessed through the base URL:
|
| 41 |
+
|
| 42 |
+
```markdown
|
| 43 |
+
http://<server-address>:7860
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
Replace `<server-address>` with your server's address.
|
| 47 |
+
|
| 48 |
+
## Endpoints
|
| 49 |
+
|
| 50 |
+
### Film Endpoints
|
| 51 |
+
|
| 52 |
+
#### `GET /api/film`
|
| 53 |
+
|
| 54 |
+
**Description:** Starts the download of a film if it's not already cached.
|
| 55 |
+
|
| 56 |
+
**Query Parameters:**
|
| 57 |
+
- `title` (string): The title of the film.
|
| 58 |
+
|
| 59 |
+
**Responses:**
|
| 60 |
+
- `200 OK`: Download started successfully.
|
| 61 |
+
```json
|
| 62 |
+
{
|
| 63 |
+
"status": "Download started",
|
| 64 |
+
"film_id": "film_id_here"
|
| 65 |
+
}
|
| 66 |
+
```
|
| 67 |
+
- `400 Bad Request`: Title parameter is required.
|
| 68 |
+
```json
|
| 69 |
+
{
|
| 70 |
+
"error": "Title parameter is required"
|
| 71 |
+
}
|
| 72 |
+
```
|
| 73 |
+
- `404 Not Found`: Movie not found.
|
| 74 |
+
|
| 75 |
+
#### `GET /api/film/store`
|
| 76 |
+
|
| 77 |
+
**Description:** Retrieves the JSON data for the film store.
|
| 78 |
+
|
| 79 |
+
**Responses:**
|
| 80 |
+
- `200 OK`: Returns the film store JSON data.
|
| 81 |
+
```json
|
| 82 |
+
{
|
| 83 |
+
"film_title": "cache_path_here"
|
| 84 |
+
}
|
| 85 |
+
```
|
| 86 |
+
- `404 Not Found`: Film store JSON not found.
|
| 87 |
+
|
| 88 |
+
#### `GET /api/film/metadata`
|
| 89 |
+
|
| 90 |
+
**Description:** Retrieves metadata for a film by title.
|
| 91 |
+
|
| 92 |
+
**Query Parameters:**
|
| 93 |
+
- `title` (string): The title of the film.
|
| 94 |
+
|
| 95 |
+
**Responses:**
|
| 96 |
+
- `200 OK`: Returns the metadata JSON for the film.
|
| 97 |
+
```json
|
| 98 |
+
{
|
| 99 |
+
"title": "Film Title",
|
| 100 |
+
"year": 2024,
|
| 101 |
+
"metadata": { ... }
|
| 102 |
+
}
|
| 103 |
+
```
|
| 104 |
+
- `400 Bad Request`: No title provided.
|
| 105 |
+
```json
|
| 106 |
+
{
|
| 107 |
+
"error": "No title provided"
|
| 108 |
+
}
|
| 109 |
+
```
|
| 110 |
+
- `404 Not Found`: Metadata not found.
|
| 111 |
+
|
| 112 |
+
### TV Show Endpoints
|
| 113 |
+
|
| 114 |
+
#### `GET /api/tv`
|
| 115 |
+
|
| 116 |
+
**Description:** Starts the download of a TV show episode if it's not already cached.
|
| 117 |
+
|
| 118 |
+
**Query Parameters:**
|
| 119 |
+
- `title` (string): The title of the TV show.
|
| 120 |
+
- `season` (string): The season number.
|
| 121 |
+
- `episode` (string): The episode number.
|
| 122 |
+
|
| 123 |
+
**Responses:**
|
| 124 |
+
- `200 OK`: Download started successfully.
|
| 125 |
+
```json
|
| 126 |
+
{
|
| 127 |
+
"status": "Download started",
|
| 128 |
+
"episode_id": "episode_id_here"
|
| 129 |
+
}
|
| 130 |
+
```
|
| 131 |
+
- `400 Bad Request`: Title, season, and episode parameters are required.
|
| 132 |
+
```json
|
| 133 |
+
{
|
| 134 |
+
"error": "Title, season, and episode parameters are required"
|
| 135 |
+
}
|
| 136 |
+
```
|
| 137 |
+
- `404 Not Found`: TV show or episode not found.
|
| 138 |
+
|
| 139 |
+
#### `GET /api/tv/store`
|
| 140 |
+
|
| 141 |
+
**Description:** Retrieves the JSON data for the TV store.
|
| 142 |
+
|
| 143 |
+
**Responses:**
|
| 144 |
+
- `200 OK`: Returns the TV store JSON data.
|
| 145 |
+
```json
|
| 146 |
+
{
|
| 147 |
+
"show_title": {
|
| 148 |
+
"season": {
|
| 149 |
+
"episode": "cache_path_here"
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
```
|
| 154 |
+
- `404 Not Found`: TV store JSON not found.
|
| 155 |
+
|
| 156 |
+
#### `GET /api/tv/metadata`
|
| 157 |
+
|
| 158 |
+
**Description:** Retrieves metadata for a TV show by title.
|
| 159 |
+
|
| 160 |
+
**Query Parameters:**
|
| 161 |
+
- `title` (string): The title of the TV show.
|
| 162 |
+
|
| 163 |
+
**Responses:**
|
| 164 |
+
- `200 OK`: Returns the metadata JSON for the TV show.
|
| 165 |
+
```json
|
| 166 |
+
{
|
| 167 |
+
"title": "TV Show Title",
|
| 168 |
+
"seasons": [ ... ],
|
| 169 |
+
"metadata": { ... }
|
| 170 |
+
}
|
| 171 |
+
```
|
| 172 |
+
- `400 Bad Request`: No title provided.
|
| 173 |
+
```json
|
| 174 |
+
{
|
| 175 |
+
"error": "No title provided"
|
| 176 |
+
}
|
| 177 |
+
```
|
| 178 |
+
- `404 Not Found`: Metadata not found.
|
| 179 |
+
|
| 180 |
+
### Cache Endpoints
|
| 181 |
+
|
| 182 |
+
#### `GET /api/cache/size`
|
| 183 |
+
|
| 184 |
+
**Description:** Retrieves the total size of the cache.
|
| 185 |
+
|
| 186 |
+
**Responses:**
|
| 187 |
+
- `200 OK`: Returns the cache size in a human-readable format.
|
| 188 |
+
```json
|
| 189 |
+
{
|
| 190 |
+
"cache_size": "10.5 MB"
|
| 191 |
+
}
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
#### `POST /api/cache/clear`
|
| 195 |
+
|
| 196 |
+
**Description:** Clears the entire cache.
|
| 197 |
+
|
| 198 |
+
**Responses:**
|
| 199 |
+
- `200 OK`: Cache cleared successfully.
|
| 200 |
+
```json
|
| 201 |
+
{
|
| 202 |
+
"status": "Cache cleared"
|
| 203 |
+
}
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
### Metadata Endpoints
|
| 207 |
+
|
| 208 |
+
#### `GET /api/filmid`
|
| 209 |
+
|
| 210 |
+
**Description:** Retrieves the film ID by title.
|
| 211 |
+
|
| 212 |
+
**Query Parameters:**
|
| 213 |
+
- `title` (string): The title of the film.
|
| 214 |
+
|
| 215 |
+
**Responses:**
|
| 216 |
+
- `200 OK`: Returns the film ID.
|
| 217 |
+
```json
|
| 218 |
+
{
|
| 219 |
+
"film_id": "film_id_here"
|
| 220 |
+
}
|
| 221 |
+
```
|
| 222 |
+
- `400 Bad Request`: Title parameter is required.
|
| 223 |
+
```json
|
| 224 |
+
{
|
| 225 |
+
"error": "Title parameter is required"
|
| 226 |
+
}
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
#### `GET /api/episodeid`
|
| 230 |
+
|
| 231 |
+
**Description:** Retrieves the episode ID by title, season, and episode.
|
| 232 |
+
|
| 233 |
+
**Query Parameters:**
|
| 234 |
+
- `title` (string): The title of the TV show.
|
| 235 |
+
- `season` (string): The season number.
|
| 236 |
+
- `episode` (string): The episode number.
|
| 237 |
+
|
| 238 |
+
**Responses:**
|
| 239 |
+
- `200 OK`: Returns the episode ID.
|
| 240 |
+
```json
|
| 241 |
+
{
|
| 242 |
+
"episode_id": "episode_id_here"
|
| 243 |
+
}
|
| 244 |
+
```
|
| 245 |
+
- `400 Bad Request`: Title, season, and episode parameters are required.
|
| 246 |
+
```json
|
| 247 |
+
{
|
| 248 |
+
"error": "Title, season, and episode parameters are required"
|
| 249 |
+
}
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
### Miscellaneous Endpoints
|
| 253 |
+
|
| 254 |
+
#### `GET /api/film/all`
|
| 255 |
+
|
| 256 |
+
**Description:** Retrieves a list of all films.
|
| 257 |
+
|
| 258 |
+
**Responses:**
|
| 259 |
+
- `200 OK`: Returns a list of film paths.
|
| 260 |
+
```json
|
| 261 |
+
[
|
| 262 |
+
"film_path_1",
|
| 263 |
+
"film_path_2"
|
| 264 |
+
]
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
#### `GET /api/tv/all`
|
| 268 |
+
|
| 269 |
+
**Description:** Retrieves a list of all TV shows.
|
| 270 |
+
|
| 271 |
+
**Responses:**
|
| 272 |
+
- `200 OK`: Returns a list of TV shows with their episodes.
|
| 273 |
+
```json
|
| 274 |
+
{
|
| 275 |
+
"show_title": [
|
| 276 |
+
{
|
| 277 |
+
"season": "season_number",
|
| 278 |
+
"episode": "episode_title"
|
| 279 |
+
}
|
| 280 |
+
]
|
| 281 |
+
}
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
## Error Handling
|
| 285 |
+
|
| 286 |
+
All endpoints return standard HTTP status codes:
|
| 287 |
+
- `200 OK` for successful requests.
|
| 288 |
+
- `400 Bad Request` for invalid requests.
|
| 289 |
+
- `404 Not Found` for missing resources.
|
| 290 |
+
|
| 291 |
+
Errors are returned in the following format:
|
| 292 |
+
```json
|
| 293 |
+
{
|
| 294 |
+
"error": "Error message here"
|
| 295 |
+
}
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
## Running the Server
|
| 299 |
+
|
| 300 |
+
To run the server, ensure you have all required dependencies installed and use the following command:
|
| 301 |
+
|
| 302 |
+
```bash
|
| 303 |
+
python app.py
|
| 304 |
+
```
|
| 305 |
+
|
| 306 |
+
The server will start on `http://0.0.0.0:7860` by default.
|
| 307 |
+
|
| 308 |
+
---
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from flask import Flask, jsonify, request, send_from_directory
|
|
|
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import threading
|
|
@@ -9,6 +10,7 @@ from tvdb import fetch_and_cache_json
|
|
| 9 |
import re
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
|
|
|
| 12 |
|
| 13 |
# Constants and Configuration
|
| 14 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
|
|
|
| 1 |
from flask import Flask, jsonify, request, send_from_directory
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
import threading
|
|
|
|
| 10 |
import re
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
+
CORS(app)
|
| 14 |
|
| 15 |
# Constants and Configuration
|
| 16 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
hf_scrapper.py
CHANGED
|
@@ -72,7 +72,7 @@ def download_film(file_url, token, cache_path, proxies, film_id, title, chunk_si
|
|
| 72 |
if download_progress[film_id]["status"] != "Downloading":
|
| 73 |
download_progress[film_id]["end_time"] = time.time()
|
| 74 |
|
| 75 |
-
def get_download_progress(
|
| 76 |
"""
|
| 77 |
Gets the download progress for a specific film.
|
| 78 |
|
|
@@ -82,15 +82,15 @@ def get_download_progress(film_id):
|
|
| 82 |
Returns:
|
| 83 |
dict: A dictionary containing the total size, downloaded size, progress percentage, status, and ETA.
|
| 84 |
"""
|
| 85 |
-
if
|
| 86 |
-
total = download_progress[
|
| 87 |
-
downloaded = download_progress[
|
| 88 |
-
status = download_progress[
|
| 89 |
progress = (downloaded / total) * 100 if total > 0 else 0
|
| 90 |
|
| 91 |
eta = None
|
| 92 |
if status == "Downloading" and downloaded > 0:
|
| 93 |
-
elapsed_time = time.time() - download_progress[
|
| 94 |
estimated_total_time = elapsed_time * (total / downloaded)
|
| 95 |
eta = estimated_total_time - elapsed_time
|
| 96 |
elif status == "Completed":
|
|
|
|
| 72 |
if download_progress[film_id]["status"] != "Downloading":
|
| 73 |
download_progress[film_id]["end_time"] = time.time()
|
| 74 |
|
| 75 |
+
def get_download_progress(id):
|
| 76 |
"""
|
| 77 |
Gets the download progress for a specific film.
|
| 78 |
|
|
|
|
| 82 |
Returns:
|
| 83 |
dict: A dictionary containing the total size, downloaded size, progress percentage, status, and ETA.
|
| 84 |
"""
|
| 85 |
+
if id in download_progress:
|
| 86 |
+
total = download_progress[id]["total"]
|
| 87 |
+
downloaded = download_progress[id]["downloaded"]
|
| 88 |
+
status = download_progress[id].get("status", "In Progress")
|
| 89 |
progress = (downloaded / total) * 100 if total > 0 else 0
|
| 90 |
|
| 91 |
eta = None
|
| 92 |
if status == "Downloading" and downloaded > 0:
|
| 93 |
+
elapsed_time = time.time() - download_progress[id]["start_time"]
|
| 94 |
estimated_total_time = elapsed_time * (total / downloaded)
|
| 95 |
eta = estimated_total_time - elapsed_time
|
| 96 |
elif status == "Completed":
|
requirements.txt
CHANGED
|
@@ -2,7 +2,4 @@ flask
|
|
| 2 |
Flask-Cors
|
| 3 |
requests
|
| 4 |
python-dotenv
|
| 5 |
-
|
| 6 |
-
ffmpeg-python
|
| 7 |
-
tqdm
|
| 8 |
-
Flask-SocketIO
|
|
|
|
| 2 |
Flask-Cors
|
| 3 |
requests
|
| 4 |
python-dotenv
|
| 5 |
+
tqdm
|
|
|
|
|
|
|
|
|