Innocenty Enikeew il y a 7 ans
Parent
commit
7e60ab1575
4 fichiers modifiés avec 19 ajouts et 23 suppressions
  1. 11 15
      abstract-tag.lisp
  2. 5 6
      audio-streams.lisp
  3. 2 1
      packages.lisp
  4. 1 1
      utils.lisp

+ 11 - 15
abstract-tag.lisp

@@ -75,6 +75,7 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 (defgeneric title (stream))
 (defgeneric writer (stream))
 (defgeneric year (stream))
+(defgeneric original-date (stream) (:method ((object t)) nil))
 
 (defgeneric show-tags (file &key &allow-other-keys))
 
@@ -92,9 +93,8 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 (defmethod album ((me id3:mp3-file))
   (declare #.utils:*standard-optimize-settings*)
 
-  (let ((frames (id3:get-frames me '("TAL" "TALB"))))
+  (let ((frames (id3:get-frames me '("TALB" "TAL"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one album tag")
       (return-from album (id3:info (first frames)))))
   (if (id3:v21-tag-header (id3:id3-header me))
       (id3:album (id3:v21-tag-header (id3:id3-header me)))
@@ -105,7 +105,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TP1" "TPE1"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one artist tag")
       (return-from artist (id3:info (first frames)))))
   (if (id3:v21-tag-header (id3:id3-header me))
       (id3:artist (id3:v21-tag-header (id3:id3-header me)))
@@ -132,7 +131,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TRD" "TDRC"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one year tag")
       (return-from year (id3:info (first frames)))))
   (if (id3:v21-tag-header (id3:id3-header me))
       (id3:year (id3:v21-tag-header (id3:id3-header me)))
@@ -143,7 +141,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TT2" "TIT2"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one title tag")
       (return-from title (id3:info (first frames)))))
   (if (id3:v21-tag-header (id3:id3-header me))
       (id3:title (id3:v21-tag-header (id3:id3-header me)))
@@ -190,7 +187,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TP2" "TPE2"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one album-artist tag")
       (return-from album-artist (id3:info (first frames)))))
   nil)
 
@@ -199,7 +195,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TCM" "TCOM"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one composer tag")
       (return-from composer (id3:info (first frames)))))
   nil)
 
@@ -208,7 +203,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TCR" "TCOP"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one copyright tag")
       (return-from copyright (id3:info (first frames)))))
   nil)
 
@@ -217,7 +211,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TEN" "TENC"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one encoder tag")
       (return-from encoder (id3:info (first frames)))))
   nil)
 
@@ -226,7 +219,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TT1" "TTE1"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one group tag")
       (return-from groups (id3:info (first frames)))))
   nil)
 
@@ -235,7 +227,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("ULT" "USLT"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one lyrics tag")
       (return-from lyrics (id3:val (first frames)))))
   nil)
 
@@ -244,7 +235,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TCM" "TCOM"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one composer tag")
       (return-from writer (id3:info (first frames)))))
   nil)
 
@@ -261,7 +251,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TPA" "TPOS"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one disk number tag")
       (return-from disk (mk-lst (id3:info (first frames))))))
   nil)
 
@@ -270,7 +259,6 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TBP" "TBPM"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one tempo tag")
       (return-from tempo (id3:info (first frames)))))
   nil)
 
@@ -288,10 +276,18 @@ is > 0 and < (sizeof *ID3V1-GENRES*)"
 
   (let ((frames (id3:get-frames me '("TRK" "TRCK"))))
     (when frames
-      (assert (= 1 (length frames)) () "There can be only one track number tag")
       (return-from track (mk-lst (id3:info (first frames))))))
   nil)
 
+
+(defmethod original-date ((me id3:mp3-file))
+  (declare #.utils:*standard-optimize-settings*)
+
+  (let ((frames (id3:get-frames me '("TDOR" "TORY" "TOR"))))
+    (when frames
+      (return-from original-date (id3:info (first frames)))))
+  nil)
+
 (defmethod show-tags ((me id3:mp3-file) &key (raw *raw-tags*))
   "Show the tags for an MP3.  If RAW is non-nil, dump all the frames;
 else, print out a subset."

+ 5 - 6
audio-streams.lisp

@@ -142,7 +142,7 @@ read in null-terminated ISO string w/o null at end"
     (when (= 0 len)
       (return-from stream-read-iso-string ""))
 
-    (flex:octets-to-string octets :external-format :iso-8859-1)))
+    (delete #\nul (flex:octets-to-string octets :external-format :iso-8859-1) :from-end t)))
 
 (defun get-byte-order-mark (octets)
   "Get the BOM from octets"
@@ -169,7 +169,7 @@ byte-order marks, so we have to do that here before calling."
 
     (if (null len)
         (progn
-          (setf octets (flex:with-output-to-sequence (out)
+          (setf octets (flex:with-output-to-sequence (out :element-type 'octet)
                          (do* ((b0 (stream-read-u8 instream)
                                    (stream-read-u8 instream))
                                (b1 (stream-read-u8 instream)
@@ -192,7 +192,7 @@ byte-order marks, so we have to do that here before calling."
                    *current-file*))
       (decf len 1))
 
-    (when (<= 0 len)
+    (when (<= len 0)
       (return-from stream-read-ucs-string ""))
 
     (when (eql kind :ucs-2)
@@ -201,8 +201,7 @@ byte-order marks, so we have to do that here before calling."
         (ecase bom
           (#xfffe (setf kind :ucs-2le))
           (#xfeff (setf kind :ucs-2be)))))
-
-    (flex:octets-to-string octets :external-format kind :start start :end len)))
+    (delete #\Nul (flex:octets-to-string octets :external-format kind :start start :end len))))
 
 (defun stream-read-utf-8-string (instream &optional (len nil))
   "Read an UTF-8 string of length LEN.  If LEN is nil, read until we get a null."
@@ -224,7 +223,7 @@ byte-order marks, so we have to do that here before calling."
     (when (= 0 len)
       (return-from stream-read-utf-8-string ""))
 
-    (flex:octets-to-string octets :external-format :utf-8)))
+    (delete #\Nul (flex:octets-to-string octets :external-format :utf-8))))
 
 
 ;;;; Files

+ 2 - 1
packages.lisp

@@ -150,7 +150,8 @@
            #:*raw-tags*
            #:title
            #:show-tags
-           #:writer)
+           #:writer
+           #:original-date)
   (:use #:common-lisp #:audio-streams #:utils))
 
 (defpackage #:mpeg

+ 1 - 1
utils.lisp

@@ -89,7 +89,7 @@ The macro expansion has relatively low overhead in space or time."
 
   (let* ((len (length array))
          (print-len (min len max-len))
-         (printable-array (make-array print-len :displaced-to array)))
+         (printable-array (make-array print-len :element-type (array-element-type array) :displaced-to array)))
 
     (declare (fixnum max-len len))
     (format nil "[~:d of ~:d bytes] <~a>" print-len len printable-array)))