How to list all the artists in the rhythm box plugin

I am trying to list all the performers in the rhythmbox database from the python rhythmbox plugin. The only solution I found was to get the UI to select all the artists and all the songs, scroll through each song and add the name of the artist to the set.

The problem with this (in addition to being painfully inefficient) is that I do not want to change the selected artist just because I need a list of all the artists in the database. I tried to save the selected artist earlier to restore it when I finished, but this causes some problems due to the user interface taking some time to update with new information and additional information (i.e. more songs in the database ), the longer it takes.

The code can be obtained using git clone git @ github.com: 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 am developing a telnet interface for rhythmbox, https://github.com/sameltvom/rhythmcurse .

Happy to enter!

Regards, Samuel

+3
source share
1 answer

I found him! This is the property_query_model property, which I should use if I want to list all the records no matter what is selected in the user interface.

Now the code is as follows:

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 .

, , . .

+1

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


All Articles