MariaKaiser commited on
Commit
a5a2f62
·
verified ·
1 Parent(s): 37516b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -43,10 +43,13 @@ download_cache = {} # URL -> local path
43
  # -----------------------------
44
  # Helper to get cached file (downloads if missing)
45
  # -----------------------------
46
- async def get_cached_file(url: str, subfolder: str) -> str:
47
  """
48
  Returns local cached path for URL.
49
  Downloads and stores in subfolder if missing.
 
 
 
50
  """
51
  if url in download_cache:
52
  return download_cache[url]
@@ -61,15 +64,24 @@ async def get_cached_file(url: str, subfolder: str) -> str:
61
  print(f"Found on disk, added to cache: {local_path}")
62
  return local_path
63
 
64
- # Download from URL/Supabase
65
- async with httpx.AsyncClient(timeout=60) as client:
66
- resp = await client.get(url)
67
- resp.raise_for_status()
68
- with open(local_path, "wb") as f:
69
- f.write(resp.content)
70
- download_cache[url] = local_path
71
- print(f"Downloaded and cached: {url} {local_path}")
72
- return local_path
 
 
 
 
 
 
 
 
 
73
 
74
  # -----------------------------
75
  # Preload all assets from Supabase at startup
 
43
  # -----------------------------
44
  # Helper to get cached file (downloads if missing)
45
  # -----------------------------
46
+ async def get_cached_file(url: str, subfolder: str) -> str | None:
47
  """
48
  Returns local cached path for URL.
49
  Downloads and stores in subfolder if missing.
50
+ If download fails:
51
+ - Raise error for prosody or bg_music
52
+ - Skip (return None) for sfx
53
  """
54
  if url in download_cache:
55
  return download_cache[url]
 
64
  print(f"Found on disk, added to cache: {local_path}")
65
  return local_path
66
 
67
+ try:
68
+ async with httpx.AsyncClient(timeout=60) as client:
69
+ resp = await client.get(url)
70
+ resp.raise_for_status()
71
+ with open(local_path, "wb") as f:
72
+ f.write(resp.content)
73
+
74
+ download_cache[url] = local_path
75
+ print(f"Downloaded and cached: {url} → {local_path}")
76
+ return local_path
77
+
78
+ except Exception as e:
79
+ if subfolder == "sfx":
80
+ print(f"Warning: Failed to download SFX {url}, skipping: {e}")
81
+ return None
82
+ else:
83
+ # Raise error for essential files
84
+ raise RuntimeError(f"Failed to download {subfolder} file {url}: {e}") from e
85
 
86
  # -----------------------------
87
  # Preload all assets from Supabase at startup