taglib-tests.lisp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  44. (mp4-tag:show-tags file :raw raw)
  45. (mp4-atom::get-audio-properties file)))))))
  46. ;;;;;;;;;;;;;;;;;;;; MP3 Tests ;;;;;;;;;;;;;;;;;;;;
  47. (defun mp3-test0 (file)
  48. (let (foo)
  49. (unwind-protect
  50. (setf foo (parse-mp3-file file))
  51. (when foo (stream-close foo)))
  52. foo))
  53. (defun mp3-test1 ()
  54. (mp3-test0 *song-mp3*))
  55. (defun mp3-test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  56. (set-pathname-encoding file-system-encoding)
  57. (osicat:walk-directory dir (lambda (f)
  58. (when (has-extension f "mp3")
  59. (let ((file (mp3-test0 f)))
  60. (when file (mp3-tag:show-tags file :raw raw)))))))
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62. (defun test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
  63. (set-pathname-encoding file-system-encoding)
  64. (osicat:walk-directory dir (lambda (f)
  65. (if (has-extension f "mp3")
  66. (let ((file (mp3-test0 f)))
  67. (when file (mp3-tag:show-tags file :raw raw)))
  68. (if (has-extension f "m4a")
  69. (let ((file (mp4-test0 f)))
  70. (when file (mp4-tag:show-tags file :raw raw))))))))