aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2018-12-24 03:13:47 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2018-12-24 03:13:47 +0100
commitcfc60e0ddda720e9eb28513dbd07054bedca4e37 (patch)
treeeee747c30966c3b44320b309e53060a1c63a61d5
parent9735824c1bfa5e884ec4862d620a6298e9e240c7 (diff)
downloadscripts-cfc60e0ddda720e9eb28513dbd07054bedca4e37.tar.gz
scripts-cfc60e0ddda720e9eb28513dbd07054bedca4e37.zip
musicSorter.sh finished.
-rwxr-xr-xmusicSorter.sh29
1 files changed, 26 insertions, 3 deletions
diff --git a/musicSorter.sh b/musicSorter.sh
index cf65400..e16e9c0 100755
--- a/musicSorter.sh
+++ b/musicSorter.sh
@@ -1,16 +1,39 @@
#!/bin/sh
+# __ __ _ ____ _
+# | \/ |_ _ ___(_) ___ / ___| ___ _ __| |_ ___ _ __
+# | |\/| | | | / __| |/ __| \___ \ / _ \| '__| __/ _ \ '__|
+# | | | | |_| \__ \ | (__ ___) | (_) | | | || __/ |
+# |_| |_|\__,_|___/_|\___| |____/ \___/|_| \__\___|_|
+#
+
+# Moves the mp3s in a given folder, creating a
+# structure such as artist/album/file.
+# Note: Some generated folder names might be wrong
+# because of "tagmp3 show" not handling non-english
+# characters correctly. Folder structure should be
+# right nonetheless.
count=0
files="${1}/*.mp3"
for file in $files; do
count=$(($count+1))
echo "File $count: $file" >> "$1/filelist.txt"
- artist=$(tagmp3 show "$file" | grep "Artist" | cut -d' ' -f7- | xargs)
+ artist=$(tagmp3 show "$file" | grep --text "Artist" | cut -d' ' -f7- | sed 's/[[:space:]]*$//')
+ echo "Artist: $artist" >> "$1/filelist.txt"
if [ -n "$artist" ]; then
- if [ -z "$(ls $1 | grep "$artist")" ]; then
+ if [ -z "$(ls "$1" | grep -w "$artist")" ]; then
mkdir -p "$1/$artist"
fi
- target="$1/$artist/$(basename "$file")"
+ album=$(tagmp3 show "$file" | grep --text "Album" | cut -d' ' -f8- | sed 's/[[:space:]]*$//')
+ echo "Album: $album" >> "$1/filelist.txt"
+ if [ -n "$album" ]; then
+ if [ -z "$(ls "$1/$artist" | grep -w "$album")" ]; then
+ mkdir -p "$1/$artist/$album"
+ fi
+ target="$1/$artist/$album/$(basename "$file")"
+ else
+ target="$1/$artist/$(basename "$file")"
+ fi
mv -f "$file" "$target"
fi
done