Created
February 23, 2018 22:12
-
-
Save andreicek/b84272e0b56117955029f8887e9bac89 to your computer and use it in GitHub Desktop.
Finds all mp3 and sorts them in a flat strucutre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
musicFolder=$1 | |
dist=$2 | |
function usage() { | |
echo $1 | |
exit 1 | |
} | |
[ "$musicFolder" ] || usage "missing music folder" | |
[ "$dist" ] || usage "missing dist folder" | |
[ $(which id3info) ] || usage "install id3info" | |
[ $(which rmtrash) ] || usage "install rmtrash" | |
files=$(find "$musicFolder" -iname "*.mp3") | |
while read -r file; do | |
info=$(id3info "$file") | |
title=$(echo "$info" | grep "Title" | awk -F ": " '{print $2}' | tr ' ' '_') | |
author=$(echo "$info" | grep "Lead" | awk -F ": " '{print $2}' | tr ' ' '_') | |
newFileName="${title}-${author}.mp3" | |
echo -n "new file name: [${newFileName}] " | |
read -e user </dev/tty | |
if [ "$user" ]; then | |
newFileName="$user" | |
fi | |
cp "$file" "${dist}${newFileName}" | |
rmtrash "$file" | |
done <<< "$files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment