]> git.draconx.ca Git - picard-plugins.git/blob - karaoke-flagger.py
Ignore compiled python junk.
[picard-plugins.git] / karaoke-flagger.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright © 2019-2020 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 = "1"
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 stanadlone recordings, "track" is actually a recording, not a track
32     recording = track.get("recording", track)
33     for r in recording["relations"]:
34         # 'karaoke version of' is the backward relation of this type...
35         if r["type-id"] != "39a08d0e-26e4-44fb-ae19-906f5fe9435d":
36             continue
37         if r["direction"] == "backward":
38             metadata["~karaoke"] = "yes"
39             return
40
41 if modulename() in config.setting["enabled_plugins"]:
42     register_track_metadata_processor(add_metadata)
43     log.info("%s activated" % (modulename()))
44 else:
45     log.debug("%s disabled in configuration" % (modulename()))