taglib-tests.lisp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. (defun set-pathname-encoding (enc)
  10. (setf (ccl:pathname-encoding-name) enc))
  11. (defun set-pathname-encoding-for-osx ()
  12. (set-pathname-encoding :utf-8))
  13. (defun set-pathname-encoding-for-linux ()
  14. (set-pathname-encoding nil))
  15. (defmethod has-extension ((n string) ext)
  16. (has-extension (parse-namestring n) ext))
  17. (defmethod has-extension ((p pathname) ext)
  18. (let ((e (pathname-type p)))
  19. (if e
  20. (string= (string-downcase e) (string-downcase ext))
  21. nil)))
  22. (defmacro redirect ((filename) &rest body)
  23. `(let ((*standard-output* (open ,filename :direction :output :if-does-not-exist :create :if-exists :supersede)))
  24. ,@body
  25. (finish-output *standard-output*)))
  26. ;;; A note re filesystem encoding: my music collection is housed on a Mac and shared via SAMBA.
  27. ;;; In order to make sure we get valid pathnames, we need to set CCL's filesystem encoding to
  28. ;;; :UTF-8
  29. ;;;;;;;;;;;;;;;;;;;; MP4 Tests ;;;;;;;;;;;;;;;;;;;;
  30. (defun mp4-test0 (file)
  31. (let (foo)
  32. (unwind-protect
  33. (setf foo (parse-mp4-file file))
  34. (when foo (stream-close foo)))
  35. foo))
  36. (defun mp4-test1 ()
  37. (mp4-test0 *song-m4a*))
  38. (defun mp4-test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  39. (set-pathname-encoding file-system-encoding)
  40. (osicat:walk-directory dir (lambda (f)
  41. (when (has-extension f "m4a")
  42. (let ((file (mp4-test0 f)))
  43. (when file (mp4-tag:show-tags file :raw raw)))))))
  44. ;;;;;;;;;;;;;;;;;;;; MP3 Tests ;;;;;;;;;;;;;;;;;;;;
  45. (defun mp3-test0 (file)
  46. (let (foo)
  47. (unwind-protect
  48. (setf foo (parse-mp3-file file))
  49. (when foo (stream-close foo)))
  50. foo))
  51. (defun mp3-test1 ()
  52. (mp3-test0 *song-mp3*))
  53. (defun mp3-test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  54. (set-pathname-encoding file-system-encoding)
  55. (osicat:walk-directory dir (lambda (f)
  56. (when (has-extension f "mp3")
  57. (let ((file (mp3-test0 f)))
  58. (when file (mp3-tag:show-tags file :raw raw)))))))
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60. (defun test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  61. (set-pathname-encoding file-system-encoding)
  62. (osicat:walk-directory dir (lambda (f)
  63. (if (has-extension f "mp3")
  64. (let ((file (mp3-test0 f)))
  65. (when file (mp3-tag:show-tags file :raw raw)))
  66. (if (has-extension f "m4a")
  67. (let ((file (mp4-test0 f)))
  68. (when file (mp4-tag:show-tags file :raw raw))))))))