Python守护进程来观察文件夹并更新数据库(Python daemon to watch a folder and update a database)

编程入门 行业动态 更新时间:2024-10-11 09:19:45
Python守护进程来观察文件夹并更新数据库(Python daemon to watch a folder and update a database)

这特别适用于管理MP3文件,但它应该很容易适用于任何具有大量文件的目录结构。

我想查找或编写一个守护进程(最好在Python中),该守护进程将监视包含许多子文件夹的文件夹,这些文件夹应该都包含X个MP3文件。 无论何时添加,更新或删除文件,都应该在数据库(最好是PostgreSQL)中反映出来。 我愿意接受如果简单地移动一个文件,删除并重新创建相应的行,但更新现有行将使我最快乐。

堆栈溢出问题管理大量的音乐集合有一点我想要的。

我基本上只想要一个数据库,然后我可以做任何我想要的。 截至目前,我的最新数据库是我的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.

最满意答案

另一个答案已经提出了针对Linux的pyinotify ,让我为Windows添加watch_directory(关于Windows的可能性的一个很好的讨论,这个模块的例子)和Mac上的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!-)

更多推荐

本文发布于:2023-08-04 10:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   进程   数据库   Python   daemon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!