summaryrefslogtreecommitdiff
path: root/kolwynia/home/bdunahu/files/.local/bin/fetch-album
diff options
context:
space:
mode:
Diffstat (limited to 'kolwynia/home/bdunahu/files/.local/bin/fetch-album')
-rwxr-xr-xkolwynia/home/bdunahu/files/.local/bin/fetch-album38
1 files changed, 38 insertions, 0 deletions
diff --git a/kolwynia/home/bdunahu/files/.local/bin/fetch-album b/kolwynia/home/bdunahu/files/.local/bin/fetch-album
new file mode 100755
index 0000000..3885f88
--- /dev/null
+++ b/kolwynia/home/bdunahu/files/.local/bin/fetch-album
@@ -0,0 +1,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