blob: 3885f88da54b0f01dacd8b8061e86428fd86acad (
plain)
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
|
#!/bin/sh
err() { echo "Usage:
rename [OPTIONS]
Options:
-d: delimiter
-a: artist/author
-A: album/book title
-y: year of publication
You will be prompted for these fields if not given." && exit 1 ;}
[ "$PWD" = "${HOME}/ik/tmp" ] || { echo "Unsafe directory!" && exit 1 ;}
while getopts "d:a:A:y:" o; do case "${o}" in
d) delimiter="${OPTARG}" ;;
a) artist="${OPTARG}" ;;
A) album="${OPTARG}" ;;
y) year="${OPTARG}" ;;
*) printf "Invalid option: -%s\\n" "$OPTARG" && err ;;
esac done
files=(*)
echo "Reference: ${files[0]}"
[ -z "$delimiter" ] && echo "What are the delimiters for these files?" && read -r delimiter
echo "Which index contains the track title? (Starting from 1)" && read -r index
[ -z "$artist" ] && echo 'Enter an artist.' && read -r artist
[ -z "$album" ] && echo 'Enter an album.' && read -r album
[ -z "$year" ] && echo 'Enter a year.' && read -r year
for file in *;
do
extension=$(echo $file | awk -F "." '{print $NF}')
title=$(echo $file | awk -F "${delimiter}" "{print \$${index}}" |
sed -re 's/^[[:blank:]]+|[[:blank:]]+$//g' -e 's/[[:blank:]]+/ /g')
new_file="${title}_${artist}_${album}_${year}.${extension}"
mv "./$file" "./$new_file"
tag-media -a "${artist}" -t "${title}" -A "${album}" -d "${year}" "${new_file}"
done
|