tag (1343B)
1 #!/bin/sh 2 3 usage() 4 { 5 echo "usage: ${0##*/} [-a artist] [-A album_title] [-c comment]" 1>&2 6 echo " [-d year] [-g genre] [-n trackno] [-N totalno]" 1>&2 7 echo " [-t song_title] file" 1>&2 8 exit 1 9 } 10 11 while getopts "a:t:A:n:N:d:g:c:" arg; do 12 case "${arg}" in 13 a) artist="${OPTARG}" ;; 14 t) title="${OPTARG}" ;; 15 A) album="${OPTARG}" ;; 16 n) track="${OPTARG}" ;; 17 N) total="${OPTARG}" ;; 18 d) date="${OPTARG}" ;; 19 g) genre="${OPTARG}" ;; 20 c) comment="${OPTARG}" ;; 21 *) usage ;; 22 esac 23 done 24 shift $((OPTIND - 1)) 25 26 file="${1}" 27 test ! -f "${file}" && echo "${0##*/}: file not found: ${file}" && usage 28 29 test -z "${title}" && read -erp "Title: " title 30 test -z "${artist}" && read -erp "Artist: " artist 31 test -z "${album}" && read -erp "Album: " album 32 test -z "${track}" && read -erp "Track number: " track 33 test -z "${total}" && read -erp "Total tracks in album: " total 34 test -z "${date}" && read -erp "Date: " date 35 test -z "${genre}" && read -erp "Genre: " genre 36 37 temp="$(mktemp)" 38 cp -f "${file}" "${temp}" 39 ffmpeg \ 40 -i "${temp}" \ 41 -nostdin \ 42 -map 0 -y -c copy \ 43 -metadata title="${title}" \ 44 -metadata album="${album}" \ 45 -metadata artist="${artist}" \ 46 -metadata track="${track}${total:+/"${total}"}" \ 47 ${date:+-metadata date="${date}"} \ 48 ${genre:+-metadata genre="${genre}"} \ 49 ${comment:+-metadata comment="${comment}"} \ 50 "${file}" 51 rm -f ${temp}