add "copy" destination type

This commit is contained in:
Vincent Riquer 2017-06-18 18:21:18 +02:00
parent 6c438c4c90
commit d16b31f479
10 changed files with 308 additions and 265 deletions

View File

@ -9,6 +9,9 @@ getConfigDestination() {
'mp3') 'mp3')
destinationformat["$destination"]=mp3 destinationformat["$destination"]=mp3
lameneeded=1 lameneeded=1
# MP3 can't handfle more than 2 channels
[[ -z ${destinationchannels["$destination"]} ]] \
&& destinationchannels["$destination"]=2
;; ;;
'opus') 'opus')
destinationformat["$destination"]=opus destinationformat["$destination"]=opus
@ -18,6 +21,9 @@ getConfigDestination() {
destinationformat["$destination"]=vorbis destinationformat["$destination"]=vorbis
oggencneeded=1 oggencneeded=1
;; ;;
'copy')
destinationformat["$destination"]=copy
;;
*) *)
echo "Unsupported destination format: $value" >&2 echo "Unsupported destination format: $value" >&2
exit $EFORMAT exit $EFORMAT

View File

@ -48,10 +48,10 @@ printConfig() {
EOF EOF
[ -n "${destinationskipmime["$destination"]}" ] \ [ -n "${destinationskipmime["$destination"]}" ] \
&& echo " |Skipped mime-types|${destinationskipmime["$destination"]//\|/ && echo " |Skipped mime-types|${destinationskipmime["$destination"]//\|/
||}" | | |}"
[ -n "${destinationmskipime["$destination"]}" ] \ [ -n "${destinationcopymime["$destination"]}" ] \
&& echo " |Copied mime-types|${destinationcopymime["$destination"]//\|/ && echo " |Copied mime-types|${destinationcopymime["$destination"]//\|/
||}" | | |}"
done done
}|column -t -s'|' }|column -t -s'|'
} }

View File

@ -63,8 +63,8 @@ path $sourcepath
# * path: Where files will be written # * path: Where files will be written
path ${destinationpath["$destination"]} path ${destinationpath["$destination"]}
# * format: ogg, opus or mp3. Other formats may appear in the future - feel # * format: copy, ogg, opus or mp3. Other formats may appear in the future -
# free to implement your preferred format. # feel free to implement your preferred format.
format ${destinationformat["$destination"]} format ${destinationformat["$destination"]}
EOCfg EOCfg

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
declare soxtaskid declare soxtaskid
decodeFile() { decodeFile() {
if [[ ${destinationformat["$destination"]} == copy ]]
then
copied=1
else
case "$mimetype" in case "$mimetype" in
'video/'*) 'video/'*)
(( disablevideo )) && continue (( disablevideo )) && continue
@ -148,4 +152,5 @@ decodeFile() {
fi fi
fi fi
fi fi
fi
} }

View File

@ -38,6 +38,25 @@ getDestDir() {
) )
) )
then then
if (( ${destinationascii["$destination"]} ))
then
echo "$album" >&${toascii[1]}
read -r -u${toascii[0]} album
echo "$albumartist" >&${toascii[1]}
read -r -u${toascii[0]} albumartist
echo "$artist" >&${toascii[1]}
read -r -u${toascii[0]} artist
echo "$genre" >&${toascii[1]}
read -r -u${toascii[0]} genre
echo "$title" >&${toascii[1]}
read -r -u${toascii[0]} title
echo "$tracknumber" >&${toascii[1]}
read -r -u${toascii[0]} tracknumber
echo "$year" >&${toascii[1]}
read -r -u${toascii[0]} year
echo "$disc" >&${toascii[1]}
read -r -u${toascii[0]} disc
fi
replace=$(sanitizeFile "$album" dir) replace=$(sanitizeFile "$album" dir)
destdir+="${destinationrenamepath[$destination]//?(\[)%\{album\}?(\])/$replace}" destdir+="${destinationrenamepath[$destination]//?(\[)%\{album\}?(\])/$replace}"
replace=$(sanitizeFile "$albumartist" dir) replace=$(sanitizeFile "$albumartist" dir)
@ -60,14 +79,15 @@ getDestDir() {
part=${filename#*/} part=${filename#*/}
while [[ $part =~ / ]] while [[ $part =~ / ]]
do do
destdir+="/$(sanitizeFile "${part%%/*}" dir)" thispart="${part%%/*}"
part=${part#*/}
done
fi
if (( ${destinationascii["$destination"]} )) if (( ${destinationascii["$destination"]} ))
then then
echo "$destdir" >&${toascii[1]} echo "$thispart" >&${toascii[1]}
read -r -u${toascii[0]} destdir read -r -u${toascii[0]} thispart
fi
destdir+="/$(sanitizeFile "$thispart" dir)"
part=${part#*/}
done
fi fi
if ! [ -d "$destdir" ] if ! [ -d "$destdir" ]
then then

View File

@ -13,7 +13,7 @@ sanitizeFile() {
string=${string//>/ } string=${string//>/ }
string=${string//:/ } string=${string//:/ }
string=${string//\*/ } string=${string//\*/ }
string=${string//|/ } string=${string//\|/ }
string=${string//\"/ } string=${string//\"/ }
# Filenames can't begin or end with ' ' # Filenames can't begin or end with ' '

View File

@ -4,7 +4,7 @@ setupDestination() {
cat <<-EODesc cat <<-EODesc
Format: Format:
vorbis, opus or mp3. Other formats may appear in the future. copy, vorbis, opus or mp3. Other formats may appear in the future.
EODesc EODesc
comeagain() { comeagain() {
read \ read \
@ -25,6 +25,9 @@ setupDestination() {
destinationformat["$destination"]=vorbis destinationformat["$destination"]=vorbis
oggencneeded=1 oggencneeded=1
;; ;;
'copy')
destinationformat["$destination"]=copy
;;
*) *)
echo "Unsupported destination format: $value" >&2 echo "Unsupported destination format: $value" >&2
comeagain comeagain
@ -44,6 +47,9 @@ setupDestination() {
${destinationpath["$destination"]+-i"${destinationpath["$destination"]}"}\ ${destinationpath["$destination"]+-i"${destinationpath["$destination"]}"}\
destinationpath["$destination"] destinationpath["$destination"]
case ${destinationformat["$destination"]} in case ${destinationformat["$destination"]} in
copy)
:
;;
vorbis) vorbis)
cat <<-EODesc cat <<-EODesc
@ -199,6 +205,8 @@ setupDestination() {
Now you will have the opportunity to configure "advanced" parameters Now you will have the opportunity to configure "advanced" parameters
for $destination. You may leave any of these fields blank. for $destination. You may leave any of these fields blank.
EODesc EODesc
if [[ ${destinationformat["$destination"]} != copy ]]
then
cat <<-EODesc cat <<-EODesc
Normalize (boolean): Normalize (boolean):
@ -232,6 +240,7 @@ setupDestination() {
esac esac
} }
comeagain comeagain
fi
cat <<-EODesc cat <<-EODesc
Rename (string): Rename (string):
@ -362,6 +371,8 @@ setupDestination() {
fi fi
done done
unset skippedmimes unset skippedmimes
if [[ ${destinationformat["$destination"]} != copy ]]
then
cat <<-EODesc cat <<-EODesc
Copy mime-type (mime-type, string): Copy mime-type (mime-type, string):
@ -492,4 +503,5 @@ setupDestination() {
destinationmaxbps[$destination]="$value" destinationmaxbps[$destination]="$value"
unset regen unset regen
unset expr unset expr
fi
} }

View File

@ -65,7 +65,7 @@ setupDestinations() {
expr='^[A-z0-9]*$' expr='^[A-z0-9]*$'
comeagain() { comeagain() {
read -p'Name: ' value read -p'Name: ' value
[ -z "$value" ] && break [ -z "$value" ] && return 1
if ! [[ $value =~ $expr ]] if ! [[ $value =~ $expr ]]
then then
echo "Invalid name $value. Please use" \ echo "Invalid name $value. Please use" \
@ -73,7 +73,7 @@ setupDestinations() {
comeagain comeagain
fi fi
} }
comeagain comeagain || break
destination="$value" destination="$value"
setupDestination setupDestination
done done

View File

@ -2,5 +2,5 @@
extractAudio() { extractAudio() {
tmpfile="${fileid}ffmpeg.wav" tmpfile="${fileid}ffmpeg.wav"
commandline=(${ionice}ffmpeg -v 0 -vn -y) commandline=(${ionice}ffmpeg -v 0 -vn -y)
commandline+=(-i "$sourcepath/$filename" "$tempdir/$tmpfile") commandline+=(-i "$sourcepath/$filename" -map a:0 "$tempdir/$tmpfile")
} }

View File

@ -92,7 +92,7 @@ master() {
if (( remaining == 0 )) if (( remaining == 0 ))
then then
sleep 0.1 sleep 0.1
continue return 0
elif (( active == 0 && ready == 0 )) elif (( active == 0 && ready == 0 ))
then then
dumpfile=tasks-$(date +%Y%m%d%H%M%S).csv dumpfile=tasks-$(date +%Y%m%d%H%M%S).csv