tag (1394B)
1 #!/bin/sh 2 3 err() { echo "Usage: 4 tag [OPTIONS] file 5 Options: 6 -a: artist/author 7 -t: song/chapter title 8 -A: album/book title 9 -n: track/chapter number 10 -N: total number of tracks/chapters 11 -d: year of publication 12 -g: genre 13 -c: comment 14 You will be prompted for title, artist, album and track if not given." && exit 1 ;} 15 16 while getopts "a:t:A:n:N:d:g:c:" o; do case "${o}" in 17 a) artist="${OPTARG}" ;; 18 t) title="${OPTARG}" ;; 19 A) album="${OPTARG}" ;; 20 n) track="${OPTARG}" ;; 21 N) total="${OPTARG}" ;; 22 d) date="${OPTARG}" ;; 23 g) genre="${OPTARG}" ;; 24 c) comment="${OPTARG}" ;; 25 *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; 26 esac done 27 28 shift $((OPTIND - 1)) 29 30 file="$1" 31 32 temp="$(mktemp -p "$(dirname "$file")")" 33 trap 'rm -f $temp' HUP INT QUIT TERM PWR EXIT 34 35 [ ! -f "$file" ] && echo 'Provide file to tag.' && err 36 37 [ -z "$title" ] && echo 'Enter a title.' && read -r title 38 [ -z "$artist" ] && echo 'Enter an artist.' && read -r artist 39 [ -z "$album" ] && echo 'Enter an album.' && read -r album 40 [ -z "$track" ] && echo 'Enter a track number.' && read -r track 41 42 cp -f "$file" "$temp" && ffmpeg -i "$temp" -map 0 -y -codec 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"} "$file"