Procházet zdrojové kódy

documentation, cleanup, etc

Mark VandenBrink před 12 roky
rodič
revize
0c4935dcb9
7 změnil soubory, kde provedl 46 přidání a 37 odebrání
  1. 16 1
      README.md
  2. 0 4
      audio-streams.lisp
  3. 0 3
      logging.lisp
  4. 7 6
      mp3-tag.lisp
  5. 1 1
      mp4-atom.lisp
  6. 16 19
      taglib-tests.lisp
  7. 6 3
      utils.lisp

+ 16 - 1
README.md

@@ -20,7 +20,7 @@ Notes II:
 * The parsing of MP3 audio properties (mpeg.lisp) is far from complete, especially when dealing with odd case WRT Xing headers.
 * I've parsed just enough of the MP4 atoms/boxes to suit the needs of this tool.  l-smash appears to parse all boxes.  Maybe one day this lib will too.
 * WRT error handling: in some cases, I've made them recoverable, but in general, I've went down the path of erroring out when
-  I get problems.
+  I get problems. 
 * I've run this tool across my 19,000+ audio collection and compared the results to some of the tools above, with little to no variations.
   That said, I have a pretty uniform collection, mostly from ripping CDs, then iTunes purchases/matched, and the Amazon matched. YMMV
 
