1 # -*- coding: utf-8 -*-
3 # Copyright © 2019-2020 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 metadata variables for
12 certain types of recordings, so that tagger scripts can incoporate
13 what sort of track we are looking at into the file tags.</p>
16 <dt><code>%_karaoke%</code></dt>
17 <dd>Set to "yes" if the track is a karaoke recording.</dd>
18 <dt><code>%_drama%</code></dt>
19 <dd>Set to "yes" if the track is a recording of an audio drama.</dd>
22 <p>For example, you could use a tagger script such as
23 <code>$if(%_karaoke%,$set(comment:karaoke,%_karaoke%))</code>
24 to tag karaoke tracks as such in order to help generate playlists
25 for your next karaoke dance party.</p>
28 PLUGIN_API_VERSIONS = ["2.0"]
29 PLUGIN_LICENSE = "GPL-3.0-or-later"
31 from picard import (config, log)
32 from picard.metadata import register_track_metadata_processor
35 return modulename.__module__[len("picard.plugins."):]
37 def add_metadata(tagger, metadata, track, release):
38 # for stanadlone recordings, "track" is actually a recording, not a track
39 recording = track.get("recording", track)
40 for r in recording["relations"]:
41 # 'karaoke version of' is the backward relation of this type...
42 if r["type-id"] == "39a08d0e-26e4-44fb-ae19-906f5fe9435d":
43 if r["direction"] == "backward":
44 metadata["~karaoke"] = "yes"
45 if r["target-type"] == "work":
46 if r["work"]["type-id"] == "40ed00fb-cd1d-3de5-afcc-4d08720d63e7":
47 metadata["~drama"] = "yes"
49 if modulename() in config.setting["enabled_plugins"]:
50 register_track_metadata_processor(add_metadata)
51 log.info("%s activated" % (modulename()))
53 log.debug("%s disabled in configuration" % (modulename()))