taglib-tests.lisp 2.3 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))
  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 (mp4-file:make-mp4-file file t))
  30. (when foo (base-file:close-audio-file 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 (mp3-file:make-mp3-file file t))
  44. (when foo (base-file:close-audio-file 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. (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)))
  59. (if (has-extension f "m4a")
  60. (let ((file (mp4-test0 f)))
  61. (when file (mp4-tag:show-tags file))))))))