From: Clinton Ebadi Date: Tue, 4 Dec 2012 08:08:49 +0000 (-0500) Subject: Initial `abcddb-tool parse' command X-Git-Url: https://git.hcoop.net/clinton/abcde.git/commitdiff_plain/dde7052dd4500a1c4e0570db71365211ccfd7dfd?ds=sidebyside Initial `abcddb-tool parse' command Produces similar output to `cddb-tool parse', but using bash's $'' syntax for saner escaping, and supporting multiple disc genres. No CLI yet. --- diff --git a/abcddb-tool b/abcddb-tool index 8aab4ed..218e75a 100755 --- a/abcddb-tool +++ b/abcddb-tool @@ -88,7 +88,50 @@ of (disc-number . tag-value)" (make-initial-db 'comment 'disc 'tracks) (port->stream cddb-port read-line))) - +;;; Commands + +;; string-tokenize is weird, might want to just use regexeps instead +(define cddb-dtitle-char-set (char-set-difference char-set:printing + (char-set #\/))) + +(define* (cddb->export cddb #:optional (out (current-output-port))) + "Convert database to shell expression for abcde" + ;; Using single quoting instead of "" to make life easier + (letrec* ((escape-for-shell + (lambda (x) (regexp-substitute/global #f "['\\\\]" x + 'pre + (lambda (m) (string-append "\\" (match:substring m))) + 'post))) + (disc-query (lambda* (key #:optional (default '(""))) + (cond ((cddb-query-disc cddb key) => identity) + (else default)))) + + (artist ((lambda (s) (substring s 0 (- (string-index s #\/) 1))) (car (disc-query 'TITLE))) + + #;(string-trim-right (car (string-tokenize (car (disc-query 'TITLE)) cddb-dtitle-char-set)))) + + (album ((lambda (s) (substring s (+ (string-index s #\/) 2))) (car (disc-query 'TITLE))) + #;(string-trim (string-join (cdr (string-tokenize (car (disc-query 'TITLE)) cddb-dtitle-char-set)) + "/")))) + + + (newline out) + + ;; Not exported CDDBGENRE intentionally, since it appears unused + (format out "DISCID=$'~A'~%DALBUM=$'~A'~%DARTIST=$'~A'~%CDYEAR=$'~A'~%" + (escape-for-shell (car (disc-query 'DISCID))) + (escape-for-shell artist) + (escape-for-shell album) + (escape-for-shell (car (disc-query 'YEAR)))) + + ;; Store genre(s) in a bash array. mp3s will just have to live with + ;; using the first, but Vorbis/FLAC can handle an arbitrary set of + ;; genres + (format out "DGENRE=(~{$'~A' ~})~%" (map escape-for-shell (disc-query 'GENRE))) + + (format out "~:{TRACK~A=$'~A'~%~}" + (map (lambda (ttitle) (list (1+ (first ttitle)) (escape-for-shell (second ttitle)))) + (cddb-query-tracks cddb 'TITLE)))))