Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Created March 1, 2024 15:02
Show Gist options
  • Save Dobby233Liu/aa3893b683be98b777fd31c13e44bb17 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/aa3893b683be98b777fd31c13e44bb17 to your computer and use it in GitHub Desktop.
SATS 2013 intro/loop matcher
from glob import iglob
from objprint import op
import os
import re
DEALL_REGEX = re.compile(r"(.*)(?:[iI]ntro|[lL]oop).*\.ogg$")
def neutralize_sep(i):
return i and i.replace(os.sep, "/") or i
remaining_audio = list(map(neutralize_sep, iglob("sounds/*")))
loop_pairs = list(map(lambda x: [None, x], iglob("sounds/*loop*.ogg")))
for intro in iglob("sounds/*intro*.ogg"):
neutral_name_fs = re.sub(DEALL_REGEX, r"\1", intro)
try:
loop_pair = next(filter(lambda x: x[1].startswith(neutral_name_fs), loop_pairs))
except StopIteration:
continue
loop_pair[0] = intro
def loop_pair_clean_sep_and_insert_neutral_name(x):
x = [neutralize_sep(i) for i in x]
x.insert(0, re.sub(DEALL_REGEX, r"\1", os.path.basename(x[0] or x[1])))
if x[1]: remaining_audio.remove(x[1])
if x[2]: remaining_audio.remove(x[2])
return x
loop_pairs = list(map(loop_pair_clean_sep_and_insert_neutral_name, loop_pairs))
"""
op(loop_pairs)
"""
"""
for neutral_name, intro, loop in loop_pairs:
with open(f"{neutral_name}.txtp", "w", encoding="utf-8-sig") as txtp:
if intro:
print(intro, file=txtp)
print(f"{loop} #{intro and "a" or "E"}", file=txtp)
for i in remaining_audio: print(i)
"""
# we cant detect dupe entries so
"""
ocurrences = {}
for neutral_name, _, _ in loop_pairs:
if neutral_name not in ocurrences.keys(): ocurrences[neutral_name] = 0
ocurrences[neutral_name] = ocurrences[neutral_name] + 1
for i in filter(lambda x: x[1] > 1, ocurrences.items()): print(i[0])
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment