Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Edit OGG Vorbis tag metadata in Emacs
;;; vorbiscomment.el --- Edit comments in Ogg Vorbis files
;; Copyright (C) 2003 Jesper Harder
;; Author: Jesper Harder <>
;; Created: 19 Aug 2003
;; Version: 1.1
;; Location: <>
;; Keywords: multimedia, data
;; 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 2, or (at your option)
;; any later version.
;;; Commentary:
;; Use `M-x vorbiscomment' to extract the comment headers from an Ogg
;; Vorbis file. `C-c C-c' in the comment buffer writes the comments
;; back to the file. You need the program "vorbiscomment" from
;; vorbis-tools.
;;; History:
;; Version 1.1: Fix saving non-ASCII file names.
;;; Code:
(defvar vorbiscomment-keywords
(list (concat "^"
(regexp-opt '("title" "version" "album" "tracknumber"
"artist" "performer" "copyright"
"license" "organization" "description"
"genre" "date" "location" "contact"
"isrc") t) "="))
"Canonical Ogg Vorbis tag names.")
(define-derived-mode vorbiscomment-mode text-mode "vorbiscomment"
(setq font-lock-defaults '(vorbiscomment-keywords t t nil nil))
(make-variable-buffer-local 'vorbiscomment-file))
(define-key vorbiscomment-mode-map (kbd "C-c C-c")
(defun vorbiscomment (file)
"Edit comments in Ogg Vorbis file FILE.\\<vorbiscomment-mode-map>
Use \\[vorbiscomment-save-and-exit] to save comments."
(interactive "fOgg Vorbis file: ")
(switch-to-buffer (generate-new-buffer file))
(setq vorbiscomment-file (expand-file-name file))
(let ((coding-system-for-read 'utf-8))
(call-process "vorbiscomment" nil t t "--raw" "-l" vorbiscomment-file)))
(defun vorbiscomment-save-and-exit ()
"Save comments and exit."
(let (status)
(encode-coding-region (point-min) (point-max) 'utf-8)
(setq status
(call-process-region (point-min) (point-max)
"vorbiscomment" nil standard-output nil
"--raw" "-q" "-w"
(if (string= status "")
(message "Comments saved in %s" vorbiscomment-file)
(error status)))
(kill-buffer nil))
(provide 'vorbiscomment)
;;; vorbiscomment.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment