- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
作为学习练习,我正在尝试为 MusicBrainz 编写一个插件,将 albumartistsort
匹配到 albumartist
并将 artistsort
匹配到 artist
,这与它当前使用的(显然)默认的 Last Name, First Name 格式相反。
我刚刚开始学习 Python,因此我正在尝试使用另一个插件作为指导,但需要进行一些重要的更改,这就是我可能搞砸的地方。
当我尝试安装插件时,它没有出现在插件列表中,尽管它被复制到插件文件夹中;并且未生成 .pyo
文件。我猜这是由于编译错误造成的,但我无法包含我需要的任何内容,因此我可以使用 picard
模块(不知道在哪里可以找到它或导入它)这样我就可以在我的 python 解释器中进行测试。
这是我的代码:
PLUGIN_NAME = "Sort Artist and Album Artist"
PLUGIN_AUTHOR = "Kevin Hernandez"
PLUGIN_DESCRIPTION = "Sorts artist/album artist by name as in Artist/Album Artist field instead of Last, First"
PLUGIN_VERSION = "0.1"
PLUGIN_API_VERSIONS = ["0.9.0", "0.10", "0.15", "0.16"]
from picard.metadata import register_album_metadata_processor
import re
def copy_albumartist_to_albumartistsort(tagger, metadata, release):
match = re.search($not($eq(metadata["albumartistsort"],metadata["albumartist"])))
if match:
metadata["albumartistsort"] = metadata["albumartist"]
def copy_artist_to_artistsort(tagger, metadata, release):
match = re.search($not($eq(metadata["artistsort"],metadata["artist"])))
if match:
metadata["artistsort"] = metadata["artist"]
register_album_metadata_processor(copy_albumartist_to_albumartistsort)
register_album_metadata_processor(copy_artist_to_artistsort)
我还尝试将函数定义为:
def copy_albumartist_to_albumartistsort(tagger, metadata, release):
metadata["albumartistsort"] = metadata["albumartist"]
def copy_artist_to_artistsort(tagger, metadata, release):
metadata["artistsort"] = metadata["artist"]
我必须指出,我并不完全理解它们何时被调用。我相信插件文档 here , here和 here不足以遵循他们那里的插件(例如,他们在不同插件中使用 re
的 search
和 match
方法没有在我指的是文档链接。
如果有更详尽的文档,您可以查明我在代码中做错了什么,或者知道如何在解释器中包含 picard
模块(在哪里可以找到它以及如何包括它),那么非常感谢您的意见和对这个问题的有效回答。
最佳答案
我认为您最大的问题是您混淆了 plugin API与 tagger scripting language .
标记器脚本是用一种简单的自定义语言编写的;插件是用 Python 编写的。您不能混合和匹配两种语言之间的语法。特别是:
match = re.search($not($eq(metadata["albumartistsort"],metadata["albumartist"])))
$not
、$eq
等在 Python 中没有任何意义。如果要检查是否相等,可以使用 ==
运算符。如果你想使用 re.search
,你可以使用正则表达式语法。等等。
此外,您的代码必须是有效的 Python,具有有效的缩进。您的代码,至少如此处发布的那样。
但让我们一一分析您的问题:
I am trying to write a plugin for MusicBrainz that matches the albumartistsort to albumartist and artistsort to artist, as opposed to the (apparently) default of Last Name, First Name format it is currently using.
MusicBrainz 中很少有自动默认设置。每个艺术家在数据库中都有一个名字和一个排序名称,由人类用户输入并由其他用户验证。您可以从 Web 界面看到这一点。例如,转到 David Bowie ,在右侧的“艺术家信息”面板中,您会看到“排序名称:Bowie, David”。如果您不习惯使用 MusicBrainz 的 Web 界面,您应该在尝试扩展 Picard 之前探索它。
When I try installing the plug in, it doesn't appear in the plugin list although it is copied to the plugin folder; and the .pyo file is not generated. I am guessing this is due to a compilation error
是的。如果您使用 -d
标志从命令行运行 Picard,它会向您显示错误,而不是静默地禁用您的插件,因此您不必猜测。这记录在 Troubleshooting 下. (如果您使用的是 Mac,路径将类似于 /Applications/MusicBrainz Picard.app/Contents/MacOS/MusicBrainz Picard
;我认为文档没有对此进行解释,因为它是标准操作系统X 应用程序包的东西。)
but I haven't been able to include whatever I need so I can use the picard module (don't know where to find it nor import it) so I can test in my python interpreter.
你真的不能在你的解释器中测试它。 Picard 捆绑了自己定制的 Python 解释器,而不是使用您的系统 Python。在该自定义解释器中,picard
包位于 sys.path
中,但在您的系统 Python 解释器中,它不是。并且尝试导入该包并使用其中的东西而不实际运行 Picard GUI 无论如何都不是一个好主意。
如果您真的想探索 picard
包中的内容,请下载源代码并运行代码的本地构建。但你真的不应该这样做。除了 API 中记录的功能之外,您不需要任何功能,如果您想调试东西,您希望在正确的上下文中调试它们,这通常意味着添加 print
功能和/或使用logging
代码中的模块。
I must point out that I don't fully understand when these are called.
在从 MusicBrainz 服务器下载每张专辑后的某个时刻,所有已注册的专辑处理器函数都会随专辑一起调用,所有已注册的轨道处理器函数都会随专辑中的每个轨道一起调用。
请注意,专辑处理器无法更改轨道级别的字段,例如轨道艺术家类型;为此,您需要一个轨道处理器。
e.g. the search and match methods they use in different plugins with re are not explained in the documentation links I am referring to.
那是因为它们是 Python 标准库的一部分,它被记录为标准 Python 文档的一部分——在这种情况下,请参见 re
.
在能够编写 Picard 插件之前,您需要了解 Python 的基础知识。
与此同时,我不确定您在此处尝试写什么,但它看起来像是一个非常令人费解的尝试,即“如果这两个字段不相等,则使它们相等”。这与“无条件地使它们相等”的作用相同。那么,为什么还要考虑正则表达式和 if
条件呢?
因此,您的函数可以简化为:
def copy_albumartist_to_albumartistsort(tagger, metadata, release):
metadata["albumartistsort"] = metadata["albumartist"]
def copy_artist_to_artistsort(tagger, metadata, release, track):
metadata["artistsort"] = metadata["artist"]
register_album_metadata_processor(copy_albumartist_to_albumartistsort)
register_track_metadata_processor(copy_artist_to_artistsort)
但是,您实际上根本不需要插件。你应该能够将这整个事情写成一个简单的标记器脚本:
$set(artistsort,%artist%)
$set(albumartistsort,%albumartist%)
关于python - 插件不适用于 MusicBrainz v1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20481326/
我一直忙于理解 MusicBrainz在过去的几个小时中,我注意到没有命令行应用程序来标记或指纹音频文件。 Musicbrainz 的指纹识别有任何 CLI 实现吗?我怎样才能创建这些指纹? 我找到了
我正在运行一个 Java 应用程序,该应用程序查询 Musicbrainz 数据库的信息,但遇到了一个特殊的问题。我的应用程序构建的查询(使用 java.net.URL.URL)如下: http://
我正在尝试使用 Musicbrainz 获取歌曲的首次发行日期。为此,我使用了 mikealmond musicBrainz 库。 我遇到的问题是,当我尝试执行与本示例 (https://github
我已经设法使用以下方法获取艺术家的信息 http://musicbrainz.org/ws/2/artist/?query=artist:michael%20jackson 返回 MBID(或 ID)
我正在创建一个 Perl 脚本,它将以 artist/album/mp3file 格式将 mp3 文件移动到我的音乐文件夹中。现在我的一些 mp3 文件可能没有 album 标签 所以我想查询 Mus
有没有办法获得艺术家(乐队)的专辑列表,以及专辑封面和运行时的链接? 我已经获得了这个端点,但它返回的数据令人困惑: http://musicbrainz.org/ws/2/recording?que
我正在尝试学习Python,并且认为我可以通过编写我实际使用的东西来学习。所以我正在尝试编写一个小脚本来翻录一些音乐 CD。 我正在使用 musicbrainzngs 包。我想要获得 CD 的轨道列表
谁能告诉我如何从 MusicBrainz 中获取轨道信息使用音频指纹从音频文件(mp3、wav、wma、ogg 等...)中提取数据库。我正在使用 MusicBrainz Sharp 库,但任何其他库
我有相当多的使用 javascript 的经验,但从未调用过外部数据库,所以这对我来说是个新领域。我正在尝试从 Musicbrainz 数据库中将乐队成员作为 json 对象返回。目前,哪个小组并不重
您好,我正在使用 musicbrainz 数据库,我无法计算每个国家/地区的所有艺术家,但无论我尝试哪个国家/地区,我都会遇到同样的错误,即使我尝试使用 like。请任何人告诉我我做错了什么? ERR
给定 music brainz 艺术家 ID(例如 - Bob Dylan = 72c536dc-7137-4477-a521-567eeb840fa8 ),我可以查询 music brainz xm
我想使用 CoverArtArchiveClient从 MusicBrainz 加载专辑图像,但它需要 MusicBrainz ID ( MBID )。有人可以提供有关如何获取特定专辑的 MBID 的
所以我为每首歌准备了 3 个东西: Name Artist MusicBrainz ID 如何按受欢迎程度对它们进行排序? 我可以使用什么服务来将歌曲与其“统计数据”相匹配? 我曾考虑使用 YouTu
我正在尝试使用第 3 方 java 库从 MusicBrainz 下载元数据:musicbrainzws2-java 我正在尝试检索指定专辑中单首歌曲的元数据。我已经检索到了专辑的 MBID,但是当我
是否有任何 Java/J2EE 网站将其软件和数据开源(例如 musicbrainz.org,开发人员可以通过下载 Perl/CGI Web 应用程序和 PostgreSQL 转储中的音乐数据轻松建立
我正在尝试使用 musicBrainz api 通过以下方法获取艺术家的唱片:http://www.musicbrainz.org/ws/2/release/?query=artist:eminem
作为学习练习,我正在尝试为 MusicBrainz 编写一个插件,将 albumartistsort 匹配到 albumartist 并将 artistsort 匹配到 artist,这与它当前使用的
我目前正在使用 mikealmond/MusicBrainz类以从精彩的 MusicBrainz 数据库中获取我需要的信息。 但我有一个问题,我需要从一个版本中获取录音,我已经找到了如何在浏览器中的
我正在尝试从 MusicBrainz API 检索轨道信息,仅使用艺术家和标题作为搜索查询: http://musicbrainz.org/ws/2/recording/?query=artist:C
Muscibrainz 提供 acoustID指纹,例如,here 但是,我找不到直接搜索它们的可能性(就像 PUIDs 或 echoprints 一样) 我错过了什么吗? acoustid.org
我是一名优秀的程序员,十分优秀!