dotfiles

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

flac-to-mp3.sh (679B)


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