如何列出节奏盒插件中的所有艺术家

发布于 2024-10-13 04:53:58 字数 2540 浏览 3 评论 0原文

我试图从 Rhythmbox Python 插件中列出 Rhythmbox 数据库中的所有艺术家。我找到的唯一解决方案是让 UI 选择所有艺术家和所有歌曲,循环播放每首歌曲并将该歌曲的艺术家姓名添加到集合中。

这样做的问题是(除了效率低下的事实之外)我不想仅仅因为我想要数据库中所有艺术家的列表而更改所选的艺术家。我之前尝试保存选定的艺术家,以便在完成后可以恢复它,但这会导致一些问题,因为 UI 需要一些时间才能使用新信息和更多信息(即更多歌曲)进行更新。数据库),花费的时间越多。

代码可以通过以下方式获取 git clone [email protected]:sameltvom/dblister.git

这是代码:

import rb
import rhythmdb
import gtk

class DblisterPlugin (rb.Plugin):
    def __init__(self):
        rb.Plugin.__init__(self)
    def activate(self, shell):
        self.shell = shell
        print '##### dblister #####'

        # choose all artists, this will choose all albums and songs as well

        # get the lock for rhythmbox ui
        gtk.gdk.threads_enter()
        for p in self.shell.props.library_source.get_property_views():
            if p.props.prop == rhythmdb.PROP_ARTIST:
                p.set_selection([""])
                break
        gtk.gdk.threads_leave()

        ##################### Print all artists in database ######################

        # loop through all songs currently selected (i.e. all songs since we did p.set_selection([""]) above
        # for each song, try to add the artist name to the 'artists' set
        artists = set() # unique keys, no duplicates
        for row in self.shell.props.selected_source.props.query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists ---'
        for artist in artists:
            print artist


        ##################### Print all songs in database ######################

        print '--- songs ---'
        # loop through all songs currently selected (i.e. all songs since we did p.set_selection([""]) above
        # for each song, print artist name and title
        for row in self.shell.props.selected_source.props.query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
             song = self.shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
            print artist + ' - ' + song

    def deactivate(self, shell):
        del self.shell
        print 'Bye world'

我想这样做的原因是因为我正在开发一个到 Rhythmbox 的 telnet 接口,https://github.com /sameltvom/节奏诅咒

很高兴输入!

亲切的问候, 塞缪尔

I'm trying to list all artists in the rhythmbox database from within a rhythmbox python plugin. The only solution I have found is to make the UI select all artists and all songs, loop through every song and add that song's artist name to a set.

The problem with this is (beside from the fact it's painfully inefficient) that I don't want to change the selected artist just because I want a list of all the artists in the database. I tried earlier to save the selected artist so that I could restore it when I'm done but that causes some problems due to the fact that the UI takes some time to be updated with the new information and the more information (i.e. more songs in the database), the more time it takes.

The code can be fetched with
git clone [email protected]:sameltvom/dblister.git

Here is the code:

import rb
import rhythmdb
import gtk

class DblisterPlugin (rb.Plugin):
    def __init__(self):
        rb.Plugin.__init__(self)
    def activate(self, shell):
        self.shell = shell
        print '##### dblister #####'

        # choose all artists, this will choose all albums and songs as well

        # get the lock for rhythmbox ui
        gtk.gdk.threads_enter()
        for p in self.shell.props.library_source.get_property_views():
            if p.props.prop == rhythmdb.PROP_ARTIST:
                p.set_selection([""])
                break
        gtk.gdk.threads_leave()

        ##################### Print all artists in database ######################

        # loop through all songs currently selected (i.e. all songs since we did p.set_selection([""]) above
        # for each song, try to add the artist name to the 'artists' set
        artists = set() # unique keys, no duplicates
        for row in self.shell.props.selected_source.props.query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists ---'
        for artist in artists:
            print artist


        ##################### Print all songs in database ######################

        print '--- songs ---'
        # loop through all songs currently selected (i.e. all songs since we did p.set_selection([""]) above
        # for each song, print artist name and title
        for row in self.shell.props.selected_source.props.query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
             song = self.shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
            print artist + ' - ' + song

    def deactivate(self, shell):
        del self.shell
        print 'Bye world'

The reason I want to do this is because I'm developing a telnet interface to rhythmbox, https://github.com/sameltvom/rhythmcurse.

Happy for input!

Kind regards,
Samuel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2024-10-20 04:53:58

我找到了!如果我想列出所有条目,无论 UI 中选择了什么,我都应该使用 base_query_model 属性。

代码现在看起来像:

import rb
import rhythmdb
import gtk

class DblisterPlugin (rb.Plugin):
    def __init__(self):
        rb.Plugin.__init__(self)
    def activate(self, shell):
        self.shell = shell
        print '##### dblister #####'


        #################### Print all artists in the library ####################
        artists = set() # unique keys, no duplicates
        for row in self.shell.props.library_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists using library_source---'
        for artist in artists:
            print artist

        del artists


        ##################### Print all artists in database ######################

        artists = set() # unique keys, no duplicates
        for row in self.shell.props.selected_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists ---'
        for artist in artists:
            print artist


        ##################### Print all songs in database ######################

        print '--- songs ---'
        for row in self.shell.props.selected_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
             song = self.shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
            print artist + ' - ' + song

    def deactivate(self, shell):
        del self.shell
        print 'Bye world'

我还发现了另一个好东西。如果我使用 elf.shell.props.library_source.props.base_query_model 而不是 self.shell.props.selected_source.props.base_query_model 我仍然会得到输出,即使我可能已将视图更改为左侧的 Last.FM 或 Radio窗格。

但是,我仍然必须循环遍历所有歌曲才能找到所有艺术家。但主要问题已经消失了。

I found it! It was the property base_query_model I should use if I want to list all entries regardless of what is selected in the UI.

The code now looks like:

import rb
import rhythmdb
import gtk

class DblisterPlugin (rb.Plugin):
    def __init__(self):
        rb.Plugin.__init__(self)
    def activate(self, shell):
        self.shell = shell
        print '##### dblister #####'


        #################### Print all artists in the library ####################
        artists = set() # unique keys, no duplicates
        for row in self.shell.props.library_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists using library_source---'
        for artist in artists:
            print artist

        del artists


        ##################### Print all artists in database ######################

        artists = set() # unique keys, no duplicates
        for row in self.shell.props.selected_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
            artists.add(artist)

        print '--- artists ---'
        for artist in artists:
            print artist


        ##################### Print all songs in database ######################

        print '--- songs ---'
        for row in self.shell.props.selected_source.props.base_query_model:
             entry = row[0]
             artist = self.shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
             song = self.shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
            print artist + ' - ' + song

    def deactivate(self, shell):
        del self.shell
        print 'Bye world'

I also found another nice thing as well. If I use elf.shell.props.library_source.props.base_query_model instead of self.shell.props.selected_source.props.base_query_model I will still get output even though I might have changed view to e.g. Last.FM or Radio in the left side pane.

However, I still must loop through all songs to find all artists. But the main problem is gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文