我想從rhythmbox python插件中列出rhythmbox數據庫中的所有藝術家。我找到的唯一解決方案是讓用戶界面選擇所有藝術家和所有歌曲,遍歷每首歌曲並將該歌曲的藝術家名稱添加到一個集合中。如何列出rhythmbox插件中的所有藝術家
這個問題是(除了事實上它是痛苦的低效率),我不想僅僅因爲我想要數據庫中所有藝術家的列表而改變選定的藝術家。我之前嘗試保存選定的藝術家,以便在完成後恢復它,但由於UI需要一些時間才能更新新信息和更多信息(即更多的歌曲數據庫),需要的時間就越多。
的代碼可以與獲取 混帳克隆[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'
我想這樣做的原因是因爲我正在開發一個telnet界面到rhythmbox,https://github.com/sameltvom/rhythmcurse。
樂於輸入!
親切的問候, 塞繆爾