Skip to content

Commit

Permalink
Pretty-print <id3v{1,2}-tag}
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1ff committed Jan 7, 2024
1 parent 463b1f1 commit a4ccd02
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
19 changes: 18 additions & 1 deletion scheme/scribbu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ at `root'"
(start-time #:init-value "" #:accessor start-time #:init-keyword #:start-time)
(end-time #:init-value "" #:accessor end-time #:init-keyword #:end-time))

(define-method (display (x <id3v1-tag>) out)
"Pretty-print <id3v1-tag> instances"
(display "<id3v1-tag " out)
(display (format #f "~a - ~a" (slot-ref x 'artist) (slot-ref x 'title)) out)
(display ">" out))

(make-symbol "unknown-frame")

(make-symbol "album-frame") ;; TAL/TALB
Expand Down Expand Up @@ -226,6 +232,18 @@ at `root'"
(frames #:init-value '() #:accessor frames #:init-keyword #:frames)
(padding #:init-value 0 #:accessor padding #:init-keyword #:padding))

(define-method (display (x <id3v2-tag>) out)
"Pretty-print <id3v2-tag> instances"
(let* ((artists (get-frames x 'artist-frame))
(artist
(if (= 0 (length artists)) "" (slot-ref (car artists) 'text)))
(titles (get-frames x 'title-frame))
(title (if (= 0 (length titles)) "" (slot-ref (car titles) 'text))))
(display "<id3v2-tag " out)
(display (format #f "~a - ~a" artist title) out)
(display (format #f " (~d bytes padding)" (slot-ref x 'padding)) out)
(display ">" out)))

(define (has-frame-internal frms f)
(cond ((null? frms) #f)
((let ((x (car frms))) (eq? f (slot-ref x 'id))) #t)
Expand All @@ -245,4 +263,3 @@ at `root'"
(set! frms (cdr frms)))
ret))


6 changes: 3 additions & 3 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ EXTRA_DIST = test-util test-split test-rename test-report test-report-tdf \
test-cleanup-encoded-by.scm test-cleanup-encoded-by \
test-cleanup-from-audacity.scm test-cleanup-from-audacity \
test-tagsets-from-scheme.scm test-tagsets-from-scheme \
test-frames-from-scheme.scm test-frames-from-scheme \
test-frames-from-scheme.scm test-display.scm test-frames-from-scheme \
test-scripting test-options test-popm test-xtag test-text test-genre \
test-m3u test-snarfed-in-scribbu
test-m3u test-snarfed-in-scribbu test-display
CLEANFILES = id3v20B id3v21B report.last.csv report-tdf.last.tdf \
report.csv report-last.csv report-tdf.tdf \
id3v20A trackB id3v1A trackA \
Expand Down Expand Up @@ -37,7 +37,7 @@ TESTS = $(check_PROGRAMS) test-split test-rename test-report test-report-tdf \
test-cleanup-encoded-by test-cleanup-from-audacity \
test-tagsets-from-scheme test-frames-from-scheme test-scripting \
test-options test-popm test-xtag test-text test-genre test-m3u \
test-snarfed-in-scribbu
test-snarfed-in-scribbu test-display
unit_SOURCES = unit.cc unit.hh charsets.cc ostream.cc id3v1.cc framesv2.cc \
framesv22.cc framesv23.cc framesv24.cc id3v2.cc id3v22.cc id3v23.cc \
id3v24.cc id3v2-utils.cc pprinter.cc csv-pprinter.cc mp3.cc tdf-pprinter.cc \
Expand Down
4 changes: 2 additions & 2 deletions test/test-cleanup-encoded-by.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ This function is for testing & debugging purposes. It will simply print the trac
path, the ID3v1 comment (if any) and the ID3v2 TENC frame (if any)."
(format #t "~s: " pth)
(if (null? v1)
(display "<no ID3v1 match>")
(format #t "ID3v1 comment: ~s" (slot-ref v1 'comment)))
(display "<no ID3v1 match> ")
(format #t "ID3v1 comment: ~s " (slot-ref v1 'comment)))
(while (not (null? tags))
(let ((tag (caar tags)))
(format #t "tag ~a" tag)
Expand Down
22 changes: 22 additions & 0 deletions test/test-display
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
export GUILE_AUTO_COMPILE=0

eval "$(../src/scribbu -L ${srcdir}/../scheme -s ${srcdir}/test-display.scm ${srcdir} \
2> >(t_err=$(cat); typeset -p t_err) \
> >(t_std=$(cat); typeset -p t_std) )"
t_stat=$?
# echo "$t_std"
t_err=$(echo "$t_err" | grep -vE ';;; note: source file .*test-display.scm' | grep -v ';;; note: source file .*scribbu.scm' | grep -v 'newer than compiled')
if [ ! -z "$t_err" ]; then
printf '=%.0s' $(seq 1 $cols)
echo "$t_err"
printf '=%.0s' $(seq 1 $cols)
exit 1
fi

output=$(echo $t_std|tr \\n :)
if [ "$output" != "<id3v1-tag Sinead O'Connor - Easter Rebellion (Performed by> <id3v2-tag The Pogues - Lorca's Novena (335921 bytes padding)>:" ]; then
echo $output
exit 1
fi

42 changes: 42 additions & 0 deletions test/test-display.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;;;; test-display.scm
;;;;
;;;; Copyright (C) 2023 Michael Herstine <sp1ff@pobox.com>
;;;;
;;;; This file is part of scribbu.
;;;;
;;;; scribbu 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 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; scribbu is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with scribbu. If not, see <http://www.gnu.org/licenses/>.;;;;
;;;;
;;;;


(use-modules (scribbu))
(use-modules (oop goops))

(setlocale LC_ALL "en_US.UTF-8")


(define (main srcdir)
"Exercise pretty-printing tags."
(let ((tag (read-id3v1-tag (format #f "~a/data/elliot-goldenthal.id3v1.tag" srcdir))))
(format (current-output-port) "~a\n" tag))
(let ((tag (caar (read-tagset (format #f "~a/data/lorca.mp3" srcdir)))))
(format (current-output-port) "~a\n" tag)))


(let ((cl (cdr (command-line))))
(if (= 1 (length cl))
(main (car cl))
(begin
(format #t "Usage: test-display.scm ${srcdir}\n")
(exit 2))))

0 comments on commit a4ccd02

Please sign in to comment.