Spaces:
Paused
Paused
Commit
·
da7bab3
1
Parent(s):
2f37eba
fix tv metadata api
Browse files
app.py
CHANGED
@@ -67,6 +67,15 @@ def find_tv_path(json_data, title):
|
|
67 |
return sub_directory['path']
|
68 |
return None
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
def get_film_id(title):
|
71 |
"""Generate a film ID based on the title."""
|
72 |
return title.replace(" ", "_").lower()
|
@@ -286,9 +295,9 @@ def get_tv_metadata():
|
|
286 |
data = json.load(f)
|
287 |
|
288 |
# Add the file structure to the metadata
|
289 |
-
|
290 |
-
if
|
291 |
-
data['file_structure'] =
|
292 |
|
293 |
return jsonify(data)
|
294 |
|
|
|
67 |
return sub_directory['path']
|
68 |
return None
|
69 |
|
70 |
+
def get_tv_structure(json_data,title):
|
71 |
+
"""Find the path of the TV show in the JSON data based on the title."""
|
72 |
+
for directory in json_data:
|
73 |
+
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
74 |
+
for sub_directory in directory['contents']:
|
75 |
+
if sub_directory['type'] == 'directory' and title.lower() in sub_directory['path'].lower():
|
76 |
+
return sub_directory
|
77 |
+
return None
|
78 |
+
|
79 |
def get_film_id(title):
|
80 |
"""Generate a film ID based on the title."""
|
81 |
return title.replace(" ", "_").lower()
|
|
|
295 |
data = json.load(f)
|
296 |
|
297 |
# Add the file structure to the metadata
|
298 |
+
tv_structure_data = get_tv_structure(file_structure, title)
|
299 |
+
if tv_structure_data:
|
300 |
+
data['file_structure'] = tv_structure_data
|
301 |
|
302 |
return jsonify(data)
|
303 |
|
test.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
|
4 |
+
CACHE_DIR = os.getenv("CACHE_DIR")
|
5 |
+
INDEX_FILE = os.getenv("INDEX_FILE")
|
6 |
+
|
7 |
+
def find_tv_path(json_data, title):
|
8 |
+
"""Find the path of the TV show in the JSON data based on the title."""
|
9 |
+
for directory in json_data:
|
10 |
+
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
11 |
+
for sub_directory in directory['contents']:
|
12 |
+
if sub_directory['type'] == 'directory' and title.lower() in sub_directory['path'].lower():
|
13 |
+
return sub_directory
|
14 |
+
return None
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
with open(INDEX_FILE, 'r') as f:
|
19 |
+
file_structure = json.load(f)
|
20 |
+
|
21 |
+
|
22 |
+
print(find_tv_path(file_structure,title="Aho Girl"))
|