1
0
Эх сурвалжийг харах

add publisher and country to album

Innocenty Enikeew 7 жил өмнө
parent
commit
5c5e6268cf
3 өөрчлөгдсөн 58 нэмэгдсэн , 33 устгасан
  1. 11 5
      db.lisp
  2. 31 27
      server.lisp
  3. 16 1
      utils.lisp

+ 11 - 5
db.lisp

@@ -2,8 +2,8 @@
 (defpackage chad-music.db
   (:use :cl #:audio-streams #:alexandria #:chad-music.utils)
   (:export #:*standard-optimize-settings*
-           #:album #:id #:artist #:year #:album #:original-date #:genre #:type #:status #:mb-id #:track-count #:total-duration #:cover
-           #:make-album #:album-id #:album-artist #:album-year #:album-album #:album-original-date
+           #:album #:id #:artist #:year #:album #:original-date #:publisher #:country #:genre #:type #:status #:mb-id #:track-count #:total-duration #:cover
+           #:make-album #:album-id #:album-artist #:album-year #:album-album #:album-original-date #:album-publisher #:album-country
            #:album-genre #:album-type #:album-status #:album-mb-id #:album-track-count #:album-total-duration #:album-cover
            #:track #:no #:title #:part-of-set #:bit-rate #:is-vbr #:duration #:path
            #:make-track #:track-album #:track-artist #:track-no #:track-title #:track-part-of-set
@@ -16,7 +16,7 @@
 (in-package :chad-music.db)
 
 (defstruct album
-  id artist year album original-date
+  id artist year album original-date publisher country
   genre type status mb-id track-count total-duration cover)
 
 (defstruct track
@@ -53,6 +53,8 @@
                          :year year
                          :album album-title
                          :original-date (abstract-tag:original-date it)
+                         :publisher (publisher it)
+                         :country (country it)
                          :genre (abstract-tag::genre it)
                          :type (utils:awhen (text-tag it "MusicBrainz Album Type") (string-downcase utils:it))
                          :status (utils:awhen (text-tag it "MusicBrainz Album Status") (string-downcase utils:it))
@@ -66,7 +68,7 @@
            :part-of-set (abstract-tag::disk it)
            :bit-rate (bit-rate it)
            :is-vbr (is-vbr it)
-           :duration (round (duration it))
+           :duration (round (or (duration it) 0))
            :path file))))))
 
 (defun rescan (paths &optional (dbs (cons (make-hash-table :test 'equal) (make-hash-table :test 'equal))))
@@ -178,7 +180,11 @@
                    (declare (simple-string word))
                    (case category
                      (album (or (search word (the simple-string (album-album data)) :test 'char-equal)
-                                (search word (the simple-string (album-artist data)) :test 'char-equal)))
+                                (search word (the simple-string (album-artist data)) :test 'char-equal)
+                                (and (album-publisher data)
+                                     (search word (the simple-string (album-publisher data)) :test 'char-equal))
+                                (and (album-country data)
+                                     (search word (the simple-string (album-country data)) :test 'char-equal))))
                      (year (or (and (album-year data)
                                     (search word (princ-to-string (the fixnum (album-year data))) :test 'char-equal))
                                (and (album-original-date data)

+ 31 - 27
server.lisp

@@ -14,38 +14,42 @@
       (loop for (path-prefix . url-prefix) in *path-url-mappings*
          do (multiple-value-bind (foundp suffix) (starts-with-subseq path-prefix path :return-suffix t)
               (when foundp
-                (return-from get-url (concatenate 'string url-prefix suffix))))))))
+                (return-from get-url (concatenate 'string url-prefix
+                                                  (format nil "~{~A~^/~}"
+                                                          (mapcar #'quri:url-encode
+                                                                  (split-sequence:split-sequence #\/ suffix)))))))))))
 
-(declaim (inline js-null))
-(defun js-null (obj)
-  (if obj obj
-      :null))
+(defmacro maybe-key-value (key value)
+  `(when ,value
+     (write-key-value ,key ,value)))
 
 (defmethod %to-json ((album album))
   (with-object
-    (write-key-value "id" (js-null (album-id album)))
-    (write-key-value "artist" (js-null (album-artist album)))
-    (write-key-value "year" (js-null (album-year album)))
-    (write-key-value "album" (js-null (album-album album)))
-    (write-key-value "original_date" (js-null (album-original-date album)))
-    (write-key-value "genre" (js-null (album-genre album)))
-    (write-key-value "type" (js-null (album-type album)))
-    (write-key-value "status" (js-null (album-status album)))
-    (write-key-value "mb_id" (js-null (album-mb-id album)))
-    (write-key-value "track_count" (js-null (album-track-count album)))
-    (write-key-value "total_duration" (js-null (album-total-duration album)))
-    (write-key-value "cover" (js-null (get-url (album-cover album))))))
+    (maybe-key-value "id" (album-id album))
+    (maybe-key-value "artist" (album-artist album))
+    (maybe-key-value "year" (album-year album))
+    (maybe-key-value "album" (album-album album))
+    (maybe-key-value "original_date" (album-original-date album))
+    (maybe-key-value "publisher" (album-publisher album))
+    (maybe-key-value "country" (album-country album))
+    (maybe-key-value "genre" (album-genre album))
+    (maybe-key-value "type" (album-type album))
+    (maybe-key-value "status" (album-status album))
+    (maybe-key-value "mb_id" (album-mb-id album))
+    (maybe-key-value "track_count" (album-track-count album))
+    (maybe-key-value "total_duration" (album-total-duration album))
+    (maybe-key-value "cover" (get-url (album-cover album)))))
 
 (defmethod %to-json ((track track))
   (with-object
-    (write-key-value "artist" (js-null (track-artist track)))
-    (write-key-value "album" (js-null (album-album (track-album track))))
-    (write-key-value "no" (js-null (clear-track-no (track-no track))))
-    (write-key-value "title" (js-null (track-title track)))
-    (write-key-value "bit_rate" (js-null (track-bit-rate track)))
-    (write-key-value "vbr" (if (track-is-vbr track) :true :false))
-    (write-key-value "duration" (js-null (track-duration track)))
-    (write-key-value "url" (js-null (get-url (track-path track))))))
+    (maybe-key-value "artist" (track-artist track))
+    (maybe-key-value "album" (album-album (track-album track)))
+    (maybe-key-value "no" (clear-track-no (track-no track)))
+    (maybe-key-value "title" (track-title track))
+    (maybe-key-value "bit_rate" (track-bit-rate track))
+    (maybe-key-value "vbr" (if (track-is-vbr track) :true :false))
+    (maybe-key-value "duration" (track-duration track))
+    (maybe-key-value "url" (get-url (track-path track)))))
 
 (defparameter +400+ '(400 nil #.(trivial-utf-8:string-to-utf-8-bytes "400")))
 (defparameter +404+ '(404 nil #.(trivial-utf-8:string-to-utf-8-bytes "404")))
@@ -60,7 +64,7 @@
 (defun get-category-list (params)
   (declare #.*standard-optimize-settings*
            (ignore params))
-  (200-json '("artist" "year" "album" "genre" "type" "status")))
+  (200-json '("artist" "year" "album" "publisher" "country" "genre" "type" "status")))
 
 (let ((db-package (find-package :chad-music.db)))
   (defun getsym (place indicator)
@@ -85,7 +89,7 @@
 (defun get-restrictions (query-params)
   (declare #.*standard-optimize-settings*
            (type list query-params))
-  (loop for key in '(artist year album genre type status)
+  (loop for key in '(artist year album publisher country genre type status)
      for value = (aget query-params (string-downcase (symbol-name key)))
      when value collect (cons key (case key
                                     (year (parse-integer value :junk-allowed t))

+ 16 - 1
utils.lisp

@@ -5,7 +5,9 @@
            #:text-tag
            #:bit-rate
            #:is-vbr
-           #:duration))
+           #:duration
+           #:publisher
+           #:country))
 (in-package :chad-music.utils)
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
@@ -25,6 +27,8 @@
 (defgeneric bit-rate (stream) (:method ((object t)) nil))
 (defgeneric is-vbr (stream) (:method ((object t)) nil))
 (defgeneric duration (stream) (:method ((object t)) nil))
+(defgeneric publisher (stream) (:method ((object t)) nil))
+(defgeneric country (stream) (:method ((object t)) nil))
 (defmethod bit-rate ((mp3 id3:mp3-file))
   (let ((info (id3:audio-info mp3)))
     (when info
@@ -40,6 +44,17 @@
     (when info
       (mpeg::len info))))
 
+(defmethod publisher ((mp3 id3:mp3-file))
+  (declare #.utils:*standard-optimize-settings*)
+
+  (let ((frames (id3:get-frames mp3 '("TPUB" "TPB"))))
+    (when frames
+      (return-from publisher (id3:info (first frames)))))
+  nil)
+
+(defmethod country ((mp3 id3:mp3-file))
+  (text-tag mp3 "MusicBrainz Album Release Country"))
+
 (defmethod bit-rate ((m4a m4a:mp4-file))
   (let ((info (m4a:audio-info m4a)))
     (when info