lowmanio.co.uk title image

Script to put your music in a database

Fri, 28 Aug 2009 12:24PM

Category: Programming

Written by Sarah | No comments

I made this script a while back now to populate a database with all the music on my computer (so excuse any poor Python!). It assumes you are on Windows and have all your music in one folder, arranged by artist with sub folder albums with songs in them. It also assumes you'll use PostgreSQL, but it's trivial to change this to mySQL or even SQLite which comes with Python2.5 or higher. You can tell it to ignore certain folders by adding to the ignorables set. It will automatically grab any album art it finds and try and get the genre, track number and composer etc from MP3 meta data (I couldn't find a way of doing any other kind of music type).

The script recursively goes through your music folders adding artists, albums and songs to the database. It then generates an HTML file listing all the songs you have. I've tried to make it normalize the track names by removing the artist and the track number (if it appears at the start) and formatting the text to have capitalized first letters of words. This is because I had many songs in the form of backstreet_boys_03_EvErYbOdY.mp3 which the script turns into Everybody.mp3. You may argue that the script should purge all songs by The Backstreet Boys, but I have a weakness for cheese. This may cause problems with titles that start with a number or actually do have the artists name as part of the song, but I didn't find any in my collection.

You will need to install SQLAlchemy and Mutagen and place the script in your 'My Music' folder.

Download: music.py

Copyright Microsoft Clipart
Tagged with: Python, SQLAlchemy, music

Comments

No comments.

Add a comment

captcha