EOF
}
-cleanup_flac()
+check_programms()
{
- local workdir="$1"
+ command -v rsync > /dev/null \
+ || errlog "command rsync not found" \
+ || return $?
+}
- [ -n "$workdir" ] \
- || errlog "missing workdir could not cleanup" \
+load_config()
+{
+ [ -f "$HOME/.albentohandy.conf" ] \
+ || errlog "file $HOME/.albentohandy.conf does not exists" \
|| return $?
+ # shellcheck disable=SC1091
+ source "$HOME/.albentohandy.conf"
- find "$workdir" -name '*.flac' -exec rm {} \;
+ [ -n "$MUSICPATH" ] \
+ || errlog "missing MUSICPATH" \
+ || return $?
}
cleanup_cover()
{
- local workdir="$1"
- local cover="$2"
-
- [ -n "$workdir" ] \
- || errlog "missing workdir could not cleanup" \
- || return $?
+ local cover="$1"
+ local workdir="$2"
find "$workdir" -name 'cover.txt' -exec rm {} \;
+ [ "$cover" == "false" ] || return 0
+ find "$workdir" -name 'cover.jpg' -exec rm {} \;
+}
- [ "$cover" == "false" ] \
- || return 0
+cleanup_flac()
+{
+ local lib="$1"
+ local workdir="$2"
- find "$workdir" -name 'cover.jpg' -exec rm {} \;
+ [ "$lib" != "flac.sh" ] || return 0
+ [ -n "$workdir" ] \
+ || errlog "missing workdir could not cleanup" \
+ || return $?
+ find "$workdir" -name '*.flac' -exec rm {} \;
}
make_symlinks_to_work()
{
local albumlist="$1"
local workdir="$2"
- local musicpath="$3"
+ local alben=()
+ mapfile -t alben < <(cat "$albumlist")
- while IFS= read -r album; do
- [ -d "$musicpath/$album" ] \
- || errlog "directory $musicpath/$album does not exists" \
+ local album=
+ for album in "${alben[@]}"; do
+ [ -d "$MUSICPATH/$album" ] \
+ || errlog "directory $MUSICPATH/$album does not exists" \
|| return $?
cp --recursive \
--symbolic-link \
- "$musicpath/$album" \
+ "$MUSICPATH/$album" \
"$workdir" \
- || errlog "could not copy symlinks from $musicpath/$album" \
+ || errlog "could not copy symlinks from $MUSICPATH/$album" \
|| return $?
rsync --recursive \
--perms \
--owner \
--exclude="*.flac" \
--include="cover.jpg" \
- "$musicpath/$album" \
+ "$MUSICPATH/$album" \
"$workdir" \
|| errlog "could not copy etc like cover" \
|| return $?
- done < "$albumlist"
-}
-
-load_config()
-{
- [ -f "$HOME/.albentohandy.conf" ] \
- || errlog "file $HOME/.albentohandy.conf does not exists" \
- || return $?
-
- # shellcheck disable=SC1091
- source "$HOME/.albentohandy.conf"
-}
-
-check_programms()
-{
- command -v rsync > /dev/null \
- || errlog "command rsync not found" \
- || return $?
+ done
}
-execute_program()
+calc_checksum()
{
- local lib="$1"
+ local checksum="$1"
local workdir="$2"
- local scriptpath=
- scriptpath=$(dirname "$(realpath "$0")")
-
- [ -f "$scriptpath/libs/$lib" ] \
- || errlog "file $scriptpath/libs/$lib does not exists" \
- || return $?
- # shellcheck disable=SC1090
- source "$scriptpath/libs/$lib" || return $?
-
- mkdir -p "$workdir"
- make_symlinks_to_work "albumlist" "$workdir" "$MUSICPATH" || return $?
- execute "$workdir" || return $?
-}
-
-checksum()
-{
- local workdir="$1"
- local checksum="$2"
[ "$checksum" == "true" ] || return 0
-
cd "$workdir" || return 1
find . -type f \
| sort \
|| return $?
}
-convert_process()
-{
- local format="$1"
- local cover="$2"
- local checksum="$3"
- local workdir="work.$$"
-
- [ -f "albumlist" ] \
- || errlog "file albumlist does not exists" \
- || return $?
-
- execute_program "$format.sh" "$workdir" || return $?
- cleanup_cover "$workdir" "$cover" || return $?
- [ "$format" != "flac" ] && cleanup_flac "$workdir"
- checksum "$workdir" "$checksum" || return $?
-}
-
main()
{
- local format=${format:="vorbis"}
+ local lib="vorbis.sh"
local cover="false"
local checksum="false"
+ local workdir="work.$$"
+ local albumlist="albumlist"
+ local scriptpath=
+ scriptpath=$(dirname "$(realpath "$0")")
+ local libpath="$scriptpath/libs"
check_programms || return $?
load_config || return $?
- [ -n "$MUSICPATH" ] \
- || errlog "missing MUSICPATH" \
- || return $?
-
while getopts "3cfhko" optname; do
case "$optname" in
- "3") format="mp3" ;;
+ "3") lib="mp3.sh" ;;
"c") checksum="true" ;;
- "f") format="flac" ;;
+ "f") lib="flac.sh" ;;
"h") usage && return 0 ;;
"k") cover="true" ;;
- "o") format="opus" ;;
+ "o") lib="opus.sh" ;;
"*") echo "unkwnon parameter" ;;
esac
done
- convert_process "$format" "$cover" "$checksum" || return $?
+ [ -f "$albumlist" ] \
+ || errlog "file $albumlist does not exists" \
+ || return $?
+
+ [ -f "$libpath/$lib" ] \
+ || errlog "file $libpath/$lib does not exists" \
+ || return $?
+ # shellcheck disable=SC1090
+ source "$libpath/$lib" || return $?
+
+ mkdir -p "$workdir"
+ make_symlinks_to_work "$albumlist" "$workdir" || return $?
+ execute "$workdir" || return $?
+ cleanup_cover "$cover" "$workdir" || return $?
+ cleanup_flac "$lib" "$workdir" || return $?
+ calc_checksum "$checksum" "$workdir" || return $?
}
main "$@"