From: Bastian Dehn Date: Sun, 13 Jul 2025 18:40:10 +0000 (+0200) Subject: refactor to create symlinks X-Git-Tag: v1.0.0^2~53^2~11 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=3549775e14ce0d031208e5389a840137f6340c57;p=albentohandy.git refactor to create symlinks --- diff --git a/albentohandy b/albentohandy index 4f36ffb..699eadc 100755 --- a/albentohandy +++ b/albentohandy @@ -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 }