taglib-tests.lisp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ;;; -*- Mode: Lisp; show-trailing-whitespace: t; Base: 10; indent-tabs: nil; Syntax: ANSI-Common-Lisp; Package: TAGLIB-TESTS; -*-
  2. ;;; Copyright (c) 2013, Mark VandenBrink. All rights reserved.
  3. (in-package #:cl-user)
  4. (defpackage #:taglib-tests
  5. (:use #:common-lisp #:logging #:audio-streams))
  6. (in-package #:taglib-tests)
  7. (defparameter *song-m4a* "01 Keep Yourself Alive.m4a")
  8. (defparameter *song-mp3* "02 You Take My Breath Away.mp3")
  9. (defmethod has-extension ((n string) ext)
  10. (has-extension (parse-namestring n) ext))
  11. (defmethod has-extension ((p pathname) ext)
  12. (let ((e (pathname-type p)))
  13. (if e
  14. (string= (string-downcase e) (string-downcase ext))
  15. nil)))
  16. (defmacro redirect (filename &rest body)
  17. `(let ((*standard-output* (open ,filename :direction :output :if-does-not-exist :create :if-exists :overwrite)))
  18. ,@body))
  19. ;;; A note re filesystem encoding: my music collection is housed on a Mac and shared via SAMBA.
  20. ;;; In order to make sure we get valid pathnames, we need to set CCL's filesystem encoding to
  21. ;;; :UTF-8
  22. ;;;;;;;;;;;;;;;;;;;; MP4 Tests ;;;;;;;;;;;;;;;;;;;;
  23. (defun mp4-test0 (file)
  24. (let (foo)
  25. (unwind-protect
  26. (setf foo (parse-mp4-file file))
  27. (when foo (stream-close foo)))
  28. foo))
  29. (defun mp4-test1 ()
  30. (mp4-test0 *song-m4a*))
  31. (defun mp4-test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  32. (let ((ccl:pathname-encoding-name file-system-encoding))
  33. (osicat:walk-directory dir (lambda (f)
  34. (when (has-extension f "m4a")
  35. (let ((file (mp4-test0 f)))
  36. (when file (mp4-tag:show-tags file :raw raw))))))))
  37. ;;;;;;;;;;;;;;;;;;;; MP3 Tests ;;;;;;;;;;;;;;;;;;;;
  38. (defun mp3-test0 (file)
  39. (let (foo)
  40. (unwind-protect
  41. (setf foo (parse-mp3-file file))
  42. (when foo (stream-close foo)))
  43. foo))
  44. (defun mp3-test1 ()
  45. (mp3-test0 *song-mp3*))
  46. (defun mp3-test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  47. (let ((ccl:pathname-encoding-name file-system-encoding))
  48. (osicat:walk-directory dir (lambda (f)
  49. (when (has-extension f "mp3")
  50. (let ((file (mp3-test0 f)))
  51. (when file (mp3-tag:show-tags file :raw raw))))))))
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. (defun test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  54. (let ((ccl:pathname-encoding-name file-system-encoding))
  55. (osicat:walk-directory dir (lambda (f)
  56. (if (has-extension f "mp3")
  57. (let ((file (mp3-test0 f)))
  58. (when file (mp3-tag:show-tags file :raw raw)))
  59. (if (has-extension f "m4a")
  60. (let ((file (mp4-test0 f)))
  61. (when file (mp4-tag:show-tags file :raw raw)))))))))