Skip to content

Instantly share code, notes, and snippets.

@wallismu
Last active September 24, 2020 19:40
Show Gist options
  • Save wallismu/b85b35b85f7c7c76727427389ddb0faf to your computer and use it in GitHub Desktop.
Save wallismu/b85b35b85f7c7c76727427389ddb0faf to your computer and use it in GitHub Desktop.
import os
import sys
import shutil
def convert(which, path):
command = ""
if which == "audio":
command = "ffmpeg -i \"" + path[0:-4] + ".wav\" -acodec libmp3lame \"" + path[0:-4] + ".mp3\" && rm \"" + path[0:-4] + ".wav\""
# if which == "pngs":
# command = "pngquant --force --skip-if-larger --ext .png --speed 1 \"" + path + "\""
if command:
os.system(command)
print(command)
# Todo: add check for icky files with no extensions (Main usually)
def init(rootInput):
for (root, dirs, files) in os.walk(rootInput):
for f in files:
print ("***", f)
toConvert = os.path.join(root, f)
if f.split('.')[1].upper() == "WAV":
convert("audio", toConvert)
if f.split('.')[1].upper() == "PNG":
convert("pngs", toConvert)
def convert_audio(path):
for (root, dirs, files) in os.walk(path):
for f in files:
if f.split('.')[1].upper() == "WAV":
name = path + "/" + f.split('.')[0]
command = "ffmpeg -i " + name + ".wav -acodec libmp3lame " + name + ".mp3"
os.system(command)
os.remove(name + ".wav")
def convert_pngs(path):
for (root, dirs, files) in os.walk(path):
for f in files:
if f.split('.')[1].upper() == "PNG":
toConvert = root + "/" + f
print (f + "**")
command = "pngquant --force --skip-if-larger --ext .png --speed 1 \"" + toConvert + "\""
os.system(command)
if __name__ == "__main__":
where = sys.argv[1]
init(where)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment