Last active
May 22, 2022 17:31
-
-
Save sowbug/101492dba72fa6c814ce90d8bb4e3177 to your computer and use it in GitHub Desktop.
Given a bunch of MP3 files in directories, copies them into a file tree that is compatible with DFPlayer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Given a bunch of MP3 files in directories, | |
# copies them into a file tree that is | |
# compatible with DFPlayer. | |
import os | |
import shutil | |
src_dir = './sfx' | |
dst_dir = './sfx-sorted' | |
src_subdirs = {} | |
for root, subdirs, files in os.walk(src_dir): | |
for subdir in subdirs: | |
src_subdirs[subdir] = [] | |
continue | |
relative_src_dir = os.path.relpath(root, src_dir) | |
for file in files: | |
src_subdirs[relative_src_dir].append(file) | |
dir_num = 1 | |
for src_subdir, src_files in src_subdirs.items(): | |
file_num = 1 | |
dst_subdir = os.path.join(dst_dir, "%02d" % (dir_num)) | |
os.makedirs(dst_subdir) | |
for src_file in src_files: | |
src_fullpath = os.path.join(src_dir, src_subdir, src_file) | |
dst_fullpath = os.path.join(dst_subdir, "%03d.mp3" % (file_num)) | |
file_num += 1 | |
print(src_fullpath, dst_fullpath) | |
shutil.copyfile(src_fullpath, dst_fullpath) | |
dir_num += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment