Skip to content

Instantly share code, notes, and snippets.

@Restioson
Last active May 9, 2017 12:39
Show Gist options
  • Save Restioson/4ea1b038e596887d8d6cfc611aa2bc28 to your computer and use it in GitHub Desktop.
Save Restioson/4ea1b038e596887d8d6cfc611aa2bc28 to your computer and use it in GitHub Desktop.
# Recursively converts flac to mp3
# Imports
import os
import itertools
import ffmpy
import glob
# Directory for mp3 files
mp3_dir = os.path.join(os.getcwd(), "mp3")
# Get flac files
flac_files = glob.glob("**/*.flac", recursive=True)
print(flac_files)
# Convert to mp3
for file in flac_files:
# Make dir for mp3 file
try: os.makedirs("\\".join(os.path.join(mp3_dir, file.replace(".\\", "").replace("flac", "mp3")).split("\\")[0:-1]))
except: pass
# Run FFMPEG operation
try: ffmpy.FFmpeg(inputs = {file : None}, outputs = {os.path.join(mp3_dir, file.replace("." + os.path.sep, "").replace("flac", "mp3")) : None}).run()
except: pass
print("Success!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment