dotfiles

Configuration for the software I use.
git clone https://git.sr.ht/~jbauer/dotfiles
Log | Files | Refs | README | LICENSE

flac-to-mp3 (838B)


      1 #!/bin/bash
      2 
      3 MUSICDIR="$HOME/Downloads"
      4 # MAXJOBS=$(nproc)
      5 MAXJOBS=10
      6 
      7 convert()
      8 {
      9     for thing in "$@"; do
     10         if [ -d "$thing" ]; then
     11             convert "$thing"/*
     12         else
     13             if [ "$numJobs" -gt "$MAXJOBS" ] || [ "$numJobs" -eq "$MAXJOBS" ]; then
     14                 wait -n;
     15                 numJobs=$((numJobs-1))
     16             fi
     17             fileName=$(basename -s .flac -s .wav -s .mp3 "$thing")
     18             dirName=$(dirname "$thing")
     19             mkdir -vp "$MUSICDIR/$dirName"
     20 	    if [ -f "$MUSICDIR/$dirName/$fileName.mp3" ]; then
     21 		    echo "$thing" already converted.
     22 	    fi
     23 	    echo "Converting $thing"
     24             ffmpeg -y -hide_banner -loglevel error -i "$thing" -q:a 1 \
     25                 "$MUSICDIR/$dirName/$fileName".mp3 &
     26             numJobs=$((numJobs+1))
     27         fi
     28     done
     29 }
     30 
     31 numJobs=0
     32 convert "$@"