Skip to content

Instantly share code, notes, and snippets.

@ElementW
Created January 30, 2018 20:14
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElementW/443ba25e3a16d004503cae9f38936455 to your computer and use it in GitHub Desktop.
Save ElementW/443ba25e3a16d004503cae9f38936455 to your computer and use it in GitHub Desktop.
Python3 script to extract music from UE4 .uexp files
#!/usr/bin/env python3
import sys, os, errno
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def analyze(file):
magics = {
'ogg': b'OggS',
'wav': b'RIFF'
}
start = file.read(1024)
for ftype, magic in magics.items():
loc = start.find(magic)
if loc != -1:
return (ftype, loc)
return None
if __name__ == '__main__':
if len(sys.argv) <= 2:
sys.exit("Usage: uexplode.py <input dir> <output dir>")
if not os.path.exists(sys.argv[1]):
sys.exit("Input dir does not exist")
indir = sys.argv[1]
outdir = sys.argv[2]
for root, dirs, files in os.walk(indir, topdown=True):
destdir = os.path.join(outdir, root[len(indir)+1:])
for name in files:
if name.endswith('.uexp'):
with open(os.path.join(root, name), 'rb') as f:
anl = analyze(f)
if anl is not None:
destfname = name[:-5] + '.' + anl[0]
destpath = os.path.join(destdir, destfname)
mkdir_p(destdir)
with open(destpath, 'wb') as dest:
f.seek(anl[1])
dest.write(f.read())
print('{} -> {}'.format(os.path.join(root, name), destpath))
@IDeserveToBeWrited
Copy link

Works with Deep Rock Galactic, thanks for good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment