|
1 | 1 | ;;;; lyrics.lisp |
2 | 2 | (in-package #:lyrics) |
3 | 3 |
|
| 4 | +(defparameter *db* nil) |
| 5 | + |
4 | 6 | (defun setup-db () |
5 | 7 | "Create a sqlite table in ~/ if one does not already exist." |
6 | | - (defparameter *db* |
| 8 | + (setf *db* |
7 | 9 | (connect (merge-pathnames "cl-lyrics.db" |
8 | 10 | (xdg-config-home)))) |
9 | 11 | (execute-non-query *db* |
|
17 | 19 | COLLATE NOCASE, |
18 | 20 | lyrics TEXT COLLATE NOCASE);")) |
19 | 21 |
|
20 | | -(setup-db) |
21 | 22 |
|
22 | 23 | (defstruct website |
23 | | - ;; website name, only used for documentation purposes |
| 24 | + ;; website name, only used for documentation purposes |
24 | 25 | (name) |
25 | 26 | ;; Template used to construct the actual url. It contains the artist-name and |
26 | 27 | ;; song-name string, respectively, which need to be replaced with the user |
@@ -160,8 +161,10 @@ name. If the lyrics are not in the db, try and extract them from one of the |
160 | 161 | supported lyrics websites. If found, save the lyrics the db and return them. If |
161 | 162 | not found, return nil." |
162 | 163 | (declare (string artist song)) |
| 164 | + (unless *db* |
| 165 | + (setup-db)) |
163 | 166 | (if-let ((lyrics (lyrics-from-db artist song))) |
164 | | - lyrics ;already in db |
| 167 | + lyrics ;already in db |
165 | 168 | (dolist (website |
166 | 169 | ;; Try to minimize the chance of getting banned; try a different |
167 | 170 | ;; order of sites on every request. |
@@ -196,3 +199,13 @@ the thread that is started for the request." |
196 | 199 | ;; at a future date; take your time; better to be safe than being banned |
197 | 200 | ;; for making too many requests in a short time. |
198 | 201 | (sleep (random-elt '(1 2 3))))))) |
| 202 | + |
| 203 | +(defun main () |
| 204 | + (setup-db) |
| 205 | + |
| 206 | + (setf replic:*prompt* "lyrics> ") |
| 207 | + (replic.completion:functions-to-commands :replic.base) |
| 208 | + (replic.completion:functions-to-commands :lyrics) |
| 209 | + (replic:autoprint-results-from :lyrics) |
| 210 | + |
| 211 | + (replic:repl)) |
0 commit comments