#!/usr/bin/env fish function manage_music set root_directory ~/Music/ # set i 1 # find $root_directory -type f -name "cover.jpg" -delete # for file in (find $root_directory -type f) # mkdir $root_directory/$i # mv $file $root_directory$i/ # set i (math $i + 1) # end # beet import -A $root_directory # find $root_directory -type d -empty -delete # for directory in (find $root_directory -type d -not \( -path /home/jawz/Music/.debris -prune \)) # set file_count (count (find $directory -maxdepth 1 -type f)) # if test $file_count -gt 0 # set file_head (find $directory -maxdepth 1 -type f | head -n 1) # ffmpeg -i $file_head -y -loglevel 0 $directory/cover.jpg # if test ! -e $directory/cover.jpg # echo $directory "doesn't have a cover" # end # end # end # Fix covers # for file in (find $root_directory -type f -name cover.jpg) # set resolution (string match -r "\d+x\d+" (identify $file)) # set width (string split x $resolution)[1] # set height (string split x $resolution)[2] # set div (math $width / $height) # # Scale up to square # if test \( $width -ne $height \) \ # -a \( $div -ge 0.98 \) \ # -a \( $div -le 1.2 \) # if test $width -gt $height # set size "$width"x"$width"! # else # set size "$height"!x"$height" # end # echo "Will scale up" $file $resolution # mogrify -resize $size $file # end # # Crop # if test $width -ne $height # if test $width -gt $height # set size "$height"x"$height"+0+0 # else # set size "$width"x"$width"+0+0 # end # echo "Will crop " $file $resolution $size # mogrify -gravity Center -crop $size $file # end # # Check if image is a square and bigger than 500x500 # if test \( $width -eq $height \) -a \( $width -gt 1000 \) # echo "Will resize " $file $resolution # mogrify -resize 1000 $file # end # end end