Hi, and let me just note that you are seeing IPython Notebook file ;)

Coincidentally not, notebook file format is stored in JSON format, too!
Let's go

Import some needed modules:

In [1]:
import os, json

Point to location where m-tags are stored:

In [2]:
mtags_dir = os.path.join(os.path.expanduser('~'), "My Documents\My Music\m-tags")

Crawl folders and read json in 'data' object, which for convenience we set as list:
Note: I stored each m-tags for each file, while storing each m-tags per folder needs obviously different approach

In [3]:
data = []
for p, d, f in os.walk(mtags_dir):
    for mfile in f:
        data.append(json.load(open(os.path.join(p, mfile)))[0])

Now we have data list with dictionary like objects full with out library tags!
For this example I created m-tags to one of my library folders. Let's see how they look like:

In [5]:
print "%d items stored!" % len(data)
data[0]
1155 items stored!

Out[5]:
{u'@': u'../../Library/Various Artists/A Brief History of Ambient, Vol. 4- Isolationism/1.01 - James Plotkin - Lost (Held Under).mp3',
 u'ALBUM': u'A Brief History of Ambient, Vol. 4: Isolationism',
 u'ALBUM ARTIST': u'Various Artists',
 u'ARTIST': u'James Plotkin',
 u'DATE': u'1994',
 u'DISCOGS_RELEASE_ID': u'72804',
 u'GENRE': [u'Noise', u'Experimental', u'Minimal', u'Ambient'],
 u'INVOLVEDPEOPLE': [u'K.K. Null', u'James Plotkin'],
 u'PUBLISHER': u'Virgin',
 u'REPLAYGAIN_ALBUM_GAIN': u'-4.43 dB',
 u'REPLAYGAIN_ALBUM_PEAK': u'1.069314',
 u'REPLAYGAIN_TRACK_GAIN': u'-3.99 dB',
 u'REPLAYGAIN_TRACK_PEAK': u'0.954819',
 u'TITLE': u'Lost (Held Under)',
 u'TOTALTRACKS': u'23',
 u'TRACKNUMBER': u'1'}

OK, what's next? foobar has great search function, we probably don't need more, but in rare cases we can import re module, then dump some regex result in playlist and load it. Or we can search for some crazy ideas, like show me the path to files that have same title as album name?

In [6]:
for d in data:
    if d['TITLE'] in d['ALBUM']: print d['@']
../../Library/Various Artists/Brain Bucket - Falling Through/01-noisia_ed_rush_and_optical-brain_bucket-def.mp3
../../Library/Various Artists/Brain Bucket - Falling Through/02-noisia_and_spor-falling_through-def.mp3
../../Library/Various Artists/Che/01 - Sunn O))) & Pan Sonic - Che.mp3
../../Library/Various Artists/Cloudshine - Drytears/a-noisia-cloud_shine-sour.mp3
../../Library/Various Artists/Cloudshine - Drytears/b-predator_and_adj-dry_tears-sour.mp3
../../Library/Various Artists/Desert Solitaire/11 - Steve Roach & Michael Stearns - Desert Solitaire.mp3
../../Library/Various Artists/Light Sleeper - Relentless (Stakka & Skynet remix)/01 - Matrix & Fierce - Light Sleeper.mp3
../../Library/Various Artists/Light Sleeper - Relentless (Stakka & Skynet remix)/02 - Cause 4 Concern - Relentless (Stakka & Skynet remix).mp3
../../Library/Various Artists/Mammoth - Sore Point/01 - Phace & Misanthrop - Mammoth.mp3
../../Library/Various Artists/Mammoth - Sore Point/02 - Phace & Noisia - Sore Point.mp3
../../Library/Various Artists/Masada - Lifeless/a-noisia-massada-sour.mp3
../../Library/Various Artists/Masada - Lifeless/b-spinor-lifeless-sour.mp3
../../Library/Various Artists/Pacman (Ram Trilogy remix) - Vessel/01 - Ed Rush & Optical - Pacman (Ram Trilogy remix).mp3
../../Library/Various Artists/Pacman (Ram Trilogy remix) - Vessel/02 - Universal Project - Vessel.mp3
../../Library/Various Artists/Scatter The Ashes - Vulcanic/02 - Cern, Misanthrop, Phace & Bulle - Vulcanic.mp3
../../Library/Various Artists/Songs Without Words- A Windham Hill Collection/04 - Songs Without Words.lossy.flac
../../Library/Various Artists/The Final Solstice II/02 - Sorrow - The Final Solstice.mp3
../../Library/Various Artists/Torque/1_07 - Ed Rush & Nico - Torque.mp3
../../Library/Various Artists/Torque/2_10 - Ed Rush & Nico - Torque.mp3
../../Library/Various Artists/Western Spaces/07 - Western Spaces.mp3

Or use anything that Python can provide!
Let's then switch in pylab and do some plots:

In [7]:
%pylab inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [8]:
genres = {}
for d in data:
    try:
        if type(d[u'GENRE']) == list:
            for g in d[u'GENRE']:
                genres[g] = genres.get(g, 0) + 1
        else:
            genres[d[u'GENRE']] = genres.get(d[u'GENRE'], 0) + 1
    except: pass

Now, we just created genres object with enumerated genres which we can easily visualize:

In [9]:
for i, k in enumerate(genres):
    barh(i, genres[k], color='m')
y = yticks(arange(len(genres))+.4, genres.keys())

Or with some dandy colormaps:

In [10]:
from __future__ import division
for i, k in enumerate(genres):
    barh(i, genres[k], color=cm.hsv(genres[k]/max(genres.values()), 1))
y = yticks(arange(len(genres))+.4, genres.keys())

Well, my limited fantasy shows itself, but just consider easily accessible data if user for examples stores playback statistics in files (in m-tags files right?)
Cheers :)

Back to top