Simpler code, README update (objective,usage,envvars) and better usage().

master get-tracks-0.4
Karchnu 2022-01-17 12:08:29 +01:00
parent 69e4cac809
commit 3f892dc644
2 changed files with 63 additions and 61 deletions

View File

@ -1,41 +1,56 @@
# Get Tracks
`get-tracks.sh` allows you to easily extract music tracks from a file with multiple songs, like a CD-in-a-file.
# Required applications
`get-tracks.sh` is a simple shell script based around `ffmpeg`, using `xxd` and `awk`.
* ffmpeg
* xxd (with '-r' and '-p' options)
* awk
It was tested on both OpenBSD and Linux.
# Usage
Download a CD and the starting time of each track in a file, and you're good to go.
```Bash
get-tracks.sh rip <audio-file> <time-file>
get-tracks.sh <audio-file> <time-file>
# Example
get-track.sh rip doom-eternal.opus doom-eternal.txt
get-track.sh doom-eternal.opus doom-eternal.txt
```
`audio-file` can be in any format understood by `ffmpeg`.
*audio-file* can be in any format understood by `ffmpeg`.
The `time-file` must have this format:
The *time-file* must have this format:
```
0:00 First song
2:20 Second song
0:00 intro
2:20 First song
3:18 Awesome song
```
# Environment variables
* **SIMULATION**: if non empty do not invoke ffmpeg
* **FORMAT** [mp3,ogg,opus,…]: for the song file format
* **NONUMBER**: if equals to 1, do not write song number
* **SEPARATOR**: (default: ' - '), write song number, with this separator
example with SEPARATOR='_': song names will be 01_song.opus 02_song.opus…
* **HEADERS**: if equals to 1, print environment parameters (verbosity, simulation, etc.)
* **SIMULATION** [empty or not]\
do not invoke ffmpeg
* **NONUMBER** [empty or 1]\
do not write song numbers
* **FORMAT** [mp3,ogg,opus,…]\
see the ffmpeg documentation for the output formats available
* **SEPARATOR** [separator] (default: ' - ')\
separator between number and name\
example with SEPARATOR='_': 01_intro.opus 02_blah.opus…
* **HEADERS** [empty or 1]\
print environment parameters (verbosity, simulation, etc.)
* **VERBOSITY** [0-3] (default: 1)\
verbosity 0: no output except errors from ffmpeg\
verbosity 1: simple indications on the current track being extracted\
verbosity 2: print actual ffmpeg commands the script currently runs
0: no output except errors from ffmpeg\
1: simple indications on the current track being extracted\
2: print actual ffmpeg commands the script currently runs
# More

View File

@ -161,23 +161,35 @@ rip(){
}
usage(){
echo "usage: $0 command"
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"
echo "show output format: start end title"
echo
echo "envvar: SIMULATION, if non empty, do not invoke ffmpeg"
echo "envvar: NONUMBER, if equals to 1, do not write song number"
echo "envvar: FORMAT [mp3,ogg,opus,…], see the ffmpeg documentation"
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: HEADERS, if equals to 1, print environment parameters (verbosity, simulation, etc.)"
echo "envvar: VERBOSITY [0-3] (default: 1)"
echo " verbosity 0: no output except 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"
cat <<END
Get tracks:
usage: $0 <single-file-playlist> <song-list>
Debug mode (displays starting and ending times for each song):
usage: $0 <song-list>
Format for <song-list>:
0:00 First track
1:30 Second track
Environment variables:
- SIMULATION [empty or not]
do not invoke ffmpeg
- NONUMBER [empty or 1]
do not write song numbers
- FORMAT [mp3,ogg,opus,…]
see the ffmpeg documentation
- SEPARATOR [separator] (default: ' - ')
separator between number and name
example with SEPARATOR='_': 01_intro.opus 02_blah.opus…
- HEADERS [empty or 1]
print environment parameters (verbosity, simulation, etc.)
- VERBOSITY [0-3] (default: 1)
0: no output except errors from ffmpeg
1: simple indications on the current track being extracted
2: print actual ffmpeg commands the script currently runs
END
}
if [ $# -lt 1 ]; then
@ -185,9 +197,6 @@ if [ $# -lt 1 ]; then
exit 0
fi
command=$1
shift
header(){
if [ "$HEADERS" = "1" ]; then
echo $*
@ -240,30 +249,8 @@ if [ $? -ne 0 ]; then
exit 1
fi
case "x-${command}" in
x-show)
# Takes the audio file in first parameter
if [ $# -ne 1 ]; then
echo "Usage: $0 show time-stamps-file" >&2
exit 1
fi
process_time_file < "$1"
;;
x-rip)
# Takes the audio file in first parameter
if [ $# -ne 2 ]; then
echo "Usage: $0 show music-file time-stamps-file" >&2
exit 1
fi
rip "$1" "$2"
;;
*)
usage 1>&2
exit 1
case $# in
1) process_time_file < "$1" ;;
2) rip "$1" "$2" ;;
*) usage 1>&2 ; exit 1 ;;
esac