Friday 19 September 2014

HOWTO: Tag music files automatically, based on folder and file name

Pasted at the bottom of this article is a Bash script I ran last night to tag my audio collection.  I was hoping this would enable Google Play Music to recognize the metadata in the tags, so that I could browse and stream music by genre, album, artist, etc. But as noted below, the tagging process worked, but Google Play Music ignored it :-(

UPDATE: the tagging process seems to have worked, but I have concluded that Google Play Music is too dumbed down to be useful for any serious music library.  I have 5,500 tracks of various genres including Jazz and Classical.  The problems with Google Play Music are:
  • Uploads are matched against their library for speed (i.e. uploads are aborted if they think they have a match already).  Sometimes this will give you the wrong track.
  • Your tags are largely ignored and replaced with often inaccurate tags. A couple of albums ended up with tags in Russian when I'd uploaded valid tags in English.
  • Your genre tags are totally ignored - meaning that you can't browse by genre, then artist, then album - so it's hard to navigate round a music library of any size.
My next step will be to use minidlna on FreeBSD or Linux, to serve the music whilst preserving the folder hierarchy to aid navigation.  It seems that minidlna should be able to stream to Google Chromecast devices as far cheaper alternatives to Sonos units.  I've got an adapter plug to get the sound from the Chromecast HDMI  so that I don't need to use a TV or a multimedia amp. So, it should be possible to use an Android application like LocalCast to command the Chromecast to play streams directly from the MiniDLNA server.  That is, the Android device is just a controller, not a music source.

The Chromecast can't play FLAC files natively by the way.  So I'm just in the process of copying my FLAC audio tree to MP3 using a bash script with FLAC and LAME.

#!/bin/bash
#
# Auto-tag music files stored in folders named as:
#      genre/artist/album/nn track name.flac
# Allows for special characters in folder and file names...
# Allows for arbitrary folder depths...
#
# Key tool is mid3v2 from mutagen: install on Ubuntu 14.04 by:
#      sudo apt-get install python-pip;sudo pip install mutagen

cd Music
for GENRE in *
do   
  find "./${GENRE}" -name *.flac | while read FLACNAME
  do
    DIRNAME=`dirname "${FLACNAME}"`

    BASENAME=`basename -s .flac "${FLACNAME}"`
    TRACK_NUM=`echo $BASENAME | cut -f1 -d\ `
    TRACK_NAME=`echo $BASENAME | cut -f2-99 -d\  `
    TRACK_COUNT=`ls -l "${DIRNAME}"/*.flac | wc -l`
    ALBUM_NAME=`basename "${DIRNAME}"`
    PARENT_FOLDER=`dirname "${DIRNAME}"`
    ARTIST_NAME=`basename "${PARENT_FOLDER}"`

    printf "%q %q %q %q %q %q %q\n" "mid3v2" "-g${GENRE}" "-a${ARTIST_NAME}" "-A${ALBUM_NAME}" "-T${TRACK_NUM}/${TRACK_COUNT}" "-t${TRACK_NAME}" "${FLACNAME}"

    done
done

No comments:

Post a Comment

Spammers: please stop wasting my time. All comments are moderated before publication.