-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassivetag
executable file
·46 lines (36 loc) · 1.61 KB
/
massivetag
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
#!/bin/sh
# Give a directory as an argument and tag all your music files inside that
# directory. It will only prompt you once for the album, author and year.
dir="$1"
[ ! -d "$dir" ] && { echo "Please add a directory to tag." && exit 1 ;}
cd "$dir" || { echo "Error: $dir Not found" && exit 2 ;}
echo "Enter the album title:"; read -r album
echo "Enter the artist:"; read -r author
echo "Enter the publication year:"; read -r year
# datag 1file 2album 3title 4author 5year 6totaltracks
datag() {
tags="ALBUM=$2\nTITLE=$3\nARTIST=$4\nDATE=$5\nTOTALTRACKS=$6"
case "$1" in
*.ogg) echo "$tags" | vorbiscomment -w "$1" ;;
*.opus) echo "$tags" | opustags -i --set-all "$1" ;;
*.mp3) eyeD3 -Q --remove-all -a "$4" -A "$2" -t "$3" -N "$6" -Y "$5" "$1" ;;
*.flac) metaflac --remove-all-tags --set-tag="$tags" "$1" ;;
*) echo "\n\tFile type '${1%.*}' not implemented yet on '$1', skipping..." ;;
esac
}
# When downloading, the name gets mess up
sanename() { iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr ' ' '_' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g" ;}
# Make a list of the songs to read to
all="$(find . -maxdepth 1 -type f -printf "%f\n")"
totaltracks="$(echo "$all" | wc -l)"
printf "\nTagging ...\n"
echo "$all" | while IFS= read -r song
do
printf " %s" "$song"
title="${song%.*}" # no ext name
datag "$song" "$album" "$title" "$author" "$year" "$totaltracks" || echo "failed tagging $song"
printf "\tdone...\n"
done
# Make the album name the directory name (if it isn't the same already)
titldir="$(echo "$album" | sanename)"
[ ! "$dir" = "$titldir" ] && { cd .. && mv --interactive --verbose "$1" "$titldir" ;}