Add script for attaching cover art to MP3 files using ffmpeg or lame. - Support batch processing of all MP3 files in a directory - Support updating individual MP3 files - Embed front-cover artwork from a supplied image - Preserve existing audio streams when using ffmpeg - Write ID3v2.3-compatible cover metadata - Replace original files with updated tagged versions - Add usage examples and script documentation - Simplify album artwork management for music collections ads
105 lines
2.5 KiB
Bash
Executable File
105 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
###############################################################################
|
|
# Script Name: add-mp3-cover.sh
|
|
#
|
|
# Description:
|
|
# Embeds album artwork into MP3 files using either ffmpeg or lame.
|
|
#
|
|
# By default, the script processes all MP3 files in the current directory.
|
|
# Alternatively, a single MP3 file can be specified.
|
|
#
|
|
# When using ffmpeg:
|
|
# - Preserves existing audio stream.
|
|
# - Embeds the supplied image as the front album cover.
|
|
# - Writes ID3v2.3-compatible metadata.
|
|
#
|
|
# When using lame:
|
|
# - Uses the --ti option to attach album artwork.
|
|
#
|
|
# Requirements:
|
|
# - ffmpeg (recommended)
|
|
# - or lame
|
|
# - Cover image located in:
|
|
# /home/lucas/Downloads/
|
|
#
|
|
# Usage:
|
|
# Process all MP3 files:
|
|
# ./add-mp3-cover.sh cover.jpg
|
|
#
|
|
# Process a specific MP3 file:
|
|
# ./add-mp3-cover.sh cover.jpg song.mp3
|
|
#
|
|
# Examples:
|
|
# Add cover.jpg to every MP3 in current directory:
|
|
# ./add-mp3-cover.sh cover.jpg
|
|
#
|
|
# Add cover.png to a specific track:
|
|
# ./add-mp3-cover.sh cover.png "My Song.mp3"
|
|
#
|
|
# Notes:
|
|
# - Original files are replaced with updated versions.
|
|
# - ffmpeg mode is enabled by default.
|
|
# - Cover image is read from /home/lucas/Downloads/.
|
|
#
|
|
###############################################################################
|
|
|
|
FFMPEG="true"
|
|
|
|
if [ "$2" == "" ]; then
|
|
|
|
# Process all MP3 files in current directory
|
|
for file in *.mp3; do
|
|
|
|
if [[ "${FFMPEG}" == "true" ]]; then
|
|
|
|
ffmpeg \
|
|
-i "$file" \
|
|
-i "/home/lucas/Downloads/$1" \
|
|
-map 0:0 \
|
|
-map 1:0 \
|
|
-c copy \
|
|
-id3v2_version 3 \
|
|
-metadata:s:v title="Album cover" \
|
|
-metadata:s:v comment="Cover (front)" \
|
|
"$file.mp3"
|
|
|
|
else
|
|
|
|
lame --ti "/home/lucas/Downloads/$1" "$file"
|
|
|
|
fi
|
|
|
|
mv "$file.mp3" "$file"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Process a specific MP3 file
|
|
for file in "$2"; do
|
|
|
|
if [[ "${FFMPEG}" == "true" ]]; then
|
|
|
|
ffmpeg \
|
|
-i "$file" \
|
|
-i "/home/lucas/Downloads/$1" \
|
|
-map 0:0 \
|
|
-map 1:0 \
|
|
-c copy \
|
|
-id3v2_version 3 \
|
|
-metadata:s:v title="Album cover" \
|
|
-metadata:s:v comment="Cover (front)" \
|
|
"$file.mp3"
|
|
|
|
else
|
|
|
|
lame --ti "/home/lucas/Downloads/$1" "$file"
|
|
|
|
fi
|
|
|
|
mv "$file.mp3" "$file"
|
|
|
|
done
|
|
|
|
fi |