| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- (in-package :cl-user)
- (defpackage chad-music.test
- (:use :cl #:audio-streams #:alexandria #:chad-music.db))
- (in-package :chad-music.test)
- (defparameter +album-split-slots+ '(artist album))
- (defparameter +album-whole-slots+ '(year genre type status))
- (defun gen-name (elements length)
- (format nil "~{~A~^ ~}" (loop for i below (1+ (random length)) collect (random-elt elements))))
- (defun generate-albums (count albums-db)
- (let ((splits (loop for slot in +album-split-slots+ append (list slot (make-hash-table :test 'equal))))
- (wholes (loop for slot in +album-whole-slots+ append (list slot (make-hash-table :test 'equal))))
- (albums (make-hash-table :test 'equal)))
- (loop for album being the hash-values of albums-db
- do (dolist (slot +album-split-slots+)
- (loop for word in (split-sequence:split-sequence #\Space (slot-value album slot))
- when (> (length word) 1)
- do (setf (gethash word (getf splits slot)) t)))
- do (dolist (slot +album-whole-slots+)
- (setf (gethash (slot-value album slot) (getf wholes slot)) t)))
- (dolist (slot +album-split-slots+)
- (setf (getf splits slot) (hash-table-keys (getf splits slot))))
- (dolist (slot +album-whole-slots+)
- (setf (getf wholes slot) (hash-table-keys (getf wholes slot))))
- (loop while (> count 0)
- do (let ((artist (gen-name (getf splits 'artist) 3))
- (num-albums (1+ (random 7))))
- (loop for i below num-albums
- for year = (random-elt (getf wholes 'year))
- for title = (gen-name (getf splits 'album) 5) then
- (gen-name (getf splits 'album) 5)
- for id = (get-album-id artist year title)
- while (> count 0)
- do (decf count)
- do (setf (gethash id albums)
- (make-album
- :id id
- :artist artist
- :year year
- :album title
- :original-date (format nil "~4,'0D-~2,'0D-~2,'0D"
- year (1+ (random 12)) (1+ (random 31)))
- :genre (random-elt (getf wholes 'genre))
- :type (random-elt (getf wholes 'type))
- :status (random-elt (getf wholes 'status))
- :cover (format nil "~A/~A/~D - ~A/cover.jpg" (elt artist 0) artist year title))))))
- albums))
- (defparameter +bit-rates+ '(128 160 192 228 320))
- (defun generate-tracks (max-album-length test-albums-db tracks-db)
- (let ((track-words (make-hash-table :test 'equal))
- (tracks (make-hash-table :test 'equal)))
- (loop for entry being the hash-values of tracks-db
- for track = (entry-data entry)
- when track
- do (loop for word in (split-sequence:split-sequence #\Space (track-title track))
- do (setf (gethash word track-words) t)))
- (setf track-words (hash-table-keys track-words))
- (loop for album being the hash-values of test-albums-db
- for track-count = (+ 2 (random (- max-album-length 1)))
- for bit-rate = (random-elt +bit-rates+)
- for is-vbr = (zerop (random 2))
- do (setf (album-track-count album) track-count
- (album-total-duration album) 0)
- do (loop for i below track-count
- for title = (gen-name track-words 5)
- for path = (format nil "~A/~A/~A - ~A/~A.mp3"
- (elt (album-artist album) 0) (album-artist album)
- (album-year album) (album-album album)
- title)
- for id = (get-file-id (pathname path))
- for track = (make-track
- :album album
- :artist (album-artist album)
- :no (list (write-to-string (1+ i)) (write-to-string track-count))
- :title title
- :part-of-set '("1" "1")
- :bit-rate bit-rate
- :is-vbr is-vbr
- :duration (+ 30 (random 300)))
- do (setf (gethash id tracks)
- (make-entry :path path :data track
- :added (get-universal-time) :modified (get-universal-time) :present t))
- do (incf (album-total-duration album) (track-duration track))))
- tracks))
- (defun generate-dbs (num-tracks dbs)
- (let* ((albums (generate-albums (round num-tracks 12) (cdr dbs)))
- (tracks (generate-tracks 24 albums (car dbs))))
- (cons tracks albums)))
|