Rhythmbox插件无法访问播客文件
我正在写一个Rhythmbox的插件,目的是遍历Rhythmbox当前知道的所有播客文件(无论是已经下载的还是未下载的),然后对这些文件做一些处理。
经过一些研究和在Rhythmbox的Python Shell中测试,我成功获取到了所有对象的列表。但是,当我把这段代码写进插件里时,出现了一个错误:
(rhythmbox:7500): GLib-GObject-WARNING **: invalid cast from `RhythmDBTree' to `RhythmDBEntryType'
而且,entries
这个列表是空的:
def run(self, action, shell):
db = shell.get_property('db')
entry_type = db.entry_type_get_by_name('podcast-post')
print entry_type
entries = []
db.entry_foreach_by_type(entry_type, entries.append)
print entries
不过,print entry_type
的输出是:<rhythmdb.EntryType object at 0xa7ea34c (RhythmDBEntryType at 0xa106988)>
,所以这个db对象显然是有效的。
我到底哪里出错了呢?
2 个回答
1
首先试着重新安装rhythmbox这个软件。
看看这个命令的输出结果,我这边运行得很好,你也把你那边的输出结果发出来。
from __future__ import print_function
def plugin_create(database):
print(database)
db.entry_foreach_by_type(db.entry_type_get_by_name('podcast-post'), print)
0
我试了以下代码:
def run(self, action, shell):
db = shell.get_property('db')
entry_type = db.entry_type_get_by_name('podcast-post')
print entry_type
entries = []
db.entry_foreach(entries.append)
print entries
for entry in entries:
if entry.get_type() == entry_type:
# process entry...
它运行得很好。虽然这个解决方案不是最优雅的,但对我来说已经足够用了。