summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-26 14:37:26 -0500
committerColin Okay <colin@cicadas.surf>2022-10-26 14:37:26 -0500
commitbf23da7325c87317ef29cdfbe0d331f74f128bfc (patch)
tree7e516d1664000dcf6a57f5c8e61385674b30820b
parent45c122f4df54d926e8c62ff94dfb1a6779f8370b (diff)
Refactor: Adding tracks checks and reuses same source tracks
-rw-r--r--playlist.lisp32
1 files changed, 19 insertions, 13 deletions
diff --git a/playlist.lisp b/playlist.lisp
index a91da0d..3579c83 100644
--- a/playlist.lisp
+++ b/playlist.lisp
@@ -36,6 +36,9 @@
(setf (playlist-tracks pl) newlist
(track-playlists track) (delete pl (track-playlists track)
:test #'eq :count 1))))
+
+(defun track-with-source (source)
+ (find source (store-objects-with-class 'track) :test #'string-equal :key 'track-source))
;;; TRANSACTIONS
(defun append-track (pl tr)
@@ -277,20 +280,23 @@
(let* ((url
(value url-input))
(notice
- (create-p notice-area :content (format nil "... Fetching ~a" url))))
+ (create-p notice-area :content (format nil "... Fetching ~a" url)))
+ (on-ok
+ (lambda (track)
+ (destroy notice)
+ (append-track pl track)
+ (append-track-list-item parent track))))
(setf (value url-input) "")
- (add-fetch-track-job
- url
- (lambda (track)
- (destroy notice)
- (append-track pl track)
- (append-track-list-item parent track))
- (lambda (err)
- (destroy notice)
- (format t "~a" err)
- (alert (window (connection-body parent))
- (format nil "Error while fetching track at: ~a~%"
- url)))))))))
+ (if-let (track (track-with-source url))
+ (funcall on-ok track)
+ (add-fetch-track-job
+ url on-ok
+ (lambda (err)
+ (destroy notice)
+ (format t "~a" err)
+ (alert (window (connection-body parent))
+ (format nil "Error while fetching track at: ~a~%"
+ url))))))))))
(defun playlist-key-from-url (url)
(first (last (ppcre:split "/" (nth 4 (multiple-value-list (quri:parse-uri url)))))))