Bulk-Edit Vorbis Metadata

1. Usecase
2. Metadata of Vorbis Files
2.1. Data Structure
2.2. Editing Metadata
3. Editing by Script
3.1. Concept
3.2. Example
4. See also

tropf

ABSTRACT

A simple hack to bulk edit metadata of vorbis files using scripts.

1. Usecase

I regularly scrape or download music from a variety of sources. These sources usually provide metadata which follows a certain schema – but not my schema.

So it is not uncommon that i wan’t to transform some schema of metadata to another.

This article will use the convention of providing the license as URL in den copyright data field:

[...]
copyright=http://creativecommons.org/licenses/by-nc-nd/3.0/
[...]

I personally prefer a human readable string, so I would use:

[...]
LICENSE=CC-BY-ND 3.0
[...]

› I also use a different key.

2. Metadata of Vorbis Files

2.1. Data Structure

Metadata of vorbis files is a list of strings of the form key=value.

Even though the keys are case sensitive, most programs handling vorbis files don’t care and can handle lower and upper case spelling.

2.2. Editing Metadata

A simple way to edit metadata of vorbis files is using the program vorbistagedit. When invoked by vorbistagedit FILE it will open an editor with a temporary file looking like this:

# vorbistagedit ($Id$)
#
# Edit the lines in this file to your desire, but
# DO NOT touch lines starting with a colon (:)!
# You may use lines starting with a plus (+) to rename files.
#
# We are in directory:
#  /tmp
#
# Tags that should be applied to all files can be specified
# before the first per-file tag definiton starts.

: Carter_Vail_-_Veltvet.ogg
+ Carter_Vail_-_Veltvet.ogg
TITLE=Veltvet
ARTIST=Carter Vail
TRACKNUMBER=6
DATE=2019
COMPOSER=Carter Vail
LABEL=http://www.jamendo.com
ENCODEDBY=Jamendo:http://www.jamendo.com| LAME
LICENSE=CC-BY-NC-ND 3.0

: EOF

You can then edit, save and close the file and your changes will be applied.

3. Editing by Script

3.1. Concept

The basic idea is instead of invoking an interactive editor a script is executed on the file.

vorbistagedit executes $EDITOR TMPFILENAME. We just have to change $EDITOR to a script accepting a filename as one argument and changes that file.

› Obviously I will use sed with the -i flag.

3.2. Example

EDITOR=’sed -i -E -e "/^license|LICENSE/d" -e "s,^copyright=http://creativecommons.org/licenses/([^/]+)/([^/]+)/,&\nLICENSE=CC-\U\1\E \2,gi"’ vorbistagedit Carter_Vail_-_Veltvet.ogg

4. See also


04 December 2020
Home