Skip to content

Instantly share code, notes, and snippets.

@kirosvi
Last active August 29, 2015 14:14
Show Gist options
  • Save kirosvi/9fbe9e3f20082ce70493 to your computer and use it in GitHub Desktop.
Save kirosvi/9fbe9e3f20082ce70493 to your computer and use it in GitHub Desktop.
simple converting files in directory, that you can call from everywhere in directory with files
#!/usr/bin/python
import os, subprocess
os.chdir(os.getcwd())
sourcedir = "./"
convert_list = []
f_ext = ".flac" #extension of source file
f_extnew = ".ogg" #extension of output file
ffmpeg = "/usr/local/bin/ffmpeg" # path to ffmpeg
params = "-strict experimental -acodec vorbis -aq 100" # settings of converting which in command after source file and before output file
spec_sym = ")(][}{" # special symbols
""" if spaces and special symbols in name, it was changed to "_" """
for file in os.listdir(sourcedir):
os.rename(file, file.replace(" ", "_"))
for i in range(len(file)):
if file[i] in spec_sym:
os.rename(file, file.replace(file[i], "_"))
for file in os.listdir(sourcedir):
if f_ext in file:
convert_list.append(file)
for file in convert_list:
child = subprocess.call(" ".join((ffmpeg, "-i", file, params, file.replace(f_ext, f_extnew))), executable='/bin/bash', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment