Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Created January 21, 2024 14:12
Show Gist options
  • Save Dobby233Liu/d39b428dec32a623a770db5539543ae1 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/d39b428dec32a623a770db5539543ae1 to your computer and use it in GitHub Desktop.
XPath is something
from lxml import etree
import glob
def externalize(sound_info_file, streamed=True, bitrate=96, stereo=True):
sound_info_file = sound_info_file + ".sound.gmx"
sound_info = etree.parse(sound_info_file)
sound_info.find("/compressed").text = "1"
sound_info.find("/streamed").text = streamed and "1" or "0"
sound_info.find("/bitRates/bitRate").text = str(bitrate)
sound_info.find("/types/type").text = stereo and "1" or "0"
sound_info.write(sound_info_file, encoding="utf-8", pretty_print=True, xml_declaration=False, with_comments=True)
project = etree.parse(next(glob.iglob("*.project.gmx")))
sounds = project.xpath("/assets/sounds")[0]
for sound_info_file in sounds.xpath(".//sound[contains(., 'snd_samplesound')]/text()"):
externalize(sound_info_file, streamed=False, bitrate=64)
externalize(sounds.xpath(".//sound[contains(., 'snd_testtrack_')]/text()")[0], streamed=False, bitrate=64)
for sound_info_file in sounds.xpath("./sounds/sounds[@name!='sfx']//sound"):
streamed, bitrate = True, 96
if not sound_info_file.xpath("./ancestor::sounds[@name='music']"):
streamed, bitrate = False, 64
externalize(sound_info_file.text, streamed=streamed, bitrate=bitrate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment