Last active
September 24, 2020 19:40
-
-
Save wallismu/b85b35b85f7c7c76727427389ddb0faf to your computer and use it in GitHub Desktop.
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 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