diff options
author | Colin Okay <colin@cicadas.surf> | 2022-10-26 14:37:26 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-10-26 14:37:26 -0500 |
commit | bf23da7325c87317ef29cdfbe0d331f74f128bfc (patch) | |
tree | 7e516d1664000dcf6a57f5c8e61385674b30820b /playlist.lisp | |
parent | 45c122f4df54d926e8c62ff94dfb1a6779f8370b (diff) |
Refactor: Adding tracks checks and reuses same source tracks
Diffstat (limited to 'playlist.lisp')
-rw-r--r-- | playlist.lisp | 32 |
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))))))) |