Python daemon for browsing a folder and updating a database

It is specifically designed to manage MP3 files, but it should work easily for any directory structure with a large number of files.

I want to find or write a daemon (preferably in Python) that will look at a folder with many subfolders that should contain the X-number of MP3 files. Each time a file is added, updated or deleted, it should reflect this in the database (preferably PostgreSQL). I am ready to accept, if the file is simply moved, that the corresponding lines are deleted and recreated again, but updating existing lines will make me happiest.

Stack Overflow Question Managing a large collection of music has a bit of what I want.

I just want the database to be able to do what I want. My most modern database at the moment is my iTunes.xml file, but I don’t want to rely on it too much, because I don’t always want to rely on iTunes to control music. I see a lot of projects that do a little of what I want, but in a format that either I can’t get, or just more complicated than I want. If there is some kind of media player that can browse the folder and update the database, which is easily accessible, I’m all for this.

The reason I tend to write my own is because it would be nice to choose my database and schema.

+4
source share
3 answers

Another answer already suggested by pyinotify for Linux, let me add watch_directory for Windows (a good discussion of features on Windows here , an example module) and fsevents on Mac (unfortunately, I don't think there is one cross-platform module offering a single interface for of these various systematic ways to get directories - change notifications).

Once you manage to receive such events, updating the corresponding SQL database is easy! -)

+8
source

If you are using Linux, you can use PyInotify .

inotify can notify you of file system events when your program is running.

+3
source

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

But since you asked for suggestions for writing your own, you can use pyinotify (Linux only). If you are using Windows, you can use the ReadDirectoryChangesW API call

0
source

Source: https://habr.com/ru/post/1302084/


All Articles