Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Last active January 22, 2024 10:05
Show Gist options
  • Save Dobby233Liu/b4ed761596305c419ab81a5545c3f5f2 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/b4ed761596305c419ab81a5545c3f5f2 to your computer and use it in GitHub Desktop.
from lxml import etree
import glob
from pathlib import Path
SOUND_DIR = "sound/"
AUDIO_DIR = SOUND_DIR + "audio/"
unused_audio = list(map(lambda x: x.replace("/", "\\"), glob.iglob(f"{AUDIO_DIR}/*")))
for sound_info_file in Path(".").glob(f"{SOUND_DIR}*.sound.gmx"):
sound_info = etree.parse(sound_info_file)
sound_file_elem = sound_info.find("/origname")
assert sound_file_elem is not None
sound_file = sound_file_elem.text
sound_file_obj = Path(sound_file)
if not sound_file_obj.exists():
audio_file_relpath = str(sound_file_obj.relative_to(AUDIO_DIR))
unused_audio.append(f"{str(sound_info_file)} (no corresponding file {audio_file_relpath})")
continue
unused_audio.remove(sound_file)
for idx, file in enumerate(unused_audio):
file = unused_audio[idx] = Path(file)
if file.suffix != ".wav" and file.with_suffix(".wav").exists():
file = file.with_name(file.name + " (has corresponding wav file)")
print(file.relative_to(AUDIO_DIR, walk_up=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment