|| return $?
}
+execute_program()
+{
+ local lib="$1"
+ local workdir="$2"
+
+ [ -f "$LIBS/$lib" ] \
+ || errlog "file $LIBS/$lib does not exists" \
+ || return $?
+
+ mkdir -p "$workdir"
+ make_symlinks_to_work "albumlist" "$workdir" "$MUSICPATH" || return $?
+ source "$LIBS/$lib" || return $?
+ execute "$workdir" || return $?
+}
+
convert_process()
{
local format="$1"
|| errlog "file albumlist does not exists" \
|| return $?
- mkdir -p $workdir
- make_symlinks_to_work "albumlist" "$workdir" $MUSICPATH \
- || return $?
-
case "$format" in
- "mp3")
- [ -f "$LIBS/mp3.sh" ] \
- || errlog "file $LIBS/mp3.sh does not exists" \
- || return $?
- source "$LIBS/mp3.sh" || return $?
- convert_flac_to_mp3 "$workdir" || return $?
- ;;
- "flac")
- [ -f "$LIBS/flac.sh" ] \
- || errlog "file $LIBS/mp3.sh does not exists" \
- || return $?
- source "$LIBS/flac.sh" || return $?
- picture_to_flac "$workdir"
- ;;
- "opus")
- [ -f "$LIBS/opus.sh" ] \
- || errlog "file $LIBS/mp3.sh does not exists" \
- || return $?
- source "$LIBS/opus.sh" || return $?
- convert_flac_to_opus "$workdir"
- ;;
- *)
- [ -f "$LIBS/voribs.sh" ] \
- || errlog "file $LIBS/mp3.sh does not exists" \
- || return $?
- source "$LIBS/voribs.sh" || return $?
- convert_flac_to_ogg "$workdir" || return $?
- ;;
+ "mp3") execute_program "mp3.sh" "$workdir" || return $? ;;
+ "flac") execute_program "flac.sh" "$workdir" || return $? ;;
+ "opus") execute_program "opus.sh" "$workdir" || return $? ;;
+ *) execute_program "vorbis.sh" "$workdir" || return $? ;;
esac
cleanup_cover "$workdir"
|| return $?
}
+execute()
+{
+ local workdir="$1"
+
+ picture_to_flac "$workdir" || return $?
+}
+
check_flac_programs
|| return $?
}
+execute()
+{
+ local workdir="$1"
+
+ convert_flac_to_mp3 "$workdir" || return $?
+}
+
check_mp3_programs
|| return $?
}
+execute()
+{
+ local workdir="$1"
+
+ convert_flac_to_opus "$workdir" || return $?
+}
+
check_opus_programs
--- /dev/null
+read_flac_to_ogg_tags()
+{
+ local inputfile="$1"
+ local outputfile="$2"
+ local coverfile="${inputfile%/*}/cover.txt"
+
+ metaflac --export-tags-to=- $inputfile \
+ | vorbiscomment --commentfile - --write $outputfile
+
+ [ -f $coverfile ] \
+ || return 0
+
+ echo "METADATA_BLOCK_PICTURE=$(base64 --wrap 0 $coverfile)" \
+ | vorbiscomment --commentfile - --raw --append $outputfile
+}
+
+encoding_flac_to_ogg()
+{
+ local inputfile="$1"
+ local outputfile="$2"
+
+ nice --adjustment=10 flac --totally-silent --stdout --decode \
+ "$inputfile" \
+ | nice --adjustment=15 oggenc --quiet --quality 6 \
+ --output "$outputfile" -
+}
+
+flac_to_vorbis()
+{
+ local inputfile="$1"
+ local outputfile="${inputfile/.flac/.ogg}"
+
+ encoding_flac_to_ogg "$inputfile" "$outputfile"
+ read_flac_to_ogg_tags "$inputfile" "$outputfile"
+}
+
+write_hex_to_file()
+{
+ local number="$1"
+ local outputfile="$2"
+ local hex_number=$(printf "%08x" "$number")
+
+ for i in {0..6..2}; do
+ printf "%b" "\x${hex_number:$i:2}" >> $outputfile
+ done
+}
+
+cover_to_metadata()
+{
+ local inputfile="$1"
+ local outputfile="${inputfile/.jpg/.txt}"
+ local filesize=$(cat $inputfile | wc -c)
+
+ # picture typ (jpg)
+ write_hex_to_file "3" "$outputfile"
+ # mime type (image/jpeg)
+ write_hex_to_file "10" "$outputfile"
+ printf "%s" "image/jpeg" >> $outputfile
+ # description length (zero)
+ write_hex_to_file "0" "$outputfile"
+ # width (zero)
+ write_hex_to_file "0" "$outputfile"
+ # heigth (zero)
+ write_hex_to_file "0" "$outputfile"
+ # color depth (zero)
+ write_hex_to_file "0" "$outputfile"
+ # color count (zero)
+ write_hex_to_file "0" "$outputfile"
+ # file size
+ write_hex_to_file "$filesize" "$outputfile"
+ cat $inputfile >> $outputfile
+}
+
+convert_flac_to_ogg()
+{
+ local workdir="$1"
+
+ export -f flac_to_vorbis
+ export -f encoding_flac_to_ogg
+ export -f read_flac_to_ogg_tags
+ export -f cover_to_metadata
+ export -f write_hex_to_file
+ find $workdir -name '*.jpg' \
+ | sort \
+ | parallel --will-cite --ungroup \
+ cover_to_metadata {}
+ find $workdir -name '*.flac' \
+ | sort \
+ | parallel --will-cite --ungroup --eta --progress \
+ flac_to_vorbis "{}"
+}
+
+check_vorbis_programs()
+{
+ command -v flac > /dev/null \
+ || errlog "command flac not found" \
+ || return $?
+ command -v metaflac > /dev/null \
+ || errlog "command metaflac not found" \
+ || return $?
+ command -v oggenc > /dev/null \
+ || errlog "command oggenc not found" \
+ || return $?
+ command -v vorbiscomment > /dev/null \
+ || errlog "command vorbiscomment not found" \
+ || return $?
+ command -v parallel > /dev/null \
+ || errlog "command parallel not found" \
+ || return $?
+}
+
+execute()
+{
+ local workdir="$1"
+
+ convert_flac_to_ogg "$workdir" || return $?
+}
+
+check_vorbis_programs
+++ /dev/null
-read_flac_to_ogg_tags()
-{
- local inputfile="$1"
- local outputfile="$2"
- local coverfile="${inputfile%/*}/cover.txt"
-
- metaflac --export-tags-to=- $inputfile \
- | vorbiscomment --commentfile - --write $outputfile
-
- [ -f $coverfile ] \
- || return 0
-
- echo "METADATA_BLOCK_PICTURE=$(base64 --wrap 0 $coverfile)" \
- | vorbiscomment --commentfile - --raw --append $outputfile
-}
-
-encoding_flac_to_ogg()
-{
- local inputfile="$1"
- local outputfile="$2"
-
- nice --adjustment=10 flac --totally-silent --stdout --decode \
- "$inputfile" \
- | nice --adjustment=15 oggenc --quiet --quality 6 \
- --output "$outputfile" -
-}
-
-flac_to_vorbis()
-{
- local inputfile="$1"
- local outputfile="${inputfile/.flac/.ogg}"
-
- encoding_flac_to_ogg "$inputfile" "$outputfile"
- read_flac_to_ogg_tags "$inputfile" "$outputfile"
-}
-
-write_hex_to_file()
-{
- local number="$1"
- local outputfile="$2"
- local hex_number=$(printf "%08x" "$number")
-
- for i in {0..6..2}; do
- printf "%b" "\x${hex_number:$i:2}" >> $outputfile
- done
-}
-
-cover_to_metadata()
-{
- local inputfile="$1"
- local outputfile="${inputfile/.jpg/.txt}"
- local filesize=$(cat $inputfile | wc -c)
-
- # picture typ (jpg)
- write_hex_to_file "3" "$outputfile"
- # mime type (image/jpeg)
- write_hex_to_file "10" "$outputfile"
- printf "%s" "image/jpeg" >> $outputfile
- # description length (zero)
- write_hex_to_file "0" "$outputfile"
- # width (zero)
- write_hex_to_file "0" "$outputfile"
- # heigth (zero)
- write_hex_to_file "0" "$outputfile"
- # color depth (zero)
- write_hex_to_file "0" "$outputfile"
- # color count (zero)
- write_hex_to_file "0" "$outputfile"
- # file size
- write_hex_to_file "$filesize" "$outputfile"
- cat $inputfile >> $outputfile
-}
-
-convert_flac_to_ogg()
-{
- local workdir="$1"
-
- export -f flac_to_vorbis
- export -f encoding_flac_to_ogg
- export -f read_flac_to_ogg_tags
- export -f cover_to_metadata
- export -f write_hex_to_file
- find $workdir -name '*.jpg' \
- | sort \
- | parallel --will-cite --ungroup \
- cover_to_metadata {}
- find $workdir -name '*.flac' \
- | sort \
- | parallel --will-cite --ungroup --eta --progress \
- flac_to_vorbis "{}"
-}
-
-check_vorbis_programs()
-{
- command -v flac > /dev/null \
- || errlog "command flac not found" \
- || return $?
- command -v metaflac > /dev/null \
- || errlog "command metaflac not found" \
- || return $?
- command -v oggenc > /dev/null \
- || errlog "command oggenc not found" \
- || return $?
- command -v vorbiscomment > /dev/null \
- || errlog "command vorbiscomment not found" \
- || return $?
- command -v parallel > /dev/null \
- || errlog "command parallel not found" \
- || return $?
-}
-
-check_vorbis_programs