Shell: audio tc batch+cover support finished.
parent
c3da2d8b3e
commit
66c427e7c9
|
@ -78,7 +78,8 @@ tc_text_2utf8 ()
|
||||||
|
|
||||||
## For the sake of simplicity we convert everything to OGG.
|
## For the sake of simplicity we convert everything to OGG.
|
||||||
## You can easily set output folder to current folder with TC_AUDIO_DEST=".".
|
## You can easily set output folder to current folder with TC_AUDIO_DEST=".".
|
||||||
TC_AUDIO_DEST="/media/data1/Musics/"
|
# TC_AUDIO_DEST="/media/data1/Musics/"
|
||||||
|
TC_AUDIO_DEST="$HOME/audio/"
|
||||||
|
|
||||||
## OGG quality ranges from -1 to 10.
|
## OGG quality ranges from -1 to 10.
|
||||||
## -q-1 45 kbit/s
|
## -q-1 45 kbit/s
|
||||||
|
@ -108,15 +109,43 @@ tc_audio_scan()
|
||||||
echo "void"
|
echo "void"
|
||||||
}
|
}
|
||||||
|
|
||||||
## TODO: cover resolution check. Should be > 100x100. Above <1000x1000 should give a warning.
|
|
||||||
## TODO: extract cover from tags if checksum does not match any from current folder.
|
tc_audio_batch()
|
||||||
|
{
|
||||||
|
|
||||||
|
OLDIFS=$IFS
|
||||||
|
IFS="
|
||||||
|
"
|
||||||
|
|
||||||
|
for i in $(find "." \( \
|
||||||
|
-iname '*.mp3' -o \
|
||||||
|
-iname '*.flac' -o \
|
||||||
|
-iname '*.wv' -o \
|
||||||
|
-iname '*.aac' -o \
|
||||||
|
-iname '*.wav' -o \
|
||||||
|
-iname '*.ape' -o \
|
||||||
|
-iname '*.mpc' \) ); do
|
||||||
|
tc_audio_transcode "$@" $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# for i in *.mp3 ; do tc_audio_transcode "$@" $i ; done
|
||||||
|
# tc_audio_transcode "$@" "01 James Russo - Winged.mp3"
|
||||||
|
|
||||||
|
IFS=$OLDIFS
|
||||||
|
unset OLDIFS
|
||||||
|
}
|
||||||
|
|
||||||
## This function is supposed to work on a per-album basis. Folders will not be
|
## This function is supposed to work on a per-album basis. Folders will not be
|
||||||
## accepted as argument. This function will work best if all tracks of a folder
|
## accepted as argument. This function will work best if all tracks of a folder
|
||||||
## belong to the same album. Theres is no way to handle covers raliably, so you
|
## belong to the same album. Theres is no way to handle covers raliably, so you
|
||||||
## should leave the only covers you want to keep in the working folder.
|
## should leave the only covers you want to keep in the working folder.
|
||||||
|
|
||||||
|
## TODO: cover resolution check. Should be > 100x100. Above <1000x1000 should give a warning.
|
||||||
|
## TODO: extract cover from tags if checksum does not match any from current folder.
|
||||||
tc_audio_transcode()
|
tc_audio_transcode()
|
||||||
{
|
{
|
||||||
|
IFS=${OLDIFS:-$IFS}
|
||||||
|
|
||||||
_printhelp ()
|
_printhelp ()
|
||||||
{
|
{
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -199,7 +228,7 @@ EOF
|
||||||
local OUTPUT
|
local OUTPUT
|
||||||
local OUTPUT_FILE
|
local OUTPUT_FILE
|
||||||
OUTPUT='$TC_AUDIO_DEST/$OUTPUT_ARTIST/${OUTPUT_ALBUM:+${OUTPUT_YEAR:+$OUTPUT_YEAR - }$OUTPUT_ALBUM/}'
|
OUTPUT='$TC_AUDIO_DEST/$OUTPUT_ARTIST/${OUTPUT_ALBUM:+${OUTPUT_YEAR:+$OUTPUT_YEAR - }$OUTPUT_ALBUM/}'
|
||||||
OUTPUT_FILE='$OUTPUT$OUTPUT_ARTIST - ${OUTPUT_PADDEDTRACK:+$OUTPUT_PADDEDTRACK - }$OUTPUT_TITLE.$OUTPUT_FORMAT'
|
OUTPUT_FILE='$OUTPUT$OUTPUT_ARTIST - ${OUTPUT_PADDEDTRACK:+$OUTPUT_PADDEDTRACK - }$OUTPUT_TITLE'
|
||||||
|
|
||||||
while getopts ":a:b:d:g:l:n:t:hps" opt; do
|
while getopts ":a:b:d:g:l:n:t:hps" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
|
@ -250,6 +279,12 @@ EOF
|
||||||
METADATA=$(echo "$STREAM" | sed -n '/Metadata/ ! d; /Metada/{b cont}; :cont ; {n;p;b cont}')
|
METADATA=$(echo "$STREAM" | sed -n '/Metadata/ ! d; /Metada/{b cont}; :cont ; {n;p;b cont}')
|
||||||
STREAM=$(echo "$STREAM" | grep "Stream")
|
STREAM=$(echo "$STREAM" | grep "Stream")
|
||||||
|
|
||||||
|
if [ -z "$STREAM" ]; then
|
||||||
|
echo "Non-audio file."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
## We get format from extension, because codec is not reliable either.
|
## We get format from extension, because codec is not reliable either.
|
||||||
local FORMAT
|
local FORMAT
|
||||||
FORMAT="${1##*.}"
|
FORMAT="${1##*.}"
|
||||||
|
@ -292,7 +327,7 @@ EOF
|
||||||
TYER=$(_metadata_filter "TYER")
|
TYER=$(_metadata_filter "TYER")
|
||||||
|
|
||||||
##================================================================================
|
##================================================================================
|
||||||
## OUTPUT_* variables.
|
## OUTPUT variables.
|
||||||
|
|
||||||
_string_cleanser()
|
_string_cleanser()
|
||||||
{
|
{
|
||||||
|
@ -333,12 +368,11 @@ EOF
|
||||||
## We remove the track count if any, we suppress leading zeros.
|
## We remove the track count if any, we suppress leading zeros.
|
||||||
OUTPUT_TRACK=$(eval _string_cleanser $OUTPUT_TRACK | sed -e 's/^0*//' -e 's|/.*||')
|
OUTPUT_TRACK=$(eval _string_cleanser $OUTPUT_TRACK | sed -e 's/^0*//' -e 's|/.*||')
|
||||||
|
|
||||||
## FIXME: ...
|
|
||||||
## If DATE is not a year, we use TYER if it is a year.
|
## If DATE is not a year, we use TYER if it is a year.
|
||||||
OUTPUT_DATE=$(eval _string_cleanser $OUTPUT_DATE)
|
OUTPUT_DATE=$(eval _string_cleanser $OUTPUT_DATE)
|
||||||
local TYER_REG=$(echo "$TYER" | sed -n 's/.*\([[:digit:]]\{4\}\).*/\1/p')
|
local TYER_REG=$(echo "$TYER" | sed -n 's/.*\([[:digit:]]\{4\}\).*/\1/p')
|
||||||
if [ ${#DATE} -ne 4 ] && [ ${#TYER} -eq 4 ]; then
|
if [ ${#DATE} -ne 4 ] && [ ${#TYER_REG} -eq 4 ]; then
|
||||||
OUTPUT_DATE="$TYER"
|
OUTPUT_DATE="$TYER_REG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Only reencode if not in OGG and if SKIP not set.
|
## Only reencode if not in OGG and if SKIP not set.
|
||||||
|
@ -346,7 +380,7 @@ EOF
|
||||||
[ "$FORMAT" = "ogg" ] && OGG_PARAM=""
|
[ "$FORMAT" = "ogg" ] && OGG_PARAM=""
|
||||||
|
|
||||||
## QUALITY
|
## QUALITY
|
||||||
## TODO: test if table is worth it.
|
## TODO: test if table is useful at all.
|
||||||
[ $OUTPUT_BITRATE -eq 0 ] && OUTPUT_BITRATE=${BITRATE}
|
[ $OUTPUT_BITRATE -eq 0 ] && OUTPUT_BITRATE=${BITRATE}
|
||||||
# if [ $OUTPUT_BITRATE -eq 0 ]; then
|
# if [ $OUTPUT_BITRATE -eq 0 ]; then
|
||||||
# [ $BITRATE -le 45 ] && OUTPUT_BITRATE=45k
|
# [ $BITRATE -le 45 ] && OUTPUT_BITRATE=45k
|
||||||
|
@ -404,7 +438,8 @@ EOF
|
||||||
echo "TRACK [$OUTPUT_TRACK]"
|
echo "TRACK [$OUTPUT_TRACK]"
|
||||||
echo
|
echo
|
||||||
echo "==> OUTPUT"
|
echo "==> OUTPUT"
|
||||||
echo "[$OUTPUT_FILE]"
|
echo "[$OUTPUT_FILE.$OUTPUT_FORMAT]"
|
||||||
|
echo
|
||||||
|
|
||||||
[ $PREVIEW -ne 0 ] && return
|
[ $PREVIEW -ne 0 ] && return
|
||||||
|
|
||||||
|
@ -418,31 +453,27 @@ EOF
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## COVER
|
## COVER
|
||||||
## We copy cover only if it does not already exist.
|
## We copy cover only if it does not already exist.
|
||||||
local OUTPUT_COVER
|
local OUTPUT_COVER
|
||||||
local COVER_COUNTER
|
local COVER_COUNTER
|
||||||
OUTPUT_COVER="$OUTPUT/"
|
OUTPUT_COVER="$OUTPUT/${OUTPUT_ALBUM:+$OUTPUT_ALBUM - }Cover"
|
||||||
[ -n "$ALBUM" ] && OUTPUT_COVER="$OUTPUT_COVER$ALBUM - "
|
|
||||||
for i in $(find "." \( \
|
for i in $(find "." \( \
|
||||||
-iname '*.png' -o \
|
-iname '*.png' -o \
|
||||||
-iname '*.jpg' \) ); do
|
-iname '*.jpg' \) ); do
|
||||||
|
|
||||||
OUTPUT_COVER="${OUTPUT_COVER}Cover.${i##*.}"
|
OUTPUT_COVER="${OUTPUT_COVER}.${i##*.}"
|
||||||
COVER_COUNTER=1
|
COVER_COUNTER=1
|
||||||
|
|
||||||
if [ ! "$(sha1sum $OUTPUT_COVER | cut -f1 -d' ')" = "$(sha1sum $i | cut -f1 -d' ')" ]; then
|
while [ -e "$OUTPUT_COVER" ] && \
|
||||||
|
[ ! "$(sha1sum $OUTPUT_COVER | cut -f1 -d' ')" = "$(sha1sum $i | cut -f1 -d' ')" ]; do
|
||||||
while [ -e "$OUTPUT_COVER" ]; do
|
OUTPUT_COVER="${OUTPUT_COVER%.*} $COVER_COUNTER.${i##*.}"
|
||||||
OUTPUT_COVER="${OUTPUT_COVER}Cover $COVER_COUNTER.${i##*.}"
|
|
||||||
COVER_COUNTER=$(($COVER_COUNTER+1))
|
COVER_COUNTER=$(($COVER_COUNTER+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
## DEBUG only.
|
## DEBUG only.
|
||||||
# echo "cp -nv $i [$OUTPUT_COVER]"
|
# echo "cp -nv $i [$OUTPUT_COVER]"
|
||||||
cp -nv "$i" "$OUTPUT_COVER"
|
cp -nv "$i" "$OUTPUT_COVER"
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
## Zsh compatibility. We need it otherwise word splitting of parameter like
|
## Zsh compatibility. We need it otherwise word splitting of parameter like
|
||||||
|
@ -452,6 +483,7 @@ EOF
|
||||||
[ "$STATUS" = "off" ] && set -o shwordsplit
|
[ "$STATUS" = "off" ] && set -o shwordsplit
|
||||||
|
|
||||||
## TAG/RECODE
|
## TAG/RECODE
|
||||||
|
# ffmpeg -i "$1" -c:a libvorbis -b:a ${OUTPUT_BITRATE}k \
|
||||||
ffmpeg -i "$1" $OGG_PARAM \
|
ffmpeg -i "$1" $OGG_PARAM \
|
||||||
-metadata title="$OUTPUT_TITLE" \
|
-metadata title="$OUTPUT_TITLE" \
|
||||||
-metadata artist="$OUTPUT_ARTIST" \
|
-metadata artist="$OUTPUT_ARTIST" \
|
||||||
|
|
Loading…
Reference in New Issue