Skip to content

Instantly share code, notes, and snippets.

@WillKirkmanM
Created September 17, 2023 14:07
Show Gist options
  • Save WillKirkmanM/8973422b9aebc4f9f6b40a63905f7b9f to your computer and use it in GitHub Desktop.
Save WillKirkmanM/8973422b9aebc4f9f6b40a63905f7b9f to your computer and use it in GitHub Desktop.
Metadata Preserving Audiobook Converter From .m4b -> .mp3
import os
import subprocess
import sys
cwd = os.getcwd()
files = os.listdir(cwd)
for file in files:
extension = os.path.splitext(file)[1]
if extension == '.m4b':
file_name = os.path.splitext(file)[0]
new_file_name = file_name + '.mp3'
command = 'ffmpeg -i "' + file + '" -c copy -map_metadata 0 -c:a libmp3lame -q:a 2 "' + new_file_name + '"'
subprocess.call(command, shell=True)
os.remove(file)
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment