Created
July 20, 2017 14:52
-
-
Save jackbergus/870c7da4f628408c61231d0b9a26bf0e to your computer and use it in GitHub Desktop.
Splists a file readable by ffmpeg into several mp3 files
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import unicodedata | |
import codecs | |
import re | |
from subprocess import call | |
import os.path | |
import string | |
import sys | |
f = codecs.open('convertall.sh', mode="a+", encoding='UTF-8') | |
f.write("#!/bin/sh\n") | |
def callConversion(file,int_time,to_time,out,format): | |
f = codecs.open('convertall.sh', mode="a+", encoding='UTF-8') | |
if to_time is not None: | |
f.write(" ".join(["ffmpeg", "-i", "\""+file+"\"", "-ss", str(int_time), "-to", str(to_time), "-c:a", "libmp3lame", "-b:a", "320k", "\""+filter(lambda x: x in set(string.printable), os.path.splitext(file)[0]+"/"+out+"."+format)+"\""])) | |
else: | |
f.write(" ".join(["ffmpeg", "-i", "\""+file+"\"", "-ss", str(int_time), "-c:a", "libmp3lame", "-b:a", "320k", "\""+filter(lambda x: x in set(string.printable), os.path.splitext(file)[0]+"/"+out+"."+format)+"\""])) | |
f.write('\n') | |
def parseAndRetrieve(x): | |
m = re.search("(\d\d):(\d\d)",x) | |
if m is not None: | |
time = int(m.group(1))*60 + int(m.group(2)) | |
string = x.replace(m.group(0),"").strip() | |
return (time,string) | |
def callCommand(x): | |
(int_time,out) = parseAndRetrieve(x) | |
#if l is not None: | |
# callConversion(tosplit,int_time,l[0],out) | |
#else: | |
# callConversion(tosplit,int_time,none,out) | |
tosplit = sys.argv[1] | |
f.write("mkdir \""+os.path.splitext(tosplit)[0]+"\"\n") | |
fname = sys.argv[2] | |
format = "mp3" | |
content = [] | |
with codecs.open(fname,'r',encoding='UTF-8') as f: | |
content = [parseAndRetrieve(x) for x in iter(f.readlines())] | |
content = map(lambda ((x,y),(z,t)): callConversion(tosplit,x,z,y,format), zip(content,content[1:]+[(None,"")])) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment