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 #####'
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()
artists = set()
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 '--- songs ---'
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
source
share