views:

370

answers:

3

This is specifically geared towards managing mp3s but should easily work for any directory structure with a lot of files.

I want to find or write a daemon (preferably in Python) that will watch a folder with many subfolders that should all contain X number of mp3s. Any time a file is added, updated or delete it should reflect that in a database (preferably PostgreSQL). I am willing to accept if a file is simply moved that the respective rows are deleted and recreated anew but updating existing rows would make me the happiest.

This question has a little of what I want:

http://stackoverflow.com/questions/1615565/managing-a-large-collection-of-music

I basically just want a database that I can then do whatever I want to with. My most up-to-date database as of now is my iTunes.xml file but I don't want to rely on that too much as I don't always want to rely on iTunes for my music management. I see plenty of projects out there that do a little of what I want but in a format that either I can't access or is just more complex than I want. If there is some media player out there that can watch a folder and update a database that is easily accessible then I am all for it.

The reason I'm leaning towards writing my own is because It would be nice to choose my database and schema myself.

+2  A: 

If you use Linux, you can use PyInotify.

inotify can notify you about filesystem events when your program is running.

Johannes Weiß
+1 This sort of thing is exactly what inotify is for
prestomation
A: 

IMO the best media player that has these features is Winamp. It rescans the music folders every X minutes, which is enough for music (but of course a little less efficient than letting the operating system watch for changes).

But as you were asking for suggestions on writing your own, you could make use of pyinotify (Linux only). If you're running Windows, you can use the ReadDirectoryChangesW API call

AndiDog
Can it connect to a database? How can I access it's data?
TheLizardKing
Guess you mean the Winamp database?! It's stored in `~\Application Data\Winamp\Plugins\ml\main.*` (on Windows of course) and has a special file format described at http://gutenberg.free.fr/fichiers/SDK%20Winamp/nde_specs_v1.txt if you want to manipulate it - which you don't really have to, why would you want to edit the database if Winamp offers everything necessary?
AndiDog
I don't necessarily want a music player. I am looking for a way to store all of my collection's metadata in a database.
TheLizardKing
Which doesn't really make sense if it isn't fully integrated with a media player.
AndiDog
What I do with the data is up to me. Thanks for your help.
TheLizardKing
+4  A: 

Another answer already suggested pyinotify for Linux, let me add watch_directory for Windows (a good discussion of the possibilities in Windows is here, the module's an example) and fsevents on the Mac (unfortunately I don't think there's a single cross-platform module offering a uniform interface to these various system-specific ways to get directory-change notification events).

Once you manage to get such events, updating an appropriate SQL database is simple!-)

Alex Martelli