Skip to content

Instantly share code, notes, and snippets.

@adventureloop
Created January 30, 2020 20:31
Show Gist options
  • Save adventureloop/1f17d4014759bf8d6647ee0bb4c6b117 to your computer and use it in GitHub Desktop.
Save adventureloop/1f17d4014759bf8d6647ee0bb4c6b117 to your computer and use it in GitHub Desktop.
#!/bin/zsh
basedir=$1
outdir=music
for track in $basedir/*m4a
do
#echo $track
info=`mp4info $track`
# drop the first entry on each line, trim white space
artist=`echo $info | grep -e '^ Artist:' | awk '{$1=""; print $0}' | awk '{$1=$1};1'`
album=`echo $info | grep -e '^ Album:' | awk '{$1=""; print $0}' | awk '{$1=$1};1'`
title=`echo $info | grep -e '^ Name:' | awk '{$1=""; print $0}' | awk '{$1=$1};1'`
echo $artist - $album - $title
mkdir -p $artist/$album/
cp $track $artist/$album/${title}.m4a
#exit
done
for track in $basedir/*mp3
do
#echo $track
# get the Title and Album lines from the info preamble.
# split these at Artist and Year to get each entry on its own line
info=`id3v2 -l $track | grep -e "^Title\|^Album" | sed 's/Artist:/\'$'\nArtist :/g' | sed 's/Year:/\'$'\nYear :/g'`
# drop the first two entries on each line, trim white space
artist=`echo $info | grep -e 'Artist' | awk '{$1=$2=""; print $0}' | awk '{$1=$1};1'`
album=`echo $info | grep -e 'Album' | awk '{$1=$2=""; print $0}' | awk '{$1=$1};1'`
title=`echo $info | grep -e 'Title' | awk '{$1=$2=""; print $0}' | awk '{$1=$1};1'`
echo $artist - $album - $title
mkdir -p $artist/$album/
cp $track $artist/$album/${title}.mp3
#exit
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment