1 # -*- coding: utf-8 -*-
3 # Copyright © 2019 Nick Bowler
5 # License GPLv3+: GNU General Public License version 3 or any later version.
6 # This is free software: you are free to change and redistribute it.
7 # There is NO WARRANTY, to the extent permitted by law.
9 PLUGIN_NAME = u"Karaoke Flagger"
10 PLUGIN_AUTHOR = u"Nick Bowler"
11 PLUGIN_DESCRIPTION = u'''<p>This plugin sets a metadata variable for recordings
12 with the "karaoke version of" relation, so that tagger scripts can incorporate
13 this fact into file tags.</p>
15 <p>The metadata variable <code>%_karaoke%</code> will be set to "yes" on
16 karaoke tracks, and left unset otherwise. So a tagger script might use
17 <code>$if(%_karaoke%,$set(comment:karaoke,%_karaoke%))</code>, for example,
18 to embed that into the file's comment tag.</p>
21 PLUGIN_API_VERSIONS = ["2.0"]
22 PLUGIN_LICENSE = "GPL-3.0-or-later"
24 from picard import (config, log)
25 from picard.metadata import register_track_metadata_processor
28 return modulename.__module__[len("picard.plugins."):]
30 def add_metadata(tagger, metadata, track, release):
31 for r in track["recording"]["relations"]:
32 # 'karaoke version of' is the backward relation of this type...
33 if r["type-id"] != "39a08d0e-26e4-44fb-ae19-906f5fe9435d":
35 if r["direction"] == "backward":
36 metadata["~karaoke"] = "yes"
39 if modulename() in config.setting["enabled_plugins"]:
40 register_track_metadata_processor(add_metadata)
41 log.info("%s activated" % (modulename()))
43 log.debug("%s disabled in configuration" % (modulename()))