aboutsummaryrefslogtreecommitdiff
path: root/emms-tag-tracktag.el
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-05-16 17:45:40 -0500
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-05-16 17:56:56 -0500
commit7dc68851d417343917f1c3d7eaaeef87b16b4690 (patch)
treef514d41f856321d4ebbf21bbee58b86bce269245 /emms-tag-tracktag.el
parentfba4599027e9982a143922fdf279791a8334cf6e (diff)
Add: re-namespace emms-tag-tracktag, info-date map to date
Diffstat (limited to 'emms-tag-tracktag.el')
-rw-r--r--emms-tag-tracktag.el73
1 files changed, 73 insertions, 0 deletions
diff --git a/emms-tag-tracktag.el b/emms-tag-tracktag.el
new file mode 100644
index 0000000..71c6ff5
--- /dev/null
+++ b/emms-tag-tracktag.el
@@ -0,0 +1,73 @@
+;;; emms-tag-tracktag.el --- EMMS interface for audiotools tracktag -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Grant Shoshin Shangreaux
+
+;; Author: Grant Shoshin Shangreaux <grant@churls.world>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Provides a wrapper for audiotools tracktag executable
+;; http://audiotools.sourceforge.net/tracktag.html
+;; Given an EMMS TRACK structure, it will map the emms-info fields onto
+;; arguments for tracktag. Then it calls the tracktag process to write the
+;; info as metadata tags on the track's associated file.
+
+;;; Code:
+
+(require 'emms)
+
+(defvar emms-tag-tracktag--info-fields
+ '((info-artist . artist)
+ (info-composer . composer)
+ (info-performer . performer)
+ (info-title . name)
+ (info-album . album)
+ (info-tracknumber . number)
+ (info-discnumber . album-number)
+ (info-year . year)
+ (info-date . date)
+ (info-note . comment))
+ "An alist mapping info-* fields to tracktag fields.")
+
+(defun emms-tag-tracktag--map-track-info (track)
+ (seq-filter (lambda (cell) (cdr cell))
+ (mapcar (lambda (pair)
+ (cons (cdr pair) (emms-track-get track (car pair))))
+ emms-tag-tracktag--info-fields)))
+
+(defun emms-tag-tracktag--build-args (track)
+ (flatten-list
+ (append
+ (mapcar (lambda (pair)
+ (let ((tag (car pair)) (value (cdr pair)))
+ (when value
+ ;; if we've deleted a tag value in the editor, remove the tag from file metadata.
+ (if (string-equal "" value) (concat "--remove-" (format "%s" tag))
+ (concat "--" (format "%s" tag) "=" value)))))
+ (emms-tag-tracktag--map-track-info track))
+ (list (emms-track-name track)))))
+
+(defun emms-tag-tracktag-file (track)
+ (apply #'call-process
+ "tracktag" nil
+ (get-buffer-create emms-tag-editor-log-buffer)
+ nil
+ "-Vdebug"
+ (emms-tag-tracktag--build-args track)))
+
+(provide 'emms-tag-tracktag)
+;;; emms-tag-tracktag.el ends here