From 745ada638b3f82b4e3076dd75d0fe8c0a47bfb31 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Fri, 30 Dec 2022 20:55:05 -0600 Subject: Add: zip/download UI and deletion of archive on playlist edit - Clicking the button will zip the playlist (if there is no zip archive already existing) - editing a playlist will delete the zip file --- zipper.lisp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'zipper.lisp') diff --git a/zipper.lisp b/zipper.lisp index 36e62f9..ede4a71 100644 --- a/zipper.lisp +++ b/zipper.lisp @@ -4,11 +4,13 @@ (defun zip-playlist (playlist) "Compresses playlist tracks into a zip archive." - (with-temp-dir (tmpdir) - (let ((zip-dir (zipped-playlist-path))) - (ensure-directories-exist zip-dir) - (org.shirakumo.zippy:compress-zip - (copy-audio-files-for-download playlist tmpdir) zip-dir :if-exists :overwrite)))) + (ensure-directories-exist (merge-pathnames "media/bundled-playlists/" (static-directory *config*))) + (unless (zipped-playlist-exists-p playlist) + (let ((zip-file (zipped-playlist-path playlist))) + (with-temp-dir (tmpdir) + (with-open-file (_foo zip-file :if-does-not-exist :create :direction :output :if-exists :overwrite) + (org.shirakumo.zippy:compress-zip + (copy-audio-files-for-download playlist tmpdir) zip-file :if-exists :overwrite)))))) (defun zip-track-filename (track pos) "Return a filename for a track. `NN-ARTIST-ALBUM-TITLE.CODEC'" @@ -29,6 +31,9 @@ "Returns the url where the playlist's zip file is expected to exist." (merge-pathnames (zipped-playlist-filename playlist) "/media/bundled-playlists/")) +(defun zipped-playlist-exists-p (playlist) + (uiop:file-exists-p (zipped-playlist-path playlist))) + (defun copy-audio-files-for-download (playlist dir) "Copies all playlist tracks into a temporary directory and returns a list of the pathnames." (loop for track in (playlist-tracks playlist) @@ -37,3 +42,8 @@ for dest = (merge-pathnames (zip-track-filename track pos) dir) do (uiop:copy-file file dest) collect dest)) + +(defun delete-zipped-playlist (playlist) + "Deletes the zipped playlist file. Returns T if it was deleted, NIL otherwise." + (princ "Deleting zipped playlist") + (uiop:delete-file-if-exists (zipped-playlist-path playlist))) -- cgit v1.2.3