From bf23da7325c87317ef29cdfbe0d331f74f128bfc Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 26 Oct 2022 14:37:26 -0500 Subject: Refactor: Adding tracks checks and reuses same source tracks --- playlist.lisp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'playlist.lisp') 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))))))) -- cgit v1.2.3