]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
refactor to create symlinks
authorBastian Dehn <hhaalo@arcor.de>
Sun, 13 Jul 2025 18:40:10 +0000 (20:40 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 13 Jul 2025 18:40:10 +0000 (20:40 +0200)
albentohandy

index 4f36ffb14ea953f7be7e99fe60fea1f9d882ae49..699eadce273070f0e807c352b497399c54096649 100755 (executable)
@@ -323,17 +323,30 @@ CleanupWorkDir()
        rm --recursive $WORKDIR
 }
 
-MakeSymlinksToWork()
+make_symlinks_to_work()
 {
-       local readonly WORKDIR="$1"
-       local readonly MUSIKDIR="$2"
-       local readonly ALBUMLIST="$3"
-
-       for i in $(cat "$ALBUMLIST"); do
-               cp --recursive --symbolic-link $MUSIKDIR/$i $WORKDIR/
-               rsync --recursive --perms --times --group --owner \
-                       --exclude="*.flac" --exclude="*.mp3" --exclude="*.ogg" \
-                       --include="cover.jpg" $MUSIKDIR/$i $WORKDIR/
+       local albumlist="$1"
+       local workdir="$2"
+       local musicpath="$3"
+
+       for album in $(cat $albumlist); do
+               cp --recursive \
+                       --symbolic-link \
+                       $musicpath/$album \
+                       $workdir \
+                       || errlog "could not copy symlinks from $musicpath/$album" \
+                       || return $?
+               rsync --recursive \
+                       --perms \
+                       --times \
+                       --group \
+                       --owner \
+                       --exclude="*.flac" \
+                       --include="cover.jpg" \
+                       $musicpath/$album \
+                       $workdir \
+                       || errlog "could not copy etc like cover" \
+                       || return $?
        done
 }
 
@@ -383,74 +396,36 @@ check_programms()
                || return $?
 }
 
-read_arguments()
+AdvancedFeatures()
 {
-       albumlist="albumlist"
-       curphase=1
-       phase=3
-       flac=false
-       mp3=false
-       opus=false
-       cover=false
-       removework=false
-       cptodest=false
+       # copy work directory to destination folder
+       if [ $cptodest == true ]; then
+               printf "Phase %02d of %02d:\n" $((curphase++)) $phase
+               printf "copy %s/ to destination %s\n\n" $WORK $dest
+               CopyWorkDirToDestDir "$WORK" "$dest"
+       fi
 
-       while getopts "3cfg:hi:m:orw:" optname; do
-               case "$optname" in
-               "3")
-                       mp3=true
-                       flac=false
-                       opus=false
-                       ;;
-               "c")
-                       cover=true
-                       ;;
-               "f")
-                       mp3=false
-                       flac=true
-                       opus=false
-                       ;;
-               "g")
-                       declare -xg replaygainapply="--apply-replaygain-which-is-not-lossless=$OPTARG"
-                       ;;
-               "h")
-                       Usage
-                       exit 0
-                       ;;
-               "i")
-                       albumlist="$OPTARG"
-                       ;;
-               "m")
-                       cptodest=true
-                       dest="$OPTARG"
-                       ((phase++))
-                       ;;
-               "o")
-                       opus=true
-                       mp3=false
-                       flac=false
-                       ;;
-               "r")
-                       removework=true
-                       ;;
-               "w")
-                       WORK="$OPTARG"
-                       ;;
-               esac
-       done
+       # delete the working directory
+       if [ $cptodest == true ] && [ $removework == true ]; then
+               CleanupWorkDir "$WORK"
+       fi
 }
 
-ConvertProcess()
+convert_process()
 {
-       if [ ! -f "$albumlist" ]; then
-               echo "ERROR: albumlist doas not exists"
-               exit 1
-       fi
+       local format="$1"
+       local workdir="work.$$"
+
+       [ -f "albumlist" ] \
+               || errlog "file albumlist does not exists" \
+               || return $?
 
-       mkdir -p $WORK
-       printf "\nPhase %02d of %02d:\n" $((curphase++)) $phase
-       printf "create symlinks of flac's in %s\n" "$WORK"
-       MakeSymlinksToWork "$WORK" "$MUSICPATH" "$albumlist"
+       mkdir -p $workdir
+       make_symlinks_to_work "albumlist" "$workdir" $MUSICPATH \
+               || return $?
+
+       # WIP
+       return
 
        if [ $mp3 == true ]; then
                printf "\nPhase %02d of %02d: flac -> mp3\n" \
@@ -479,32 +454,37 @@ ConvertProcess()
        CleanupCover "$WORK"
 }
 
-AdvancedFeatures()
-{
-       # copy work directory to destination folder
-       if [ $cptodest == true ]; then
-               printf "Phase %02d of %02d:\n" $((curphase++)) $phase
-               printf "copy %s/ to destination %s\n\n" $WORK $dest
-               CopyWorkDirToDestDir "$WORK" "$dest"
-       fi
-
-       # delete the working directory
-       if [ $cptodest == true ] && [ $removework == true ]; then
-               CleanupWorkDir "$WORK"
-       fi
-}
-
 main()
 {
-       WORK="$(pwd)/work.$$" # temporary working directory
-       MUSICPATH="/tmp/musikpath" # flac collection directory
+       local format=
 
        check_programms || return $?
        load_config || return $?
 
-       read_arguments $*
+       [ -n "$MUSICPATH" ] \
+               || errlog "missing MUSICPATH" \
+               || return $?
+
+       cover=false
+       removework=false
+       cptodest=false
+
+       while getopts "3cfg:hi:m:orw:" optname; do
+               case "$optname" in
+               "3") format="mp3" ;;
+               "c") cover=true ;;
+               "f") format="flac" ;;
+               "g") declare -xg replaygainapply="--apply-replaygain-which-is-not-lossless=$OPTARG" ;;
+               "h") Usage && return 0 ;;
+               "i") albumlist="$OPTARG" ;;
+               "m") cptodest=true && dest="$OPTARG" && ((phase++)) ;;
+               "o") format="opus" ;;
+               "r") removework=true ;;
+               "w") WORK="$OPTARG" ;;
+               esac
+       done
 
-       ConvertProcess
+       convert_process "$format" || return $$
        AdvancedFeatures
 }