这专门用于管理 MP3 文件,但它应该可以轻松地适用于任何包含大量文件的目录结构。
我想找到或编写一个守护程序(最好用Python)来监视一个包含许多子文件夹的文件夹,这些子文件夹都应该包含X个MP3文件。每当添加、更新或删除文件时,它都应该在数据库(最好是 PostgreSQL)中反映出来。我愿意接受,如果只是移动文件,相应的行将被删除并重新创建,但更新现有行会让我最高兴。
Stack Overflow 问题管理大量音乐 有一些我想要的东西。
我基本上只想要一个数据库,然后我可以用它做任何我想做的事情。我目前最新的数据库是我的 iTunes.xml
文件,但我不想过度依赖它,因为我并不总是想依赖 iTunes 来处理我的数据。音乐管理。我看到很多项目都做了一些我想要的事情,但其格式要么我无法访问,要么比我想要的更复杂。如果有一些媒体播放器可以观看文件夹并更新易于访问的数据库,那么我完全支持它。
我倾向于自己编写的原因是因为自己选择数据库和模式会很好。
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.
发布评论
评论(3)
另一个答案已经建议使用 pyinotify for Linux,让我添加 watch_directory 适用于 Windows(关于 Windows 中的可能性的一个很好的讨论是 此处,该模块是一个示例)和 fsevents (不幸的是,我认为没有一个跨平台模块为这些各种特定于系统的方式获取目录更改通知事件提供统一的接口)。
一旦您设法获取此类事件,更新适当的 SQL 数据库就很简单!-)
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!-)
如果您使用 Linux,则可以使用 PyInotify。
inotify
可以在程序运行时通知您有关文件系统事件的信息。If you use Linux, you can use PyInotify.
inotify
can notify you about filesystem events when your program is running.IMO,具有这些功能的最佳媒体播放器是 Winamp。它每 X 分钟重新扫描一次音乐文件夹,这对于音乐来说已经足够了(但当然比让操作系统监视更改效率稍低)。
但是,当您寻求有关编写自己的建议时,您可以使用 pyinotify (仅限 Linux)。如果您运行的是 Windows,则可以使用 ReadDirectoryChangesW API 调用
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