From 0d633e657b7b548ad0a4b9d265da4ee6b6570df9 Mon Sep 17 00:00:00 2001 From: Miniontoby <47940064+Miniontoby@users.noreply.github.com> Date: Tue, 14 Feb 2023 11:38:55 +0100 Subject: [PATCH] Added sounds extracter Added the way to extract sound files too. With this change #1 is can be sort of marked as fixed --- sb3_extractor/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sb3_extractor/__init__.py b/sb3_extractor/__init__.py index ed37e33..5ded0d2 100644 --- a/sb3_extractor/__init__.py +++ b/sb3_extractor/__init__.py @@ -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) @@ -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()