diff options
Diffstat (limited to 'zipper.lisp')
-rw-r--r-- | zipper.lisp | 20 |
1 files changed, 15 insertions, 5 deletions
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))) |