Skip to content

Commit

Permalink
Setup cache
Browse files Browse the repository at this point in the history
  • Loading branch information
damusss authored Aug 14, 2024
1 parent d6c4911 commit 03d61ca
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/pygbag/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from .html_embed import html_embed

COUNTER = 0
UNSUPPORTED_CACHE = []
OGG_CACHE = []


class REPLAY:
Expand All @@ -22,11 +24,13 @@ async def pack_files(zf, packlist, zfolders, target_folder):

for asset in packlist:
asset_name = str(asset)[1:]
if "--disable-mp3-error" not in sys.argv and Path(asset_name).suffix[1:].lower() in ["mp3", "wav", "aiff"]:
raise RuntimeError(
f"Audio file '{str(asset)[1:]}' in '{target_folder}' has a common unsupported format. "
"Use OGG format instead. Suppress this error with the '--disable-sound-format-error' option."
)

if "--disable-sound-format-error" not in sys.argv:
suffix = Path(asset_name).suffix[1:].lower()
if suffix in ["mp3", "wav", "aiff"]:
UNSUPPORTED_CACHE.append((asset_name.replace(f".{suffix}", ""), suffix))
elif suffix == "ogg":
OGG_CACHE.append(asset_name.replace(".ogg", ""))

zpath = list(zfolders)
zpath.insert(0, str(target_folder))
Expand Down Expand Up @@ -120,6 +124,18 @@ async def archive(apkname, target_folder, build_dir=None):
# pack_files(zf, Path.cwd(), ["assets"], target_folder)
await pack_files(zf, packlist, ["assets"], target_folder)

for unsupported_name, suffix in UNSUPPORTED_CACHE:
found_ogg = False
for ogg_name in OGG_CACHE:
if ogg_name in [unsupported_name, f"{unsupported_name}-pygbag"]:
found_ogg = True
break
if not found_ogg:
raise RuntimeError(
f"Audio file '{unsupported_name}.{suffix}' in '{target_folder}' has a common unsupported format. "
"Use OGG format instead. Suppress this error with the '--disable-sound-format-error' option."
)

print(f"packing {COUNTER} files complete")


Expand Down

0 comments on commit 03d61ca

Please sign in to comment.