IdEst – ID3 Editing and Scripting Tool (split by node):   Section:   Chapter:FastBack: Scripting   Up: Scripting   FastForward: Backups   Contents: Table of ContentsIndex: Concept Index

10.2 Using Scripts to Modify ID3 Frames

This section illustrates how to write scripts that modify ID3 tags. We will write a script which creates a new value for the ‘title’ (TIT2) frame from the name of the input file. The title is created using the following algorithm:

  1. Strip off leading directories and the ‘.mp3’ suffix.
  2. Replace underscores with spaces.

Here is the implementation:

;; settitle.scm - set title (TIT2) frame based on
;; the file name.

(use-modules (ice-9 regex)
	     (srfi srfi-13))

(define (idest-main file frames)
   ((string-match "(.*)\\.mp3" file) =>
    (lambda (match)
       (cons "TIT2"
		(lambda (c)
		  (if (char=? c #\_) #\space c))
		(match:substring match 1)))))
	(lambda (elt)
	  (not (string=? (car elt) "TIT2")))

(set! idest-readonly #f)

An example of using this script on all files in the current directory:

$ idest --script settitle *.mp3