Spaces:
Build error
Build error
Commit
·
d53de2e
1
Parent(s):
da7bab3
update
Browse files
app.py
CHANGED
|
@@ -112,6 +112,40 @@ def bytes_to_human_readable(num, suffix="B"):
|
|
| 112 |
num /= 1024.0
|
| 113 |
return f"{num:.1f} Y{suffix}"
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
def start_prefetching():
|
| 116 |
"""Start the metadata prefetching in a separate thread."""
|
| 117 |
prefetch_metadata()
|
|
@@ -124,7 +158,7 @@ thread.start()
|
|
| 124 |
# API Endpoints
|
| 125 |
|
| 126 |
@app.route('/api/movie', methods=['GET'])
|
| 127 |
-
def
|
| 128 |
"""Endpoint to get the movie by title."""
|
| 129 |
title = request.args.get('title')
|
| 130 |
if not title:
|
|
@@ -159,7 +193,7 @@ def get_movie():
|
|
| 159 |
return jsonify({"status": "Download started", "film_id": film_id})
|
| 160 |
|
| 161 |
@app.route('/api/tv', methods=['GET'])
|
| 162 |
-
def
|
| 163 |
"""Endpoint to get the TV show by title, season, and episode."""
|
| 164 |
title = request.args.get('title')
|
| 165 |
season = request.args.get('season')
|
|
@@ -208,13 +242,13 @@ def get_tv_show():
|
|
| 208 |
return jsonify({"status": "Download started", "episode_id": episode_id})
|
| 209 |
|
| 210 |
@app.route('/api/progress/<id>', methods=['GET'])
|
| 211 |
-
def
|
| 212 |
"""Endpoint to get the download progress of a movie or TV show episode."""
|
| 213 |
progress = get_download_progress(id)
|
| 214 |
return jsonify({"id": id, "progress": progress})
|
| 215 |
|
| 216 |
@app.route('/api/filmid', methods=['GET'])
|
| 217 |
-
def
|
| 218 |
"""Endpoint to get the film ID by providing the movie title."""
|
| 219 |
title = request.args.get('title')
|
| 220 |
if not title:
|
|
@@ -223,7 +257,7 @@ def get_film_id_by_title():
|
|
| 223 |
return jsonify({"film_id": film_id})
|
| 224 |
|
| 225 |
@app.route('/api/episodeid', methods=['GET'])
|
| 226 |
-
def
|
| 227 |
"""Endpoint to get the episode ID by providing the TV show title, season, and episode."""
|
| 228 |
title = request.args.get('title')
|
| 229 |
season = request.args.get('season')
|
|
@@ -234,12 +268,12 @@ def get_episode_id():
|
|
| 234 |
return jsonify({"episode_id": episode_id})
|
| 235 |
|
| 236 |
@app.route('/api/proxy', methods=['GET'])
|
| 237 |
-
def
|
| 238 |
proxies = get_system_proxies()
|
| 239 |
return jsonify({"proxies": proxies})
|
| 240 |
|
| 241 |
@app.route('/api/size', methods=['GET'])
|
| 242 |
-
def
|
| 243 |
total_size = 0
|
| 244 |
for dirpath, dirnames, filenames in os.walk(CACHE_DIR):
|
| 245 |
for f in filenames:
|
|
@@ -249,7 +283,7 @@ def get_cache_size():
|
|
| 249 |
return jsonify({"cache_size": readable_size})
|
| 250 |
|
| 251 |
@app.route('/api/clear_cache', methods=['POST'])
|
| 252 |
-
def
|
| 253 |
for dirpath, dirnames, filenames in os.walk(CACHE_DIR):
|
| 254 |
for f in filenames:
|
| 255 |
fp = os.path.join(dirpath, f)
|
|
@@ -257,7 +291,7 @@ def clear_cache():
|
|
| 257 |
return jsonify({"status": "Cache cleared"})
|
| 258 |
|
| 259 |
@app.route('/api/store/tv', methods=['GET'])
|
| 260 |
-
def
|
| 261 |
"""Endpoint to get the TV store JSON."""
|
| 262 |
if os.path.exists(TV_STORE_JSON_PATH):
|
| 263 |
with open(TV_STORE_JSON_PATH, 'r') as json_file:
|
|
@@ -266,7 +300,7 @@ def get_tv_store():
|
|
| 266 |
return jsonify({}), 404
|
| 267 |
|
| 268 |
@app.route('/api/film/metadata', methods=['GET'])
|
| 269 |
-
def
|
| 270 |
"""Endpoint to get the film metadata by title."""
|
| 271 |
title = request.args.get('title')
|
| 272 |
if not title:
|
|
@@ -282,7 +316,7 @@ def get_film_metadata():
|
|
| 282 |
return jsonify({'error': 'Metadata not found'}), 404
|
| 283 |
|
| 284 |
@app.route('/api/tv/metadata', methods=['GET'])
|
| 285 |
-
def
|
| 286 |
"""Endpoint to get the TV show metadata by title."""
|
| 287 |
title = request.args.get('title')
|
| 288 |
if not title:
|
|
@@ -303,6 +337,12 @@ def get_tv_metadata():
|
|
| 303 |
|
| 304 |
return jsonify({'error': 'Metadata not found'}), 404
|
| 305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
# Routes
|
| 307 |
@app.route('/')
|
| 308 |
def index():
|
|
|
|
| 112 |
num /= 1024.0
|
| 113 |
return f"{num:.1f} Y{suffix}"
|
| 114 |
|
| 115 |
+
def get_all_tv_shows(indexed_cache):
|
| 116 |
+
"""Get all TV shows from the indexed cache structure JSON file."""
|
| 117 |
+
tv_shows = {}
|
| 118 |
+
for directory in indexed_cache:
|
| 119 |
+
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
| 120 |
+
for sub_directory in directory['contents']:
|
| 121 |
+
if sub_directory['type'] == 'directory':
|
| 122 |
+
show_title = sub_directory['path'].split('/')[-1]
|
| 123 |
+
tv_shows[show_title] = []
|
| 124 |
+
for season_directory in sub_directory['contents']:
|
| 125 |
+
if season_directory['type'] == 'directory':
|
| 126 |
+
season = season_directory['path'].split('/')[-1]
|
| 127 |
+
for episode in season_directory['contents']:
|
| 128 |
+
if episode['type'] == 'file':
|
| 129 |
+
tv_shows[show_title].append({
|
| 130 |
+
"season": season,
|
| 131 |
+
"episode": episode['path'].split('/')[-1],
|
| 132 |
+
"path": episode['path']
|
| 133 |
+
})
|
| 134 |
+
return tv_shows
|
| 135 |
+
|
| 136 |
+
def get_all_films(indexed_cache):
|
| 137 |
+
"""Get all films from the indexed cache structure JSON file."""
|
| 138 |
+
films = []
|
| 139 |
+
for directory in indexed_cache:
|
| 140 |
+
if directory['type'] == 'directory' and directory['path'] == 'films':
|
| 141 |
+
for sub_directory in directory['contents']:
|
| 142 |
+
if sub_directory['type'] == 'directory':
|
| 143 |
+
for item in sub_directory['contents']:
|
| 144 |
+
if item['type'] == 'file':
|
| 145 |
+
films.append(item['path'])
|
| 146 |
+
return films
|
| 147 |
+
|
| 148 |
+
|
| 149 |
def start_prefetching():
|
| 150 |
"""Start the metadata prefetching in a separate thread."""
|
| 151 |
prefetch_metadata()
|
|
|
|
| 158 |
# API Endpoints
|
| 159 |
|
| 160 |
@app.route('/api/movie', methods=['GET'])
|
| 161 |
+
def get_movie_api():
|
| 162 |
"""Endpoint to get the movie by title."""
|
| 163 |
title = request.args.get('title')
|
| 164 |
if not title:
|
|
|
|
| 193 |
return jsonify({"status": "Download started", "film_id": film_id})
|
| 194 |
|
| 195 |
@app.route('/api/tv', methods=['GET'])
|
| 196 |
+
def get_tv_show_api():
|
| 197 |
"""Endpoint to get the TV show by title, season, and episode."""
|
| 198 |
title = request.args.get('title')
|
| 199 |
season = request.args.get('season')
|
|
|
|
| 242 |
return jsonify({"status": "Download started", "episode_id": episode_id})
|
| 243 |
|
| 244 |
@app.route('/api/progress/<id>', methods=['GET'])
|
| 245 |
+
def get_progress_api(id):
|
| 246 |
"""Endpoint to get the download progress of a movie or TV show episode."""
|
| 247 |
progress = get_download_progress(id)
|
| 248 |
return jsonify({"id": id, "progress": progress})
|
| 249 |
|
| 250 |
@app.route('/api/filmid', methods=['GET'])
|
| 251 |
+
def get_film_id_by_title_api():
|
| 252 |
"""Endpoint to get the film ID by providing the movie title."""
|
| 253 |
title = request.args.get('title')
|
| 254 |
if not title:
|
|
|
|
| 257 |
return jsonify({"film_id": film_id})
|
| 258 |
|
| 259 |
@app.route('/api/episodeid', methods=['GET'])
|
| 260 |
+
def get_episode_id_api():
|
| 261 |
"""Endpoint to get the episode ID by providing the TV show title, season, and episode."""
|
| 262 |
title = request.args.get('title')
|
| 263 |
season = request.args.get('season')
|
|
|
|
| 268 |
return jsonify({"episode_id": episode_id})
|
| 269 |
|
| 270 |
@app.route('/api/proxy', methods=['GET'])
|
| 271 |
+
def get_proxy_api():
|
| 272 |
proxies = get_system_proxies()
|
| 273 |
return jsonify({"proxies": proxies})
|
| 274 |
|
| 275 |
@app.route('/api/size', methods=['GET'])
|
| 276 |
+
def get_cache_size_api():
|
| 277 |
total_size = 0
|
| 278 |
for dirpath, dirnames, filenames in os.walk(CACHE_DIR):
|
| 279 |
for f in filenames:
|
|
|
|
| 283 |
return jsonify({"cache_size": readable_size})
|
| 284 |
|
| 285 |
@app.route('/api/clear_cache', methods=['POST'])
|
| 286 |
+
def clear_cache_api():
|
| 287 |
for dirpath, dirnames, filenames in os.walk(CACHE_DIR):
|
| 288 |
for f in filenames:
|
| 289 |
fp = os.path.join(dirpath, f)
|
|
|
|
| 291 |
return jsonify({"status": "Cache cleared"})
|
| 292 |
|
| 293 |
@app.route('/api/store/tv', methods=['GET'])
|
| 294 |
+
def get_tv_store_api():
|
| 295 |
"""Endpoint to get the TV store JSON."""
|
| 296 |
if os.path.exists(TV_STORE_JSON_PATH):
|
| 297 |
with open(TV_STORE_JSON_PATH, 'r') as json_file:
|
|
|
|
| 300 |
return jsonify({}), 404
|
| 301 |
|
| 302 |
@app.route('/api/film/metadata', methods=['GET'])
|
| 303 |
+
def get_film_metadata_api():
|
| 304 |
"""Endpoint to get the film metadata by title."""
|
| 305 |
title = request.args.get('title')
|
| 306 |
if not title:
|
|
|
|
| 316 |
return jsonify({'error': 'Metadata not found'}), 404
|
| 317 |
|
| 318 |
@app.route('/api/tv/metadata', methods=['GET'])
|
| 319 |
+
def get_tv_metadata_api():
|
| 320 |
"""Endpoint to get the TV show metadata by title."""
|
| 321 |
title = request.args.get('title')
|
| 322 |
if not title:
|
|
|
|
| 337 |
|
| 338 |
return jsonify({'error': 'Metadata not found'}), 404
|
| 339 |
|
| 340 |
+
|
| 341 |
+
@app.route("/api/all_films")
|
| 342 |
+
def get_all_films_api():
|
| 343 |
+
get_all_films()
|
| 344 |
+
|
| 345 |
+
|
| 346 |
# Routes
|
| 347 |
@app.route('/')
|
| 348 |
def index():
|
test.py
CHANGED
|
@@ -4,19 +4,30 @@ import json
|
|
| 4 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
| 5 |
INDEX_FILE = os.getenv("INDEX_FILE")
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
"""
|
| 9 |
-
|
|
|
|
| 10 |
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
| 11 |
for sub_directory in directory['contents']:
|
| 12 |
-
if sub_directory['type'] == 'directory'
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
with open(INDEX_FILE, 'r') as f:
|
| 19 |
file_structure = json.load(f)
|
| 20 |
|
| 21 |
|
| 22 |
-
print(
|
|
|
|
| 4 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
| 5 |
INDEX_FILE = os.getenv("INDEX_FILE")
|
| 6 |
|
| 7 |
+
def get_all_tv_shows(indexed_cache):
|
| 8 |
+
"""Get all TV shows from the indexed cache structure JSON file."""
|
| 9 |
+
tv_shows = {}
|
| 10 |
+
for directory in indexed_cache:
|
| 11 |
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
| 12 |
for sub_directory in directory['contents']:
|
| 13 |
+
if sub_directory['type'] == 'directory':
|
| 14 |
+
show_title = sub_directory['path'].split('/')[-1]
|
| 15 |
+
tv_shows[show_title] = []
|
| 16 |
+
for season_directory in sub_directory['contents']:
|
| 17 |
+
if season_directory['type'] == 'directory':
|
| 18 |
+
season = season_directory['path'].split('/')[-1]
|
| 19 |
+
for episode in season_directory['contents']:
|
| 20 |
+
if episode['type'] == 'file':
|
| 21 |
+
tv_shows[show_title].append({
|
| 22 |
+
"season": season,
|
| 23 |
+
"episode": episode['path'].split('/')[-1],
|
| 24 |
+
"path": episode['path']
|
| 25 |
+
})
|
| 26 |
+
return tv_shows
|
| 27 |
|
| 28 |
|
| 29 |
with open(INDEX_FILE, 'r') as f:
|
| 30 |
file_structure = json.load(f)
|
| 31 |
|
| 32 |
|
| 33 |
+
print(get_all_tv_shows(file_structure))
|