Skip to content

Instantly share code, notes, and snippets.

@andreicek
Created February 23, 2018 22:12
Show Gist options
  • Save andreicek/b84272e0b56117955029f8887e9bac89 to your computer and use it in GitHub Desktop.
Save andreicek/b84272e0b56117955029f8887e9bac89 to your computer and use it in GitHub Desktop.
Finds all mp3 and sorts them in a flat strucutre
#!/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