【问题标题】:Subscribe-to-podcast fails - wants 2 arguments, not 1?订阅播客失败 - 需要 2 个参数,而不是 1 个?
【发布时间】:2014-06-07 17:48:57
【问题描述】:

我曾经通过调用“rhythmbox [播客的网址]”来订阅新的播客,但由于this bug,这不再有效。它只是打开 Rhythmbox,而不是打开和订阅。 (尽管如果您碰巧在播客部分单击“添加”,它会预先填充它)

GTK3 应用程序之间是否有一些新的通信方式,或者应用程序无法简单地告诉 Rhythmbox 订阅某个播客?

更新:查看答案here 我在 iPython 中发现了以下带有很多 tab 键的内容:

from gi.repository import RB
 ....
In [2]: RB.PodcastManager.insert_feed_url
Out[2]: gi.FunctionInfo(insert_feed_url)

In [3]: RB.PodcastManager.insert_feed_url('http://feeds.feedburner.com/NodeUp')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-b6415d6bfb17> in <module>()
----> 1 RB.PodcastManager.insert_feed_url('http://feeds.feedburner.com/NodeUp')

TypeError: insert_feed_url() takes exactly 2 arguments (1 given)

这似乎是正确的 API,但参数是什么?它可以在 GTK3 之前的系统中工作吗?

更新通过Python api here,我想我差不多了:

from gi.repository import RB
mypod = RB.PodcastChannel() #Creates blank podcast object
RB.podcast_parse_load_feed(mypod, 'http://wpdevtable.com/feed/podcast/', False)
#loads mypod.url, mypod.description etc.

RB.PodcastManager.add_parsed_feed(mypod); #fails

add_parsed_feed 上的文档似乎不正确,需要 2 个参数,而不是 1 个。我知道内部类的函数是用 def thing(self, firstarg) 定义的,这是否会导致 Python 绑定到 Rhythmbox 出现问题?为什么我无法将解析后的播客添加到 Rhythmbox?

【问题讨论】:

    标签: python ubuntu gtk pygobject rhythmbox


    【解决方案1】:

    您需要在调用add_parsed_feed 之前实例化PodcastManager 对象,以便将self 作为第一个参数隐式提供:

    manager = RB.PodcastManager()
    manager.add_parsed_feed(mypod)
    

    RB.PodcastManager().add_parsed_feed(mypod)
    

    当您以这种方式调用它时,add_parsed_feed 方法将绑定到您创建的 RB.PodcastManager 实例。当您调用绑定方法时,它绑定到的实例(在这种情况下为manager)将自动作为第一个参数提供(最终将在add_parsed_feed 中提供self)..

    另一方面,当您调用 RB.PodcastManager.add_parsed_feed 时,add_parsed_feed 方法不会绑定到 RB.PodcastManager 的任何实例,因此 Python 无法自动提供该实例作为第一个参数。这就是为什么您会收到关于仅提供一个参数的错误。

    编辑:

    请注意,使用此 API 似乎无法正常工作;即使我从嵌入到 Rhythmbox 的 Python 控制台中使用它,它似乎总是对我来说是段错误。如果您不介意编辑 Rhythmbox 源代码并自己构建它,那么获得您想要的行为实际上非常容易 - 这只是一行更改。在shell/rb-shell.c 中,在rb_shell_load_uri 函数中,更改此行:

    rb_podcast_source_add_feed (shell->priv->podcast_source, uri);
    

    到这里:

    rb_podcast_manager_subscribe_feed (shell->priv->podcast_manager, uri, TRUE);
    

    然后重建。现在,当您在启动节奏盒时包含播客 URI 时,它将订阅提要并开始播放。

    这是补丁形式的变化:

    diff --git a/shell/rb-shell.c b/shell/rb-shell.c
    index 77526d9..e426396 100644
    --- a/shell/rb-shell.c
    +++ b/shell/rb-shell.c
    @@ -2995,7 +2995,7 @@ rb_shell_load_uri (RBShell *shell,
            /* If the URI points to a Podcast, pass it on to the Podcast source */
            if (rb_uri_could_be_podcast (uri, NULL)) {
                    rb_shell_select_page (shell, RB_DISPLAY_PAGE (shell->priv->podcast_source));
    -               rb_podcast_source_add_feed (shell->priv->podcast_source, uri);
    +               rb_podcast_manager_subscribe_feed (shell->priv->podcast_manager, uri, TRUE);
                    return TRUE;
            }
    

    【讨论】:

    • 很好,你怎么知道要试试这个?看来这方面的文档很少,可惜没有简单的命令行订阅命令?
    • @NoBugs 这只是基本的 Python 语法,任何熟悉 Python 面向对象编程的人都会知道使用它。它不是 RB API 或类似的东西所独有的。您可以阅读更多关于绑定和未绑定方法的区别here
    • @NoBugs 或者有关 Python 中类的更一般性概述,请参阅 here
    • 我明白了,在 RB 中,他们使用初始资本来暗示它是一个需要创建的类。这里的文档显示它是一个类,add_parsed_feed 不是静态的。 lazka.github.io/pgi-docs/#RB-3.0/classes/…
    • 谢谢,我熟悉 Python 中类的工作方式,但我应该回顾一下——当它是一个基于绑定 C 代码的类时,就像在 Rhythmbox-Python api 中一样,这不是有什么不同吗?跨度>
    猜你喜欢
    • 2011-12-06
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多