|
@@ -14,6 +14,7 @@
|
|
|
#:make-entry #:entry-track #:entry-added #:entry-modified #:entry-present
|
|
#:make-entry #:entry-track #:entry-added #:entry-modified #:entry-present
|
|
|
#:get-album-id #:get-file-id #:rescan
|
|
#:get-album-id #:get-file-id #:rescan
|
|
|
#:clear-track-no
|
|
#:clear-track-no
|
|
|
|
|
+ #:db-stats
|
|
|
#:save-db #:load-db
|
|
#:save-db #:load-db
|
|
|
#:query-category #:query-tracks #:album-tracks))
|
|
#:query-category #:query-tracks #:album-tracks))
|
|
|
(in-package :chad-music.db)
|
|
(in-package :chad-music.db)
|
|
@@ -96,7 +97,7 @@
|
|
|
(gethash (track-album-id track)
|
|
(gethash (track-album-id track)
|
|
|
(db-albums *db*)))
|
|
(db-albums *db*)))
|
|
|
|
|
|
|
|
-(defun rescan (paths)
|
|
|
|
|
|
|
+(defun rescan (&optional (paths (mapcar 'car chad-music.server::*path-url-mappings*)))
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|
|
|
|
|
|
|
|
(let ((added 0) (updated 0) (removed 0)
|
|
(let ((added 0) (updated 0) (removed 0)
|
|
@@ -168,7 +169,7 @@
|
|
|
for track = (entry-track entry)
|
|
for track = (entry-track entry)
|
|
|
when track
|
|
when track
|
|
|
do (setf (gethash (track-album-id track) album-added-db) (entry-added entry))
|
|
do (setf (gethash (track-album-id track) album-added-db) (entry-added entry))
|
|
|
- do (push track (gethash (track-album-id track) album-tracks-db)))
|
|
|
|
|
|
|
+ and do (push track (gethash (track-album-id track) album-tracks-db)))
|
|
|
(loop for album-id being the hash-keys in album-tracks-db using (hash-value tracks)
|
|
(loop for album-id being the hash-keys in album-tracks-db using (hash-value tracks)
|
|
|
do (setf (gethash album-id album-tracks-db)
|
|
do (setf (gethash album-id album-tracks-db)
|
|
|
(sort tracks 'track<)))))
|
|
(sort tracks 'track<)))))
|
|
@@ -179,6 +180,7 @@
|
|
|
(car track-no)
|
|
(car track-no)
|
|
|
track-no)))
|
|
track-no)))
|
|
|
(etypecase track
|
|
(etypecase track
|
|
|
|
|
+ (null nil)
|
|
|
(integer track)
|
|
(integer track)
|
|
|
(string (parse-integer track :junk-allowed t))))))
|
|
(string (parse-integer track :junk-allowed t))))))
|
|
|
|
|
|
|
@@ -310,6 +312,20 @@
|
|
|
(defun album-tracks (album-id)
|
|
(defun album-tracks (album-id)
|
|
|
(gethash album-id (db-album-tracks *db*)))
|
|
(gethash album-id (db-album-tracks *db*)))
|
|
|
|
|
|
|
|
|
|
+(defun db-stats ()
|
|
|
|
|
+ (declare #.*standard-optimize-settings*)
|
|
|
|
|
+ (let ((albums (db-albums *db*))
|
|
|
|
|
+ (artists (make-hash-table :test 'equal)))
|
|
|
|
|
+ (loop for entry being the hash-values in albums
|
|
|
|
|
+ summing (album-total-duration entry) into total-duration
|
|
|
|
|
+ summing (album-track-count entry) into total-tracks
|
|
|
|
|
+ counting t into total-albums
|
|
|
|
|
+ do (setf (gethash (album-artist entry) artists) t)
|
|
|
|
|
+ finally (return (list :|artists| (hash-table-count artists)
|
|
|
|
|
+ :|albums| total-albums
|
|
|
|
|
+ :|tracks| total-tracks
|
|
|
|
|
+ :|duration| total-duration)))))
|
|
|
|
|
+
|
|
|
(defun save-db (&optional (file-name *db-path*))
|
|
(defun save-db (&optional (file-name *db-path*))
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|
|
|
(with-output-to-file (s file-name :if-exists :supersede)
|
|
(with-output-to-file (s file-name :if-exists :supersede)
|