Created
July 26, 2025 22:28
-
-
Save jmarhee/a315113e141fdb3e3bf6ca7b29ed507d to your computer and use it in GitHub Desktop.
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 | |
# Check if the directory is provided as an argument | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 <directory>" | |
exit 1 | |
fi | |
# Directory containing the audio files | |
DIRECTORY=$1 | |
# Check if the directory exists | |
if [ ! -d "$DIRECTORY" ]; then | |
echo "Error: Directory '$DIRECTORY' does not exist." | |
exit 1 | |
fi | |
# Prompt for artist name and album title | |
read -p "Enter the artist name: " ARTIST | |
read -p "Enter the album title: " ALBUM | |
read -p "Enter the path to album art (leave blank if none): " ALBUM_ART | |
# Iterate over M4A files in the directory | |
for FILE in "$DIRECTORY"/*.m4a; do | |
# Skip if no M4A files are found | |
if [ ! -e "$FILE" ]; then | |
echo "No M4A files found in the directory." | |
exit 0 | |
fi | |
# Extract the base filename (without the directory path) | |
BASENAME=$(basename "$FILE" .m4a) | |
# Extract the track number (before the "-") | |
TRACK_NUMBER=$(echo "$BASENAME" | cut -d'-' -f1 | tr -d '[:space:]') | |
# Extract the title (after the "-") | |
TITLE=$(echo "$BASENAME" | cut -d'-' -f2- | tr -d '[:space:]') | |
# Convert M4A to MP3 using ffmpeg | |
MP3_FILE="$DIRECTORY/$BASENAME.mp3" | |
echo "Converting '$FILE' to MP3..." | |
ffmpeg -i "$FILE" -q:a 0 "$MP3_FILE" -y | |
# Apply metadata using eyeD3 | |
echo "Updating metadata for '$MP3_FILE': Track $TRACK_NUMBER, Title '$TITLE', Artist '$ARTIST', Album '$ALBUM'" | |
eyeD3 --track="$TRACK_NUMBER" --title="$TITLE" --artist="$ARTIST" --album="$ALBUM" "$MP3_FILE" | |
# Add album art if provided | |
if [ -n "$ALBUM_ART" ]; then | |
echo "Adding album art from '$ALBUM_ART' to '$MP3_FILE'" | |
eyeD3 --add-image="$ALBUM_ART:FRONT_COVER" "$MP3_FILE" | |
fi | |
done | |
echo "Conversion and metadata update complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment