#!/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 ### Configuration export MUSIC_PATH="." ### Functions file_exists() { files=( ./*$1 ) if [ ${#files[@]} -gt 0 ]; then echo ${files[0]} fi } check_extensions() { EXTENSIONS_SUPPORTED=("MP3" "Mp3" "mp3" "m4a") for i in "${EXTENSIONS_SUPPORTED[@]}" do file_exists "$i" done } extract_cover() { if [ ! -f "cover.jpg" ] then shopt -s nullglob # erase not matching result val=$(check_extensions) #echo "file found" $val "in" $(pwd) ffmpeg -i "$val" cover.jpg else echo "cover.jpg exists in " $(pwd) fi } ### Program find $MUSIC_PATH -type f -name ".*" -delete # remove hidden files export -f extract_cover check_extensions file_exists find $MUSIC_PATH \( -iname \*.MP3 -o -iname \*.Mp3 -o -iname \*.mp3 -o -iname \*.m4a \) -type f -execdir bash -c 'extract_cover "$0"' {} \;