]> git.draconx.ca Git - picard-plugins.git/commitdiff
Add karaoke flagger script
authorNick Bowler <nbowler@draconx.ca>
Fri, 19 Apr 2019 17:11:00 +0000 (13:11 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 19 Apr 2019 17:12:32 +0000 (13:12 -0400)
karaoke-flagger.py [new file with mode: 0644]

diff --git a/karaoke-flagger.py b/karaoke-flagger.py
new file mode 100644 (file)
index 0000000..13abe78
--- /dev/null
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2019 Nick Bowler
+#
+# License GPLv3+: GNU General Public License version 3 or any later version.
+# This is free software: you are free to change and redistribute it.
+# There is NO WARRANTY, to the extent permitted by law.
+
+PLUGIN_NAME = u"Karaoke Flagger"
+PLUGIN_AUTHOR = u"Nick Bowler"
+PLUGIN_DESCRIPTION = u'''<p>This plugin sets a metadata variable for recordings
+with the "karaoke version of" relation, so that tagger scripts can incorporate
+this fact into file tags.</p>
+
+<p>The metadata variable <code>%_karaoke%</code> will be set to "yes" on
+karaoke tracks, and left unset otherwise.  So a tagger script might use
+<code>$if(%_karaoke%,$set(comment:karaoke,%_karaoke%))</code>, for example,
+to embed that into the file's comment tag.</p>
+'''
+PLUGIN_VERSION = "0"
+PLUGIN_API_VERSIONS = ["2.0"]
+PLUGIN_LICENSE = "GPL-3.0-or-later"
+
+from picard import (config, log)
+from picard.metadata import register_track_metadata_processor
+
+def modulename():
+    return modulename.__module__[len("picard.plugins."):]
+
+def add_metadata(tagger, metadata, track, release):
+    for r in track["recording"]["relations"]:
+        # 'karaoke version of' is the backward relation of this type...
+        if r["type-id"] != "39a08d0e-26e4-44fb-ae19-906f5fe9435d":
+            continue
+        if r["direction"] == "backward":
+            metadata["~karaoke"] = "yes"
+            return
+
+if modulename() in config.setting["enabled_plugins"]:
+    register_track_metadata_processor(add_metadata)
+    log.info("%s activated" % (modulename()))
+else:
+    log.debug("%s disabled in configuration" % (modulename()))