Last active
September 23, 2017 03:46
-
-
Save beall49/a6f91ed00a1da0248e5d13772e438829 to your computer and use it in GitHub Desktop.
split mp3 in 20 min intervals using mp3splt
This file contains hidden or 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
""" | |
install mp3splt http://mp3splt.sourceforge.net/mp3splt_page/home.php | |
add to environment variable PATH=>C:\Program Files (x86)\mp3splt or | |
save and run this file from that location | |
""" | |
import os | |
import glob | |
from subprocess import call | |
class Mp3Split: | |
def __init__(self): | |
self.DIRECTORY = "A:\\Directory\\Where\\Your\\Files\\Are" | |
# change to whatever you want {} is for disc number | |
self.new_file_name = "new_file_name_{}" | |
self.output_dir = self.DIRECTORY + "output" | |
def create_output_directory(self): | |
if not os.path.exists(self.output_dir): | |
os.makedirs(self.output_dir) | |
def get_files(self): | |
return glob.glob(self.DIRECTORY + "*.mp3") | |
def get_new_file_name(self, disc_number): | |
return self.new_file_name.format(disc_number) | |
def get_cmd(self, mp3, output_name): | |
return " ".join([ | |
"mp3splt", | |
"\"{0}\"".format(mp3), | |
"-g", | |
"r%[@N=0,@t=\"{0}_@N\"]".format(output_name), | |
"-d", | |
"\"{0}\"".format(self.output_dir), | |
"-o", | |
"\"{0}_@n\"".format(output_name), | |
"-t", | |
"20.0" | |
]) | |
def split_files(self): | |
files = self.get_files() | |
for disc_number, mp3 in enumerate(files, start=1): | |
output_name = self.get_new_file_name(disc_number) | |
command = self.get_cmd(mp3, output_name) | |
print command | |
call(command) | |
def main(self): | |
self.create_output_directory() | |
self.split_files() | |
if __name__ == "__main__": | |
split = Mp3Split() | |
split.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment