Spaces:
Paused
Paused
Commit ·
c9f8e3c
1
Parent(s): a6e6b00
add cors
Browse filesFiles changed (4)
- README.md+292-12
- app.py+2
- hf_scrapper.py+6-6
- requirements.txt+1-4
10 unmodified lines11121314151617181920212223242526272810 unmodified lines## Scripts### app.py -> main script that run flask server### hf_scrapper.py -> script for interacting with huggingface### indexer.py script to index the repo structure### tvdb.py script to interact with TheTVDB## Templates### index.html -> display few movies and few shows### films.html -> browse all movies### tv.html ->browse all tv shows### film_page.html -> film details page### tvshow_page -> tv show details , seasons , episodes page### film_player.html -> film player page### tv_player.html -> tv show player page10 unmodified lines111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730810 unmodified lines## Scripts```app.py -> main script that run flask serverhf_scrapper.py -> script for interacting with huggingfaceindexer.py -> script to index the repo structuretvdb.py -> script to interact with TheTVDB```## Film and TV APIThis API provides endpoints for accessing and managing film and TV show data, including downloading, caching, and retrieving metadata.## Table of Contents- [Base URL](#base-url)- [Endpoints](#endpoints)- [Film Endpoints](#film-endpoints)- [TV Show Endpoints](#tv-show-endpoints)- [Cache Endpoints](#cache-endpoints)- [Metadata Endpoints](#metadata-endpoints)- [Miscellaneous Endpoints](#miscellaneous-endpoints)- [Error Handling](#error-handling)- [Running the Server](#running-the-server)## Base URLAll endpoints are accessed through the base URL:```markdownhttp://<server-address>:7860```Replace `<server-address>` with your server's address.## Endpoints### Film Endpoints#### `GET /api/film`**Description:** Starts the download of a film if it's not already cached.**Query Parameters:**- `title` (string): The title of the film.**Responses:**- `200 OK`: Download started successfully.```json{"status": "Download started","film_id": "film_id_here"}```- `400 Bad Request`: Title parameter is required.```json{"error": "Title parameter is required"}```- `404 Not Found`: Movie not found.#### `GET /api/film/store`**Description:** Retrieves the JSON data for the film store.**Responses:**- `200 OK`: Returns the film store JSON data.```json{"film_title": "cache_path_here"}```- `404 Not Found`: Film store JSON not found.#### `GET /api/film/metadata`**Description:** Retrieves metadata for a film by title.**Query Parameters:**- `title` (string): The title of the film.**Responses:**- `200 OK`: Returns the metadata JSON for the film.```json{"title": "Film Title","year": 2024,"metadata": { ... }}```- `400 Bad Request`: No title provided.```json{"error": "No title provided"}```- `404 Not Found`: Metadata not found.### TV Show Endpoints#### `GET /api/tv`**Description:** Starts the download of a TV show episode if it's not already cached.**Query Parameters:**- `title` (string): The title of the TV show.- `season` (string): The season number.- `episode` (string): The episode number.**Responses:**- `200 OK`: Download started successfully.```json{"status": "Download started","episode_id": "episode_id_here"}```- `400 Bad Request`: Title, season, and episode parameters are required.```json{"error": "Title, season, and episode parameters are required"}```- `404 Not Found`: TV show or episode not found.#### `GET /api/tv/store`**Description:** Retrieves the JSON data for the TV store.**Responses:**- `200 OK`: Returns the TV store JSON data.```json{"show_title": {"season": {"episode": "cache_path_here"}}}```- `404 Not Found`: TV store JSON not found.#### `GET /api/tv/metadata`**Description:** Retrieves metadata for a TV show by title.**Query Parameters:**- `title` (string): The title of the TV show.**Responses:**- `200 OK`: Returns the metadata JSON for the TV show.```json{"title": "TV Show Title","seasons": [ ... ],"metadata": { ... }}```- `400 Bad Request`: No title provided.```json{"error": "No title provided"}```- `404 Not Found`: Metadata not found.### Cache Endpoints#### `GET /api/cache/size`**Description:** Retrieves the total size of the cache.**Responses:**- `200 OK`: Returns the cache size in a human-readable format.```json{"cache_size": "10.5 MB"}```#### `POST /api/cache/clear`**Description:** Clears the entire cache.**Responses:**- `200 OK`: Cache cleared successfully.```json{"status": "Cache cleared"}```### Metadata Endpoints#### `GET /api/filmid`**Description:** Retrieves the film ID by title.**Query Parameters:**- `title` (string): The title of the film.**Responses:**- `200 OK`: Returns the film ID.```json{"film_id": "film_id_here"}```- `400 Bad Request`: Title parameter is required.```json{"error": "Title parameter is required"}```#### `GET /api/episodeid`**Description:** Retrieves the episode ID by title, season, and episode.**Query Parameters:**- `title` (string): The title of the TV show.- `season` (string): The season number.- `episode` (string): The episode number.**Responses:**- `200 OK`: Returns the episode ID.```json{"episode_id": "episode_id_here"}```- `400 Bad Request`: Title, season, and episode parameters are required.```json{"error": "Title, season, and episode parameters are required"}```### Miscellaneous Endpoints#### `GET /api/film/all`**Description:** Retrieves a list of all films.**Responses:**- `200 OK`: Returns a list of film paths.```json["film_path_1","film_path_2"]```#### `GET /api/tv/all`**Description:** Retrieves a list of all TV shows.**Responses:**- `200 OK`: Returns a list of TV shows with their episodes.```json{"show_title": [{"season": "season_number","episode": "episode_title"}]}```## Error HandlingAll endpoints return standard HTTP status codes:- `200 OK` for successful requests.- `400 Bad Request` for invalid requests.- `404 Not Found` for missing resources.Errors are returned in the following format:```json{"error": "Error message here"}```## Running the ServerTo run the server, ensure you have all required dependencies installed and use the following command:```bashpython app.py```The server will start on `http://0.0.0.0:7860` by default.---
12344 unmodified lines91011121314from flask import Flask, jsonify, request, send_from_directoryimport osimport jsonimport threading4 unmodified linesimport reapp = Flask(__name__)# Constants and ConfigurationCACHE_DIR = os.getenv("CACHE_DIR")123454 unmodified lines10111213141516from flask import Flask, jsonify, request, send_from_directoryfrom flask_cors import CORSimport osimport jsonimport threading4 unmodified linesimport reapp = Flask(__name__)CORS(app)# Constants and ConfigurationCACHE_DIR = os.getenv("CACHE_DIR")
71 unmodified lines727374757677783 unmodified lines82838485868788899091929394959671 unmodified linesif download_progress[film_id]["status"] != "Downloading":download_progress[film_id]["end_time"] = time.time()def get_download_progress(film_id):"""Gets the download progress for a specific film.3 unmodified linesReturns:dict: A dictionary containing the total size, downloaded size, progress percentage, status, and ETA."""if film_id in download_progress:total = download_progress[film_id]["total"]downloaded = download_progress[film_id]["downloaded"]status = download_progress[film_id].get("status", "In Progress")progress = (downloaded / total) * 100 if total > 0 else 0eta = Noneif status == "Downloading" and downloaded > 0:elapsed_time = time.time() - download_progress[film_id]["start_time"]estimated_total_time = elapsed_time * (total / downloaded)eta = estimated_total_time - elapsed_timeelif status == "Completed":71 unmodified lines727374757677783 unmodified lines82838485868788899091929394959671 unmodified linesif download_progress[film_id]["status"] != "Downloading":download_progress[film_id]["end_time"] = time.time()def get_download_progress(id):"""Gets the download progress for a specific film.3 unmodified linesReturns:dict: A dictionary containing the total size, downloaded size, progress percentage, status, and ETA."""if id in download_progress:total = download_progress[id]["total"]downloaded = download_progress[id]["downloaded"]status = download_progress[id].get("status", "In Progress")progress = (downloaded / total) * 100 if total > 0 else 0eta = Noneif status == "Downloading" and downloaded > 0:elapsed_time = time.time() - download_progress[id]["start_time"]estimated_total_time = elapsed_time * (total / downloaded)eta = estimated_total_time - elapsed_timeelif status == "Completed":
1 unmodified line23456781 unmodified lineFlask-Corsrequestspython-dotenvffmpyffmpeg-pythontqdmFlask-SocketIO1 unmodified line23451 unmodified lineFlask-Corsrequestspython-dotenvtqdm
README.md+292-12
app.py+2
hf_scrapper.py+6-6
requirements.txt+1-4