Spaces:
Build error
Build error
Commit
·
487a828
1
Parent(s):
86769fb
fix
Browse files
app.py
CHANGED
|
@@ -3,8 +3,11 @@ import os
|
|
| 3 |
import urllib.parse
|
| 4 |
from hf_scrapper import download_and_cache_file, get_system_proxies
|
| 5 |
from indexer import indexer
|
|
|
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import json
|
|
|
|
|
|
|
| 8 |
|
| 9 |
load_dotenv()
|
| 10 |
INDEX_FILE = os.getenv("INDEX_FILE")
|
|
@@ -24,6 +27,37 @@ if not os.path.exists(INDEX_FILE):
|
|
| 24 |
with open(INDEX_FILE, 'r') as f:
|
| 25 |
file_structure = json.load(f)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
app = Flask(__name__)
|
| 28 |
|
| 29 |
def get_film_file_path(title):
|
|
|
|
| 3 |
import urllib.parse
|
| 4 |
from hf_scrapper import download_and_cache_file, get_system_proxies
|
| 5 |
from indexer import indexer
|
| 6 |
+
from tvdb import fetch_and_cache_json
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
import json
|
| 9 |
+
import re
|
| 10 |
+
from threading import Thread
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
INDEX_FILE = os.getenv("INDEX_FILE")
|
|
|
|
| 27 |
with open(INDEX_FILE, 'r') as f:
|
| 28 |
file_structure = json.load(f)
|
| 29 |
|
| 30 |
+
def prefetch_metadata():
|
| 31 |
+
for item in file_structure:
|
| 32 |
+
if 'contents' in item:
|
| 33 |
+
for sub_item in item['contents']:
|
| 34 |
+
original_title = sub_item['path'].split('/')[-1]
|
| 35 |
+
media_type = 'series' if item['path'].startswith('tv') else 'movie'
|
| 36 |
+
title = original_title
|
| 37 |
+
year = None
|
| 38 |
+
|
| 39 |
+
match = re.search(r'\((\d{4})\)', original_title)
|
| 40 |
+
if match:
|
| 41 |
+
year_str = match.group(1)
|
| 42 |
+
if year_str.isdigit() and len(year_str) == 4:
|
| 43 |
+
title = original_title[:match.start()].strip()
|
| 44 |
+
year = int(year_str)
|
| 45 |
+
else:
|
| 46 |
+
parts = original_title.rsplit(' ', 1)
|
| 47 |
+
if len(parts) > 1 and parts[-1].isdigit() and len(parts[-1]) == 4:
|
| 48 |
+
title = parts[0].strip()
|
| 49 |
+
year = int(parts[-1])
|
| 50 |
+
|
| 51 |
+
fetch_and_cache_json(original_title, title, media_type, year)
|
| 52 |
+
|
| 53 |
+
def start_prefetching():
|
| 54 |
+
prefetch_metadata()
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
thread = Thread(target=start_prefetching)
|
| 58 |
+
thread.daemon = True
|
| 59 |
+
thread.start()
|
| 60 |
+
|
| 61 |
app = Flask(__name__)
|
| 62 |
|
| 63 |
def get_film_file_path(title):
|