Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ffprobe instead of mp3info for determining total length of album.… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions mp3-split
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -113,32 +113,32 @@ 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', '<time>', '-ss', '<start>', '<out.mp3>']
_eyeD3_call = ['eyeD3', '-n', '<num>', '-t', '<track>', '<file.mp3>']
for i in range(0, len(timecodes)-1):
outFileName = trackNames[i]+'.mp3'
outFileName = trackNums[i] + " " + trackNames[i] + fileExtension

call = list(_ffmpeg_call)
call[6] = timecode_diff(timecodes[i+1], timecodes[i])
call[8] = timecodes[i]
call[9] = outFileName
print_call(call)
subprocess.check_output(call)

call = list(_eyeD3_call)
call[2] = trackNums[i]
call[4] = trackNames[i]
call[5] = outFileName
print_call(call)
subprocess.check_output(call)

if fileExtension == ".mp3":
call = list(_eyeD3_call)
call[2] = trackNums[i]
call[4] = trackNames[i]
call[5] = outFileName
print_call(call)
subprocess.check_output(call)