@@ -79,4 +79,19 @@ Header: version/revision: 3/0, flags: 0x00: 0/0/0/0, size = 11,899 bytes; No ext
         frame-txxx: flags: 0x0000: 0/0/0/0/0/0, offset: 136, version = 3, id: TXXX, len: 33, NIL, <Tagging time/2013-08-08T16:38:38>
 ```
 
+I also have a semi-complete logging strategy in place.  Logging is based on LOG5 package.
+
+To see the ouput of ALL logging statements to *STANDARD-OUTPUT*, you can do the following:
+
+```
+(with-logging () (taglib-tests::test2))
+```
+
+To see only the MP4-ATOM related logging stuff and redirect logging to to a file called "foo.txt":
+
+```
+(with-logging (:file "foo.txt" (categories '(mp4-atom::cat-log-mp4-atom))) (taglib-tests::test2))
+```
+
+See *logging.lisp* for more info.
 

+ 0 - 4
audio-streams.lisp

@@ -77,10 +77,6 @@ Thus (stream-seek in) == (stream-seek in 0 :current)"
                     (ccl::stream-position stream (+ (ccl::stream-position stream) offset))))
       (:end (ccl::stream-position stream (- (ccl::stream-length stream) offset))))))
 
-;; (defmethod stream-seek ((in-stream base-stream))
-;;   "Short hand for getting current stream read position"
-;;   (stream-seek in-stream 0 :current))
-
 (defun stream-read-octets (instream bytes &key (bits-per-byte 8))
   "Used to slurp in octets for the stream-read-* methods"
   (loop with value = 0

+ 0 - 3
logging.lisp

@@ -13,13 +13,11 @@
           ,@body)
      (log5:stop-sender 'trace-log)))
 
-
 (defparameter *logging-categories* '(mp4-atom::cat-log-mp4-atom
                                      audio-streams::cat-log-stream
                                      mpeg::cat-log-mpeg-frame
                                      id3-frame::cat-log-id3-frame))
 
-
 (defmacro with-logging ((&optional file &key (categories *logging-categories*)) &body body)
   (alexandria:with-gensyms (output-stream)
     `(let (,output-stream)
@@ -33,4 +31,3 @@
             ,@body)
        (if ,file (close ,output-stream))
        (log5:stop-sender 'trace-log))))
-

+ 7 - 6
mp3-tag.lisp

@@ -238,11 +238,12 @@
             (str (info (first frames))))
 
         ;; XXX for V23/V24 TCON frames, a genre can be pretty gnarly.
-        ;; if the first byte of the TCON INFO field is a '(', this is interpreted
-        ;; as an ID3v2.1 genre number.  These can stack up (called "refinements") too.
+        ;; if the first byte of the TCON INFO field is a '(', what is between this '('
+        ;; and the next ')' is interpreted as an ID3v2.1 genre number.
+        ;; These can stack up (called "refinements") too.
         ;; The INFO field can also just be a string.
-        ;; We're taking a simplistic approach here: we can hand the '(' case, but
-        ;; only allow one (no refinements) or we can handle the simple string case
+        ;; We're taking a simplistic approach here: we can handle the '(' case, but
+        ;; only allow one (no refinements) OR we can handle the simple string case
         (when (and (>= (length str) 1) (eq #\( (aref str 0)))
           (setf count (count #\( str))
           (when (> count 1) (warn-user "Don't support genre refinement yet, found ~d genres" count))
@@ -343,7 +344,7 @@
 (defmethod show-tags ((me mp3-file-stream) &key (raw nil))
   "Show the tags for an mp3-file.  If RAW is non-nil, dump all the frames; else, print out a subset."
   (if raw
-      (format t "~a: ~a~%" (stream-filename me)
+      (format t "~a~%~a~%" (stream-filename me)
               (with-output-to-string (s)
                 (when (audio-info me)
                   (mpeg::vpprint (audio-info me) s)
@@ -366,7 +367,7 @@
             (track (track me))
             (writer (writer me))
             (year (year me)))
-        (format t "~a: ~a~%" (stream-filename me)
+        (format t "~a~%~a~%" (stream-filename me)
                 (if (audio-info me)
                     (mpeg::vpprint (audio-info me) nil) ""))
         (when album (format t "~4talbum: ~a~%" album))

+ 1 - 1
mp4-atom.lisp

@@ -466,7 +466,7 @@ Loop through this container and construct constituent atoms"
       (log-mp4-atom "make-mp4-atom: @ pos = ~:d of size = ~:d and type = ~a" pos siz (as-string typ))
 
       (when (= 0 siz)
-        (error "trying to make an atom ~a with size of 0 at offset ~:d in ~a, ammending size to be 8"
+        (error "trying to make an atom ~a with size of 0 at offset ~:d in file ~a"
                (as-string typ) pos (stream-filename mp4-file)))
 
       (setf atom (make-instance (find-atom-class typ) :atom-size siz :atom-type typ :atom-file-position pos :mp4-file mp4-file :atom-parent-type parent-type))

+ 16 - 19
taglib-tests.lisp

@@ -10,12 +10,6 @@
 (defparameter *song-m4a* "01 Keep Yourself Alive.m4a"     "handy filename to test MP4s")
 (defparameter *song-mp3* "02 You Take My Breath Away.mp3" "handy filename to test MP3s")
 
-(defun report-error (format-string &rest args)
-  "Used in the mpX-testX functions below to show errors found to user."
-  (format *error-output* "~&****************************************~%")
-  (apply #'format *error-output* format-string args)
-  (format *error-output* "****************************************~%"))
-
 ;;;
 ;;; Set the pathname (aka filename) encoding in CCL for appropriate platorm
 (defun set-pathname-encoding (enc)        (setf (ccl:pathname-encoding-name) enc))
@@ -54,7 +48,7 @@ to see if it matches. PATHNAME version."
          (handler-case
              (setf foo (parse-mp4-file file))
            (condition (c)
-             (report-error "Dir: ~a~%File: ~a~%Got condition: <~a>~%" dir file c)))
+             (utils:warn-user "Dir: ~a~%File: ~a~%Got condition: <~a>~%" dir file c)))
       (when foo (stream-close foo)))
     foo))
 
@@ -66,10 +60,9 @@ to see if it matches. PATHNAME version."
   (set-pathname-encoding file-system-encoding)
   (osicat:walk-directory dir (lambda (f)
                                (when (has-extension f "m4a")
-                                 (let ((file (mp4-test0 f)))
+                                 (let ((file (mp4-test0 (merge-pathnames (ccl:current-directory) (pathname f)))))
                                    (when file
-                                     (mp4-tag:show-tags file :raw raw)
-                                     (mp4-atom::get-mp4-audio-info file)))))))
+                                     (mp4-tag:show-tags file :raw raw)))))))
 
 ;;;;;;;;;;;;;;;;;;;; MP3 Tests ;;;;;;;;;;;;;;;;;;;;
 (defun mp3-test0 (file)
@@ -80,7 +73,7 @@ to see if it matches. PATHNAME version."
          (handler-case
              (setf foo (parse-mp3-file file))
            (condition (c)
-             (report-error "Dir: ~a~%File: ~a~%Got condition: <~a>~%" dir file c)))
+             (utils:warn-user "Dir: ~a~%File: ~a~%Got condition: <~a>~%" dir file c)))
       (when foo (stream-close foo)))
     foo))
 
@@ -92,17 +85,21 @@ to see if it matches. PATHNAME version."
   (set-pathname-encoding file-system-encoding)
   (osicat:walk-directory dir (lambda (f)
                                (when (has-extension f "mp3")
-                                 (let ((file (mp3-test0 f)))
-                                   (when file (mp3-tag:show-tags file :raw raw)))))))
+                                 (let ((file (mp3-test0 (merge-pathnames (ccl:current-directory) (pathname f)))))
+                                   (when file
+                                     (mp3-tag:show-tags file :raw raw)))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun test2 (&key (dir "Queen") (raw nil) (file-system-encoding :utf-8))
   "Walk :DIR and call SHOW-TAGS for each file (MP4/MP3) found."
   (set-pathname-encoding file-system-encoding)
   (osicat:walk-directory dir (lambda (f)
-                               (if (has-extension f "mp3")
-                                   (let ((file (mp3-test0 f)))
-                                     (when file (mp3-tag:show-tags file :raw raw)))
-                                   (if (has-extension f "m4a")
-                                       (let ((file (mp4-test0 f)))
-                                         (when file (mp4-tag:show-tags file :raw raw))))))))
+                               (let ((full-name (merge-pathnames (ccl:current-directory) (pathname f))))
+                                 (cond ((has-extension f "mp3")
+                                        (let ((file (mp3-test0 full-name)))
+                                          (when file
+                                            (mp3-tag:show-tags file :raw raw))))
+                                       ((has-extension f "m4a")
+                                        (let ((file (mp4-test0 full-name)))
+                                          (when file
+                                            (mp4-tag:show-tags file :raw raw)))))))))

+ 6 - 3
utils.lisp

@@ -5,14 +5,17 @@
 (defun warn-user (format-string &rest args)
   "print a warning error to *ERROR-OUTPUT* and continue"
   ;; COMPLETELY UNPORTABLE!!!
+  (format *error-output* "~&****************************************~%")
   (format *error-output* "~&~&WARNING in ~a:: " (ccl::%last-fn-on-stack 1))
   (apply #'format *error-output* format-string args)
-  (format *error-output* "~%~%"))
+  (format *error-output* "~%~%")
+  (format *error-output* "****************************************~%"))
 
-(defparameter *max-raw-bytes-print-len* 10)
+
+(defparameter *max-raw-bytes-print-len* 10 "Max number of octets to print from an array")
 
 (defun printable-array (array)
-  "given an array, return a string of the first *MAX-RAW-BYTES-PRINT-LEN* bytes"
+  "Given an array, return a string of the first *MAX-RAW-BYTES-PRINT-LEN* bytes"
   (let* ((len (length array))
          (print-len (min len *max-raw-bytes-print-len*))
          (printable-array (make-array print-len :displaced-to array)))