4

This is specifically geared towards managing MP3 files, but it 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 MP3 files. Any time a file is added, updated or deleted, 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.

The Stack Overflow question Managing a large collection of music has a little of what I want.

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.

Community
  • 1
  • 1
TheLizardKing
  • 2,014
  • 3
  • 20
  • 27

3 Answers3

8

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
  • 854,459
  • 170
  • 1,222
  • 1,395
3

If you use Linux, you can use PyInotify.

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

Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
0

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
  • 68,631
  • 21
  • 159
  • 205
  • Can it connect to a database? How can I access it's data? – TheLizardKing Feb 22 '10 at 23:04
  • 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 Feb 22 '10 at 23:10
  • 1
    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 Feb 22 '10 at 23:12
  • Which doesn't really make sense if it isn't fully integrated with a media player. – AndiDog Feb 22 '10 at 23:14
  • 4
    What I do with the data is up to me. Thanks for your help. – TheLizardKing Feb 22 '10 at 23:16