Skip to content

Commit

Permalink
Added sounds extracter
Browse files Browse the repository at this point in the history
Added the way to extract sound files too. 

With this change waterimp#1 is can be sort of marked as fixed
  • Loading branch information
Miniontoby authored Feb 14, 2023
1 parent df10540 commit 0d633e6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sb3_extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def extract_sb3(filename):
scripts = sprite.block_info.scripts()
blocks = sprite.block_info.blocks()
costumes = sprite.costumes
sounds = sprite.sounds
for costume_index, costume in enumerate(costumes):
costume_name = replace_delimiters(costume.name)
costume_center = (costume.center_x, costume.center_y)
Expand All @@ -85,6 +86,21 @@ def extract_sb3(filename):

rasterize_png(new_filename)

for sound_index, sound in enumerate(sounds):
sound_name = replace_delimiters(sound.name)
sound_filename = sound.filename

new_filename = f'{sprite_name}-{str(sound_index).zfill(3)}-{sound_name}{os.path.splitext(sound_filename)[1]}'
new_filename = beautify_path_fragment(new_filename)
new_filename = sanitize_path_fragment(new_filename) # important for security
new_filename = os.path.join(base_folder, new_filename)

print(f' * extracted {new_filename}')

contents = assets_map[sound_filename].read()

with open(new_filename, 'wb') as output_file:
output_file.write(contents)

if __name__ == '__main__':
main()

0 comments on commit 0d633e6

Please sign in to comment.