Advertisement
DeaD_EyE

get all sound files from sc2 mpq packed archives

Jul 20th, 2019
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement