Comments.
parent
84422ac6ca
commit
0e8a90dd81
|
@ -1,31 +1,34 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# From a single byte in hexadecimal per line
|
||||
# to lines ending with 0a (hex for '\n').
|
||||
regroup_lines(){
|
||||
awk '
|
||||
BEGIN {
|
||||
first=1
|
||||
line_start=1
|
||||
}
|
||||
|
||||
{
|
||||
if (first == 1)
|
||||
if (line_start == 1)
|
||||
line = $1;
|
||||
else
|
||||
line = line " " $1;
|
||||
|
||||
first = 0;
|
||||
line_start = 0;
|
||||
if ($1 == "0a") {
|
||||
print line;
|
||||
first = 1
|
||||
line_start = 1
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if (first == 0)
|
||||
if (line_start == 0)
|
||||
print line
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
# From ’ to '
|
||||
simple_quote(){
|
||||
sed "s/e2 80 99/27/g"
|
||||
}
|
||||
|
@ -34,20 +37,23 @@ remove_multibyte_characters(){
|
|||
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
|
||||
}
|
||||
|
||||
# Reverse hexadecimal to original value.
|
||||
from_hex(){
|
||||
xxd -p -r
|
||||
}
|
||||
|
||||
# Remove non ascii characters, convert "’" to "'".
|
||||
to_ascii(){
|
||||
to_hex_one_colomun |
|
||||
regroup_lines |
|
||||
simple_quote |
|
||||
remove_multibyte_characters |
|
||||
from_hex
|
||||
to_hex_one_column | # Convert input into hexadecimal and a single byte per line.
|
||||
regroup_lines | # Required to easily match multi-byte characters.
|
||||
simple_quote | # Convert "’" to "'".
|
||||
remove_multibyte_characters | # Remove non ascii values.
|
||||
from_hex # Convert back from hex.
|
||||
}
|
||||
|
||||
process_durations(){
|
||||
|
@ -112,8 +118,7 @@ first_column_to_seconds(){
|
|||
|
||||
# Get a more usable time representation for the beginning and the end of songs.
|
||||
process_time_file(){
|
||||
time_file="$1"
|
||||
to_ascii < "$time_file" | first_column_to_seconds | process_durations
|
||||
to_ascii | first_column_to_seconds | process_durations
|
||||
}
|
||||
|
||||
run_ffmpeg(){
|
||||
|
@ -159,7 +164,7 @@ rip(){
|
|||
audio_file="$1"
|
||||
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_end_s=$(echo $LINE | cut -d ' ' -f 2)
|
||||
track_title=$(echo $LINE | cut -d ' ' -f 3-)
|
||||
|
@ -175,7 +180,7 @@ rip(){
|
|||
|
||||
usage(){
|
||||
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
|
||||
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 " 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
|
||||
|
@ -234,10 +239,6 @@ if [ "$SIMULATION" != "" ]; then
|
|||
echo "SIMULATION envvar is set: this is a simulation."
|
||||
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
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "xxd: you don't have an xxd program with '-p' option." 1>&2
|
||||
|
@ -254,12 +255,12 @@ case "x-${command}" in
|
|||
x-show)
|
||||
|
||||
# Takes the audio file in first parameter
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 show music-file time-stamps-file" >&2
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: $0 show time-stamps-file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
process_time_file "$2"
|
||||
process_time_file < "$1"
|
||||
;;
|
||||
|
||||
x-rip)
|
||||
|
@ -273,10 +274,6 @@ case "x-${command}" in
|
|||
rip "$1" "$2"
|
||||
;;
|
||||
|
||||
x-input)
|
||||
to_ascii < "$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage 1>&2
|
||||
exit 1
|
||||
|
|
Loading…
Reference in New Issue