aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-12-18 20:11:32 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2023-01-07 14:22:47 -0600
commit991f2f44acc7e6f839d3b43225b2f35e32f6887a (patch)
tree9aba679648b276baa82d3ef978434d34f945bbea
parent32310d910b8721f46c96cfb3709ca2d13da7b066 (diff)
Add: basic first implementation of creating playlist zips
-rw-r--r--vampire.asd3
-rw-r--r--zipper.lisp34
2 files changed, 36 insertions, 1 deletions
diff --git a/vampire.asd b/vampire.asd
index 2690ca3..ac49ea3 100644
--- a/vampire.asd
+++ b/vampire.asd
@@ -15,7 +15,8 @@
#:derrida
#:ironclad
#:jonathan
- #:swank)
+ #:swank
+ #:zippy)
:components ((:file "hunchentoot-handle-static-file")
(:file "package")
(:file "definition-macros")
diff --git a/zipper.lisp b/zipper.lisp
new file mode 100644
index 0000000..4d80f59
--- /dev/null
+++ b/zipper.lisp
@@ -0,0 +1,34 @@
+;;;; zipper.lisp
+
+(in-package :vampire)
+
+(defun clean-slashes (str)
+ (cl-ppcre:regex-replace-all "/" str "-"))
+
+(defun zip-playlist (playlist)
+ (let* ((tracks (zip-playlist-filenames playlist))
+ (out (format nil "public/static/~a.zip" (clean-slashes (playlist-title playlist)))))
+ (org.shirakumo.zippy:compress-zip tracks out)))
+
+(defun zip-track-filename (track pos playlist)
+ (with-slots (artist album title codec) track
+ (format nil "~a/~2,'0d-~a-~a-~a.~a" (zip-playlist-dir playlist) pos
+ (clean-slashes artist) (clean-slashes album) (clean-slashes title) codec)))
+
+(defun zip-playlist-dir (playlist)
+ (format nil "public/static/downloads/~a/" (clean-slashes (playlist-title playlist))))
+
+(defun zip-playlist-filenames (playlist)
+ (loop for track in (playlist-tracks playlist)
+ for i from 1
+ collect (zip-track-filename track i playlist)))
+
+(defun copy-audio-files-for-download (playlist)
+ (ensure-directories-exist #P"public/static/downloads/")
+ (let ((audio-files (mapcar #'track-file (playlist-tracks playlist)))
+ (dest-files (zip-playlist-filenames playlist))
+ (dest-dir (zip-playlist-dir playlist)))
+ (ensure-directories-exist dest-dir)
+ (loop for file in audio-files
+ for dest in dest-files
+ do (uiop:copy-file file (format nil "~a~a" dest-dir dest)))))