taglib-tests.lisp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 :overwrite)))
  24. ,@body))
  25. ;;;;;;;;;;;;;;;;;;;; MP4 Tests ;;;;;;;;;;;;;;;;;;;;
  26. (defun mp4-test0 (file)
  27. (let (foo)
  28. (unwind-protect
  29. (setf foo (parse-mp4-file file))
  30. (when foo (stream-close foo)))
  31. foo))
  32. (defun mp4-test1 ()
  33. (mp4-test0 *song-m4a*))
  34. (defun mp4-test2 (&key (dir "Queen"))
  35. (osicat:walk-directory dir (lambda (f)
  36. (when (has-extension f "m4a")
  37. (let ((file (mp4-test0 f)))
  38. (when file (mp4-tag:show-tags file)))))))
  39. ;;;;;;;;;;;;;;;;;;;; MP3 Tests ;;;;;;;;;;;;;;;;;;;;
  40. (defun mp3-test0 (file)
  41. (let (foo)
  42. (unwind-protect
  43. (setf foo (parse-mp3-file file))
  44. (when foo (stream-close foo)))
  45. foo))
  46. (defun mp3-test1 ()
  47. (mp3-test0 *song-mp3*))
  48. (defun mp3-test2 (&key (dir "Queen"))
  49. (osicat:walk-directory dir (lambda (f)
  50. (when (has-extension f "mp3")
  51. (let ((file (mp3-test0 f)))
  52. (when file (mp3-tag:show-tags file)))))))
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. (defun test2 (&key (dir "Queen"))
  55. (set-pathname-encoding-for-osx)
  56. (osicat:walk-directory dir (lambda (f)
  57. (if (has-extension f "mp3")
  58. (let ((file (mp3-test0 f)))
  59. (when file (mp3-tag:show-tags file)))
  60. (if (has-extension f "m4a")
  61. (let ((file (mp4-test0 f)))
  62. (when file (mp4-tag:show-tags file))))))))