#!/bin/bash # Recursively gets into each folder, checks if there is an audio file # and extracts the cover with ffmpeg ### Helpers # Check all extensions available # find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u export MUSIC_PATH="." extract_cover() { if [ ! -f "cover.jpg" ] then ffmpeg -hide_banner -i "$1" cover.jpg else echo "cover.jpg exists in " $(pwd) fi } export -f extract_cover if [ "$#" -eq 1 ]; then export MUSIC_PATH=$1 fi find $MUSIC_PATH \( -iname \*.MP3 -o -iname \*.Mp3 -o -iname \*.mp3 -o -iname \*.m4a \) -type f -execdir bash -c 'extract_cover "$0"' {} \;