Created
September 14, 2022 05:50
-
-
Save AfroThundr3007730/73380630ea7ff9e3ec331e52445c8371 to your computer and use it in GitHub Desktop.
Splits an audio file based on timestamps in a cuesheet
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
#!/bin/bash | |
# Splits an audio file based on timestamps in a cuesheet | |
split_music_compilation() { | |
[[ -f $1 ]] || { echo 'Audio file not found:' "$1"; return 1; } | |
[[ -f $2 ]] || { echo 'Cuesheet file not found:' "$2"; return 1; } | |
local source=$1 cuesheet=$2 count=0 pstamp='0:00' stamp title album | |
while read -r line; do | |
[[ $line =~ ([0-9]+:[0-9]+:[0-9]+).-.(.*).\[(.*)\] ]] && { | |
stamp=${BASH_REMATCH[1]} | |
title=${BASH_REMATCH[2]} | |
album=${BASH_REMATCH[3]} | |
[[ count -gt 0 ]] && nice -n 19 ionice -c 3 ffmpeg -i "$source" -ss "$pstamp" \ | |
-t $(($(date -d "$stamp" +%s)-$(date -d "$pstamp" +%s))) -c copy -v 0 \ | |
"$(printf '%02d - %s [%s].%s' "$count" "$ptitle" "$palbum" "${source##*.}")" & | |
((count++)) | |
pstamp=$stamp | |
ptitle=$title | |
palbum=$album | |
} | |
done < "$cuesheet" | |
nice -n 19 ionice -c 3 ffmpeg -i "$source" -ss "$pstamp" -c copy -v 0 \ | |
"$(printf '%02d - %s [%s].%s' "$count" "$title" "$album" "${source##*.}")" | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The accompanying cue sheet should be in the format below:
The regex can be adapted to handle other name formats.