Code grooming.

master
Karchnu 2021-04-06 17:24:26 +02:00
parent 390659b000
commit f36c7d604e
1 changed files with 17 additions and 22 deletions

View File

@ -56,7 +56,7 @@ to_ascii(){
from_hex # Convert back from hex.
}
process_durations(){
process_end_of_songs(){
awk -v NONUMBER="$NONUMBER" -v SEPARATOR="$SEPARATOR" '
BEGIN {
@ -118,21 +118,20 @@ first_column_to_seconds(){
# Get a more usable time representation for the beginning and the end of songs.
process_time_file(){
to_ascii | first_column_to_seconds | process_durations
to_ascii | first_column_to_seconds | process_end_of_songs
}
run_ffmpeg(){
file=$1
from=$2
duration=$3
to=$3
final_title=$4
LOG_LEVEL="-loglevel error"
FROM="-ss $from"
if [ "$duration" = "" ]; then
DURATION=""
else
DURATION="-t $duration"
TO=""
if [ "$to" != "" ]; then
TO="-to $to"
fi
INPUT_FILE="-i $file"
OUTPUT_FILE="$final_title"
@ -144,7 +143,7 @@ run_ffmpeg(){
echo "extracting '$final_title'"
;;
v2)
echo "ffmpeg $LOG_LEVEL $FROM $DURATION $INPUT_FILE '$OUTPUT_FILE'"
echo "ffmpeg $LOG_LEVEL $FROM $TO $INPUT_FILE '$OUTPUT_FILE'"
;;
*)
echo "verbosity is not set properly" >&2
@ -153,28 +152,24 @@ run_ffmpeg(){
esac
if [ "$SIMULATION" = "" ]; then
$(< /dev/null ffmpeg $LOG_LEVEL $FROM $DURATION $INPUT_FILE "$OUTPUT_FILE")
$(< /dev/null ffmpeg $LOG_LEVEL $FROM $TO $INPUT_FILE "$OUTPUT_FILE")
fi
}
rip(){
track_start_s=0
track_end_s=0
audio_file="$1"
time_file="$2"
process_time_file < "$time_file" | while read LINE; do
track_start_s=$(echo $LINE | cut -d ' ' -f 1)
track_end_s=$(echo $LINE | cut -d ' ' -f 2)
track_start=$(echo $LINE | cut -d ' ' -f 1)
track_end=$(echo $LINE | cut -d ' ' -f 2)
track_title=$(echo $LINE | cut -d ' ' -f 3-)
if [ "$track_end_s" != "END_OF_FILE" ]; then
track_duration=$(echo "$track_end_s - $track_start_s" | bc)
else
track_duration=""
if [ "$track_end" = "END_OF_FILE" ]; then
track_end=""
fi
run_ffmpeg "${audio_file}" "${track_start_s}" "${track_duration}" "${track_title}.${FORMAT}"
run_ffmpeg "${audio_file}" "${track_start}" "${track_end}" "${track_title}.${FORMAT}"
done
}
@ -192,9 +187,9 @@ usage(){
echo "envvar: SEPARATOR [separator] (default: ' - '), write song number, with this separator"
echo " example with SEPARATOR='_': song names will be 01_song.opus 02_song.opus…"
echo "envvar: VERBOSITY [0-3] (default: 1)"
echo " VERBOSITY 0: no output exept errors from ffmpeg"
echo " VERBOSITY 1: simple indications on the current track being extracted"
echo " VERBOSITY 2: print actual ffmpeg commands the script currently runs"
echo " verbosity 0: no output exept errors from ffmpeg"
echo " verbosity 1: simple indications on the current track being extracted"
echo " verbosity 2: print actual ffmpeg commands the script currently runs"
}
if [ $# -lt 1 ]; then