-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag
More file actions
executable file
·51 lines (46 loc) · 1.31 KB
/
Copy pathtag
File metadata and controls
executable file
·51 lines (46 loc) · 1.31 KB
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
#!/bin/sh
usage()
{
echo "usage: ${0##*/} [-a artist] [-A album_title] [-c comment]" 1>&2
echo " [-d year] [-g genre] [-n trackno] [-N totalno]" 1>&2
echo " [-t song_title] file" 1>&2
exit 1
}
while getopts "a:t:A:n:N:d:g:c:" arg; do
case "${arg}" in
a) artist="${OPTARG}" ;;
t) title="${OPTARG}" ;;
A) album="${OPTARG}" ;;
n) track="${OPTARG}" ;;
N) total="${OPTARG}" ;;
d) date="${OPTARG}" ;;
g) genre="${OPTARG}" ;;
c) comment="${OPTARG}" ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
file="${1}"
test ! -f "${file}" && echo "${0##*/}: file not found: ${file}" && usage
test -z "${title}" && read -erp "Title: " title
test -z "${artist}" && read -erp "Artist: " artist
test -z "${album}" && read -erp "Album: " album
test -z "${track}" && read -erp "Track number: " track
test -z "${total}" && read -erp "Total tracks in album: " total
test -z "${date}" && read -erp "Date: " date
test -z "${genre}" && read -erp "Genre: " genre
temp="$(mktemp)"
cp -f "${file}" "${temp}"
ffmpeg \
-i "${temp}" \
-nostdin \
-map 0 -y -c copy \
-metadata title="${title}" \
-metadata album="${album}" \
-metadata artist="${artist}" \
-metadata track="${track}${total:+/"${total}"}" \
${date:+-metadata date="${date}"} \
${genre:+-metadata genre="${genre}"} \
${comment:+-metadata comment="${comment}"} \
"${file}"
rm -f ${temp}