SHARE
TWEET

get all sound files from sc2 mpq packed archives

DeaD_EyE Jul 20th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. """
  4. Script to extract all audio from downloaded content of Star Craft II
  5.  
  6. This module is needed:
  7. https://github.com/eagleflo/mpyq
  8. """
  9.  
  10. from pathlib import Path
  11. from zlib import error as zlib_error
  12.  
  13. from mpyq import MPQArchive
  14.  
  15.  
  16. FILE_TYPES = ('.mp3', '.ogg')
  17.  
  18.  
  19. def get_sound(path):
  20.     path = Path(path)
  21.     for file in path.rglob('*.s2m?'):
  22.         try:
  23.             mpq = MPQArchive(file)
  24.             # print(f'Processing {file.name}')
  25.         except ValueError:
  26.             continue
  27.         for content in map(bytes.decode, mpq.files):
  28.             if any(content.endswith(ext) for ext in FILE_TYPES):
  29.                 try:
  30.                     mpq.extract_files(content)
  31.                 except (RuntimeError, zlib_error):
  32.                     # print(f'Error with decompression: {file.name}')
  33.                     pass
  34.  
  35. my_path = "Games/starcraft-ii/drive_c/ProgramData/Blizzard Entertainment/Battle.net/Cache"
  36. get_sound(my_path)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top