From f1fd6f4a30414417455e4cb556ee0c01a844e2a8 Mon Sep 17 00:00:00 2001 From: Matthias Reis Date: Mon, 13 Dec 2021 16:08:06 +0100 Subject: [PATCH] Use ffprobe instead of mp3info for determining total length of album. This makes it possible to split files that are not in mp3 format. --- mp3-split | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) mode change 100755 => 100644 mp3-split diff --git a/mp3-split b/mp3-split old mode 100755 new mode 100644 index 1cb0ceb..ef096d5 --- a/mp3-split +++ b/mp3-split @@ -25,7 +25,7 @@ def timecode_to_secs(timecode): if len(timecode) == 3: hours = int(timecode[0]) mins = int(timecode[1]) - secs = int(timecode[2])+(mins*60)+(hours*3600) + secs = int(math.ceil(float(timecode[2])))+(mins*60)+(hours*3600) elif len(timecode) == 2: mins = int(timecode[0]) secs = int(timecode[1])+(mins*60) @@ -113,21 +113,20 @@ for line in data: #ffmpeg -i your_audio_file.mp3 -acodec copy -t 00:30:00 -ss 00:00:00 half_hour_split.mp3 -call = ['mp3info', '-p', '"%S"', mp3Path] -print_call(call) -mp3SecsRaw = subprocess.check_output(call) -mp3Secs = int(re.match(r'.*?([0-9]{1,}).*', str(mp3SecsRaw), flags=0).group(1)) +call = ["ffprobe", mp3Path] +mp3SecsRaw = subprocess.run(call, capture_output=True, text=True).stderr -mp3Len = secs_to_timecode(mp3Secs) +mp3Len = re.search(r'Duration:\s(.*?),', mp3SecsRaw, re.MULTILINE).group(1) timecodes.append(mp3Len) print('\nAudio ends at ', mp3Len) +filename, fileExtension = os.path.splitext(mp3Path) _ffmpeg_call = ['ffmpeg', '-i', mp3Path, '-acodec', 'copy', '-t', '