]> git.draconx.ca Git - picard-plugins.git/blob - karaoke-flagger.py
Add karaoke flagger script
[picard-plugins.git] / karaoke-flagger.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright © 2019 Nick Bowler
4 #
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.
8
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>
14
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>
19 '''
20 PLUGIN_VERSION = "0"
21 PLUGIN_API_VERSIONS = ["2.0"]
22 PLUGIN_LICENSE = "GPL-3.0-or-later"
23
24 from picard import (config, log)
25 from picard.metadata import register_track_metadata_processor
26
27 def modulename():
28     return modulename.__module__[len("picard.plugins."):]
29
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":
34             continue
35         if r["direction"] == "backward":
36             metadata["~karaoke"] = "yes"
37             return
38
39 if modulename() in config.setting["enabled_plugins"]:
40     register_track_metadata_processor(add_metadata)
41     log.info("%s activated" % (modulename()))
42 else:
43     log.debug("%s disabled in configuration" % (modulename()))