Comments.

master
Karchnu 2021-04-06 16:09:15 +02:00
parent 84422ac6ca
commit 0e8a90dd81
1 changed files with 26 additions and 29 deletions

View File

@ -1,31 +1,34 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# From a single byte in hexadecimal per line
# to lines ending with 0a (hex for '\n').
regroup_lines(){ regroup_lines(){
awk ' awk '
BEGIN { BEGIN {
first=1 line_start=1
} }
{ {
if (first == 1) if (line_start == 1)
line = $1; line = $1;
else else
line = line " " $1; line = line " " $1;
first = 0; line_start = 0;
if ($1 == "0a") { if ($1 == "0a") {
print line; print line;
first = 1 line_start = 1
} }
} }
END { END {
if (first == 0) if (line_start == 0)
print line print line
} }
' '
} }
# From to '
simple_quote(){ simple_quote(){
sed "s/e2 80 99/27/g" sed "s/e2 80 99/27/g"
} }
@ -34,20 +37,23 @@ remove_multibyte_characters(){
sed "s/e2 80 .. //g" sed "s/e2 80 .. //g"
} }
to_hex_one_colomun(){ # Convert input into hexadecimal and a single byte per line.
to_hex_one_column(){
xxd -p -c 1 xxd -p -c 1
} }
# Reverse hexadecimal to original value.
from_hex(){ from_hex(){
xxd -p -r xxd -p -r
} }
# Remove non ascii characters, convert "" to "'".
to_ascii(){ to_ascii(){
to_hex_one_colomun | to_hex_one_column | # Convert input into hexadecimal and a single byte per line.
regroup_lines | regroup_lines | # Required to easily match multi-byte characters.
simple_quote | simple_quote | # Convert "" to "'".
remove_multibyte_characters | remove_multibyte_characters | # Remove non ascii values.
from_hex from_hex # Convert back from hex.
} }
process_durations(){ process_durations(){
@ -112,8 +118,7 @@ first_column_to_seconds(){
# Get a more usable time representation for the beginning and the end of songs. # Get a more usable time representation for the beginning and the end of songs.
process_time_file(){ process_time_file(){
time_file="$1" to_ascii | first_column_to_seconds | process_durations
to_ascii < "$time_file" | first_column_to_seconds | process_durations
} }
run_ffmpeg(){ run_ffmpeg(){
@ -159,7 +164,7 @@ rip(){
audio_file="$1" audio_file="$1"
time_file="$2" time_file="$2"
process_time_file "$time_file" | while read LINE; do process_time_file < "$time_file" | while read LINE; do
track_start_s=$(echo $LINE | cut -d ' ' -f 1) track_start_s=$(echo $LINE | cut -d ' ' -f 1)
track_end_s=$(echo $LINE | cut -d ' ' -f 2) track_end_s=$(echo $LINE | cut -d ' ' -f 2)
track_title=$(echo $LINE | cut -d ' ' -f 3-) track_title=$(echo $LINE | cut -d ' ' -f 3-)
@ -175,7 +180,7 @@ rip(){
usage(){ usage(){
echo "usage: $0 command" echo "usage: $0 command"
echo "command: show <single-file-playlist> <song-list>" echo "command: show <song-list>"
echo "command: rip <single-file-playlist> <song-list>" echo "command: rip <single-file-playlist> <song-list>"
echo echo
echo "song-list line format example: 1:30 My second track of the playlist" echo "song-list line format example: 1:30 My second track of the playlist"
@ -187,9 +192,9 @@ usage(){
echo "envvar: SEPARATOR [separator] (default: ' - '), write song number, with this separator" 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 " example with SEPARATOR='_': song names will be 01_song.opus 02_song.opus…"
echo "envvar: VERBOSITY [0-3] (default: 1)" echo "envvar: VERBOSITY [0-3] (default: 1)"
echo " verbosity 0: no output exept errors from ffmpeg" echo " VERBOSITY 0: no output exept errors from ffmpeg"
echo " verbosity 1: simple indications on the current track being extracted" echo " VERBOSITY 1: simple indications on the current track being extracted"
echo " verbosity 2: print actual ffmpeg commands the script currently runs" echo " VERBOSITY 2: print actual ffmpeg commands the script currently runs"
} }
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
@ -234,10 +239,6 @@ if [ "$SIMULATION" != "" ]; then
echo "SIMULATION envvar is set: this is a simulation." echo "SIMULATION envvar is set: this is a simulation."
fi fi
# soxi provides the total length of the music file.
#which soxi 2>/dev/null
#total_length=$(soxi -D "${audio_file}" | sed "s/\..*//") # integer values only
</dev/null xxd -p >/dev/null 2>/dev/null </dev/null xxd -p >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "xxd: you don't have an xxd program with '-p' option." 1>&2 echo "xxd: you don't have an xxd program with '-p' option." 1>&2
@ -254,12 +255,12 @@ case "x-${command}" in
x-show) x-show)
# Takes the audio file in first parameter # Takes the audio file in first parameter
if [ $# -ne 2 ]; then if [ $# -ne 1 ]; then
echo "Usage: $0 show music-file time-stamps-file" >&2 echo "Usage: $0 show time-stamps-file" >&2
exit 1 exit 1
fi fi
process_time_file "$2" process_time_file < "$1"
;; ;;
x-rip) x-rip)
@ -273,10 +274,6 @@ case "x-${command}" in
rip "$1" "$2" rip "$1" "$2"
;; ;;
x-input)
to_ascii < "$1"
;;
*) *)
usage 1>&2 usage 1>&2
exit 1 exit 1