Created
November 29, 2020 22:13
-
-
Save FromDarkHell/72222eef971f0ae7bd003050aef66f1a to your computer and use it in GitHub Desktop.
Lego Creator: Python Parsers
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 subprocess | |
import os | |
import glob | |
# Add mutagen | |
from mutagen.mp3 import MP3 | |
from mutagen.easyid3 import EasyID3 | |
for file in glob.glob("./sound/*.wav"): | |
outFile = f"./mp3/{os.path.splitext(os.path.basename(file))[0]}.mp3" | |
if os.path.exists(outFile): | |
print(f"{os.path.basename(file)} exists... Not converting!") | |
continue | |
print(f"Converting {os.path.basename(file)}") | |
cmd = f"ffmpeg -i {file} -acodec libmp3lame {outFile} -y" | |
subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
print("Done globbing wav files...\n") | |
fileToSongName = { | |
"cos.mp3": "Chamber of Secrets", | |
"diagon.mp3": "Diagon Alley", | |
"fforest.mp3": "Forbidden Forest", | |
"gring.mp3": "Gringotts Bank", | |
"hagext.mp3": "Hagrid's Hut Exterior", | |
"hagint.mp3": "Hagrid's Hut Interior", | |
"hogdung.mp3": "Hogwarts Dungeon", | |
"hogext.mp3": "Hogwarts Exterior", | |
"int.mp3": "Interior", | |
"knockturn.mp3": "Knockturn Alley", | |
"minifigshop.mp3": "Mini-Fig Shop", | |
"olli.mp3": "Ollivander's", | |
"qpitch.mp3": "Quidditch Pitch", | |
"title.mp3": "Lego Creator: Harry Potter and the CoS Title", | |
"workshop.mp3": "Workshop Theme", | |
} | |
songNum = 1 | |
for file in glob.glob("./mp3/*.mp3"): | |
fileName = os.path.basename(file) | |
print(f"Adding ID3 tags to {fileName}") | |
mp3file = MP3(file, ID3=EasyID3) | |
mp3file["album"] = ["Lego Creator: Harry Potter and the Chamber of Secrets"] | |
mp3file["albumartist"] = ["Earcom Ltd", "Paul Weir", "Mariko Ohtake"] | |
mp3file["title"] = fileToSongName[fileName] | |
mp3file["tracknumber"] = f"{songNum}/{len(fileToSongName)}" | |
mp3file.save() | |
songNum += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment