Created
February 12, 2017 02:28
-
-
Save ivannp/ddc501f62f0c159d13202b111fb19721 to your computer and use it in GitHub Desktop.
Converting files (.m4b to .mp3) in python
This file contains 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
import glob | |
import os | |
import subprocess | |
def main(): | |
base_dir = os.path.abspath('d:/abooks') | |
ffmpeg_path = os.path.abspath('C:/tools/ffmpeg/bin/ffmpeg.exe') | |
pattern = os.path.join(base_dir, '**', '*.m4b') | |
file_list = [file for file in glob.glob(pattern, recursive = True)] | |
for file in file_list: | |
dir_path, file_name = os.path.split(file) | |
# Drop the file extension | |
file_name = os.path.splitext(file_name)[0] | |
output_path = os.path.join(dir_path, file_name + '.mp3') | |
if not os.path.exists(output_path): | |
# Convert | |
print('Converting: ' + file) | |
subprocess.call([ffmpeg_path, '-i', file, '-acodec', 'libmp3lame', output_path]) | |
else: | |
print('Skipping: ' + file) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment