-
Notifications
You must be signed in to change notification settings - Fork 1
/
taglib-extended.scm
51 lines (42 loc) · 1.34 KB
/
taglib-extended.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#lang scheme
(provide taglib-extended-tags)
(require srfi/2)
(require srfi/26)
(require (planet untyped/unlib/list))
(require "taglib.ss")
(require "taglib_more")
(define (parse-txxx-frame raw-tag-value)
(and-let* ((m (regexp-match
(regexp "\\[(.*)\\] (.*) ([^ ]*)")
raw-tag-value)))
(cons
(string-upcase (second m))
(fourth m))))
(define tag-alist-map
`((#"TRCK" . "TRACKNUMBER")
(#"TPE1" . "ARTIST")
(#"TIT2" . "TITLE")
(#"TALB" . "ALBUM")))
(define (translate-tag raw-tag)
(let ((tag-type (car raw-tag))
(tag-value (cdr raw-tag)))
(or
(and (equal? tag-type #"TXXX")
(parse-txxx-frame tag-value))
(and-let* ((key (assoc-value/default tag-type tag-alist-map #f)))
(cons key tag-value))
raw-tag)))
(define (id3v2-frames filename)
(and-let* ((raw-tags (taglib-id3v2-frames filename))
((not (null? raw-tags))))
(map translate-tag raw-tags)))
(define (taglib-extended-tags filename)
(or
(id3v2-frames filename)
(taglib-flac-frames filename)
(taglib-tags filename)))
;(printf "~%-----------------~%")
;(write (taglib-extended-tags "etc/test2.mp3"))
;
;(printf "~%~%~%-----------------~%")
;(write (taglib-extended-tags "etc/test2.flac"))