Last active
May 29, 2025 17:59
-
-
Save jmatthewturner/41c210d3ec3dedd70e4cc8efa00e95e7 to your computer and use it in GitHub Desktop.
BASH script to conform MP3 artwork to make the Kenwood Excelon series head units happy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will iterate through a folder and conform the artwork for any MP3s to a standard that is pleasing | |
# to the Kenwood Excelon series of car audio head units. It assumes all files in the folder are from the same album. | |
# (Note that this has been tested on a Kenwood Excelon DMX809S, but I assume this will work for all Excelon products.) | |
# | |
# This script will look for cover art contained in the folder first. If none is found, it will attempt to extract embedded | |
# artwork from the alphabetically first MP3. | |
# | |
# As far as I can tell, these are the criteria for the Kenwood Excelon to display album artwork: | |
# 1. Must be embedded in the MP3 -- images in folders are not read. | |
# 2. Must be perfectly square. | |
# 3. Must be less than 500KB. (This is the ONLY criterion mentioned in the manual, btw.) | |
# 4. I don't know what the upper size limit is, but 500x500px seems to be safe. | |
# 5. Color space must be sRGB. | |
# | |
# Note that there are additional criteria, but the above are the criteria that relate to the actual image. Additional criteria | |
# (and more BASH scripts) are outlined here: | |
# https://jmatthewturner.wordpress.com/2025/05/29/usb-mp3-functionality-on-kenwood-excelon-head-units/ | |
# | |
# This was written by Claude.ai, with prompts from jmatthewturner. I have refined it a bit, but it's 95% AI generated. | |
# | |
# https://gist.github.com/jmatthewturner/41c210d3ec3dedd70e4cc8efa00e95e7 | |
############# | |
# VARIABLES # | |
############# | |
first_mp3=0 # the first mp3 encountered by the for loop | |
cover_img=0 # the cover art, if available | |
################# | |
# MAIN FUNCTION # | |
################# | |
echo "Starting Kenwood.sh..." | |
# Look for cover art already saved in the folder under common file names | |
if [ -f "Cover.jpg" ]; then | |
echo "Found Cover.jpg." | |
cover_img="Cover.jpg" | |
elif [ -f "Cover.png" ]; then | |
echo "Found Cover.png." | |
cover_img="Cover.png" | |
elif [ -f "cover.jpg" ]; then | |
echo "Found cover.jpg." | |
cover_img="cover.jpg" | |
elif [ -f "cover.png" ]; then | |
echo "Found cover.png." | |
cover_img="cover.png" | |
elif [ -f "folder.jpg" ]; then | |
echo "Found folder.jpg." | |
cover_img="folder.jpg" | |
elif [ -f "folder.png" ]; then | |
echo "Found folder.png." | |
cover_img="folder.png" | |
elif [ -f "cover.webp" ]; then | |
echo "Found cover.webp." | |
cover_img="cover.webp" | |
else | |
# If no artwork is found in the folder, attempt to extract artwork embedded with the tag "FRONT_COVER Image" | |
# from the first MP3 file. If the cover art is embedded, this will create FRONT_COVER.jpg/png. | |
first_mp3=$(ls *.mp3 | head -n 1) | |
echo "No artwork found in folder. Attempting to extract from $first_mp3..." | |
echo | |
eyeD3 --write-images=. "$first_mp3" | |
# Check to see if cover art was extracted. If so, set cover_img to the extracted artwork. | |
if [ -f "FRONT_COVER.jpg" ]; then | |
echo "FRONT_COVER.jpg successfully extracted from $first_mp3." | |
cover_img="FRONT_COVER.jpg" | |
elif [ -f "FRONT_COVER.png" ]; then | |
echo "FRONT_COVER.png successfully extracted from $first_mp3." | |
cover_img="FRONT_COVER.png" | |
else | |
# At this point, all attempts to locate artwork have failed. | |
echo "No cover image found!" | |
exit 1 | |
fi | |
fi | |
# Conform the image with ImageMagick | |
convert "$cover_img" -strip -resize 500x500\! -colorspace sRGB cover_conformed.jpg | |
echo "Conformed $cover_img to cover_conformed.jpg." | |
# Embed the conformed image into all MP3s in the folder | |
echo "Embedding cover_conformed.jpg into all MP3s..." | |
echo | |
for f in *.mp3; do | |
eyeD3 -Q --remove-all-images "$f" | |
eyeD3 -Q --add-image "cover_conformed.jpg:FRONT_COVER" "$f" | |
done | |
# Clean up temporary images | |
#rm "$cover_img" cover_conformed.jpg | |
echo | |
echo "Skipping temp file removal." | |
# Report success | |
echo "Done processing album art for all MP3s in this folder." | |
if [ "$first_mp3" == "0" ]; then | |
echo "Found $cover_img in folder, successfully conformed to cover_conformed.jpg and embedded in all files." | |
else echo "Successfully extracted artwork from $first_mp3, conformed to cover_conformed and embedded in all files." | |
fi | |
echo | |
# Exit successfully | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment