|
@@ -2,6 +2,7 @@
|
|
|
(defpackage chad-music.db
|
|
(defpackage chad-music.db
|
|
|
(:use :cl #:audio-streams #:alexandria #:chad-music.utils)
|
|
(:use :cl #:audio-streams #:alexandria #:chad-music.utils)
|
|
|
(:export #:*standard-optimize-settings*
|
|
(:export #:*standard-optimize-settings*
|
|
|
|
|
+ #:*db-path*
|
|
|
#:*db*
|
|
#:*db*
|
|
|
#:album #:id #:artist #:year #:album #:original-date #:publisher #:country #:genre #:type #:status #:mb-id #:track-count #:total-duration #:cover
|
|
#: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
|
|
#:make-album #:album-id #:album-artist #:album-year #:album-album #:album-original-date #:album-publisher #:album-country
|
|
@@ -23,6 +24,7 @@
|
|
|
(album-tracks (make-hash-table :test 'equal) :type hash-table))
|
|
(album-tracks (make-hash-table :test 'equal) :type hash-table))
|
|
|
|
|
|
|
|
(defvar *db* (make-db) "Metadata database")
|
|
(defvar *db* (make-db) "Metadata database")
|
|
|
|
|
+(defvar *db-path* "music.sexp" "Default file to save/load database")
|
|
|
|
|
|
|
|
(defstruct album
|
|
(defstruct album
|
|
|
id artist year album original-date publisher country
|
|
id artist year album original-date publisher country
|
|
@@ -293,7 +295,7 @@
|
|
|
(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 save-db (file-name)
|
|
|
|
|
|
|
+(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)
|
|
|
(labels ((print-values (table)
|
|
(labels ((print-values (table)
|
|
@@ -302,7 +304,7 @@
|
|
|
(print-values (db-albums *db*))
|
|
(print-values (db-albums *db*))
|
|
|
(print-values (db-tracks *db*)))))
|
|
(print-values (db-tracks *db*)))))
|
|
|
|
|
|
|
|
-(defun load-db (file-name)
|
|
|
|
|
|
|
+(defun load-db (&optional (file-name *db-path*))
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|
|
|
(with-input-from-file (s file-name)
|
|
(with-input-from-file (s file-name)
|
|
|
(let ((albums (make-hash-table :test 'equal))
|
|
(let ((albums (make-hash-table :test 'equal))
|