-
Notifications
You must be signed in to change notification settings - Fork 10
/
embed_picture_into_mp3.sh
executable file
·79 lines (72 loc) · 1.97 KB
/
embed_picture_into_mp3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
BASENAME="$(basename "$0")"
# Help.
if [ "$1" = '--help' -o "$1" = '-help' -o "$1" = '-h' ]; then
echo "Usage: ${BASENAME} [-t FRONT_COVER] front.jpg file1.mp3 file2.mp3 ..."
echo ""
echo "It will remove any embedded pictures from the MP3 files and add the specified picture to the MP3 files."
echo "The picture type will be auto-detected from the filename (ignoring case):"
echo " AlbumArt* -> 03 FONT_COVER"
echo " cover* -> 03 FONT_COVER"
echo " front* -> 03 FONT_COVER"
echo " back* -> 04 BACK_COVER"
echo " booklet* -> 05 LEAFLET"
echo " leaflet* -> 05 LEAFLET"
echo " media* -> 06 MEDIA"
echo " medium* -> 06 MEDIA"
echo " * -> 00 OTHER"
exit
fi
# Picture type, and -t/--type command-line flag.
TYPE=""
if [ "$1" = '-t' -o "$1" = '--type' ]; then
shift
TYPE="$1"
if [ -z "${TYPE}" ]; then
echo "The '-t' option requires a parameter. Aborting."
exit 2
fi
shift
fi
# The path to the embedded picture.
PICTURE="$1"
shift
if [ ! -r "${PICTURE}" ]; then
echo "Picture '${PICTURE}' was not found or is not readable. Aborting."
exit 1
fi
# Auto-detect type.
# http://stackoverflow.com/questions/2264428/converting-string-to-lower-case-in-bash-shell-scripting
AUTO_TYPE="OTHER"
PICTURE_NAME="$( basename "${PICTURE}" )"
case "${PICTURE_NAME,,}" in
albumart* | cover* | front* )
AUTO_TYPE="FRONT_COVER"
;;
back* )
AUTO_TYPE="BACK_COVER"
;;
booklet* | leaflet* )
AUTO_TYPE="LEAFLET"
;;
media* | medium* )
AUTO_TYPE="MEDIA"
;;
esac
if [ -z "${TYPE}" ]; then
TYPE="${AUTO_TYPE}"
fi
# The MP3 files.
if [ -z "$1" ]; then
echo "Missing parameters: MP3 files to be modified. Aborting."
exit 1
fi
# I can use a single command because eyeD3 first removes tags, and then
# edits/adds tags.
# Optional flags: --to-v2.4
# TSO2 frame is not supported by eyeD3, and it is not essential anyway.
# It will also change TSOP to XSOP.
set -x
eyeD3 --remove-frame TSO2 \
--remove-all-images --add-image "${PICTURE}:${TYPE}" \
"$@"