【问题标题】:How to compare two releases in a MusicBrainz Picard plugin?如何比较 MusicBrainz Picard 插件中的两个版本?
【发布时间】:2014-07-10 18:47:51
【问题描述】:

我一直在尝试编写一个 Picard 插件。我的想法是让它自动将音译的曲目列表作为 cmets 插入以非拉丁脚本编写的曲目标题的版本。 MusicBrainz 包含这些音译作为与实际版本并行存在的伪版本。例如,对于a given release,我必须首先阅读相关版本 ID 的关系。然后,我必须将这些曲目的标题转移到我文件的注释字段中。在伪代码中:

pseudo_release = actual_release.getTransliteration() # As indicated in a relationship
i = 1
while i <= actual_release.numTracks():
    actual_release.getTrack(i).setComment(pseudo_release.getTrack(i).getTitle())
    i++

第一行是我不知道该怎么做。由于该关系不能作为 Picard 变量使用,因此无法通过 API 中指示的任何方式访问它。

我一直在查看 Picard 的来源以及 the standalone web service,但找不到任何东西。这完全有可能吗?如果可以,我该怎么做?

【问题讨论】:

    标签: python metadata tagging musicbrainz


    【解决方案1】:

    如果您编写元数据处理器,则可以在 Picard 中获得有关关系的信息,包括音译的曲目列表。一个简单的插件迭代版本的所有关系如下所示:

    PLUGIN_NAME = "Find transliterated tracklisting relationships"
    PLUGIN_AUTHOR = "Wieland Hoffmann"
    PLUGIN_DESCRIPTION = "I'm too lazy"
    PLUGIN_VERSION = "0.1"
    PLUGIN_API_VERSIONS = ["1.0"]
    
    from picard.metadata import register_album_metadata_processor
    from picard import log
    
    
    # The relationship type id for transliterations from
    # https://musicbrainz.org/relationship/fc399d47-23a7-4c28-bfcf-0607a562b644
    TRANS_REL_UUID = "fc399d47-23a7-4c28-bfcf-0607a562b644"
    
    
    @register_album_metadata_processor
    def find_transliteration_relationship(album, metadata, release):
        if "relation_list" in release.children:
            for rel in release.relation_list:
                if rel.relation[0].type_id == TRANS_REL_UUID:
                    log.info("Found a transliterated tracklisting relationship")
                    for release in rel.relation[0].release:
                        log.info("Its target is https://musicbrainz.org/release/%s",
                                 release.id)
    

    传递给处理器的release 参数是Picards XmlNode 类的一个实例,它的结构(包括它的子对象)类似于您通过Web 服务向MusicBrainz 服务器询问此版本获得的XML( this 是它为您的示例版本返回的内容,如果您只询问关系)。现在您有了关系目标的 MBID,您可以使用 Picards Web 服务模块的 get 方法(albums tagger.xmlws 属性是 XmlWebService 类的一个实例)向 MusicBrainz 网站发送另一个请求,询问获取有关该版本的数据(不要忘记增加和减少 albums _requests 属性,以便在您更改数据之前它不会完成加载步骤)。

    使用它来请求和处理更多数据的其他一些插件是the album artist websiteLast.FM.Plus 插件。

    /edit:我刚刚被告知已经有 a ticket 用于改进 Picard 处理伪发布的方式,该链接指向 a plugin 做你想做的事。

    【讨论】:

      【解决方案2】:

      MusicBrainz Web Service你可以得到这样的音译版本: https://musicbrainz.org/ws/2/release/1492ce2b-a9ee-4aa3-b9e2-b18ad093bc51?inc=release-rels (注意inc=release-rels)。 您也可以使用json web service

      使用python-musicbrainzngs,您可以执行musicbrainzngs.get_release_by_id("1492ce2b-a9ee-4aa3-b9e2-b18ad093bc51",includes=["release-rels"]) 之类的操作。

      但是,Picard 不附带 musicbrainzngs。因此,您要么必须单独安装 python-musicbrainzngs,否则您的插件将无法正常工作,或者您必须使用 Picard 提供的模块。我不确定 Picard 元数据中到底包含什么以及不包含什么,但这些模块可能会有所帮助:picard.albumpicard.webservicepicard.mbxml

      【讨论】:

      • 您确定可以通过 Picard 使用非标准库吗?我使用 pip-Win 为 2.7.8 安装了 python-musicbrainzngs,它在交互式解释器中运行正常,但在插件中导入时出现“ImportError: No module named musicbrainzngs”错误。
      • 是的,这应该是可能的,但您可能不得不修改环境变量或将模块放在 Picard 找到它的特定位置。尽管我同意在 Windows 上运行它可能比在 Linux(我所在的位置)上更难。
      • 在 Picard 中使用 python-musicbrainzngs 不是一个好主意,因为 Picard 是用 (Py)Qt 构建的,并且到处使用它的异步原语,所以你很可能会导致库出现问题网络上的同步请求。除此之外,Windows 上与 Picard 捆绑的 Python 解释器不包含套接字模块 (iirc),因此很难使用构建 python-musicbrainzngs 的标准库网络模块。
      猜你喜欢
      • 1970-01-01
      • 2022-11-11
      • 2021-11-30
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      相关资源
      最近更新 更多