summaryrefslogtreecommitdiff
path: root/zipper.lisp
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-12-30 20:55:05 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2023-01-07 14:22:47 -0600
commit745ada638b3f82b4e3076dd75d0fe8c0a47bfb31 (patch)
tree47a4f0a58d626137d009254dcd9dba590bc29c8b /zipper.lisp
parent7a1e8d41ce96a7514adb31529f05aaed6a13c259 (diff)
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
Diffstat (limited to 'zipper.lisp')
-rw-r--r--zipper.lisp20
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)))