aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--playlist.lisp14
-rw-r--r--zipper.lisp34
2 files changed, 30 insertions, 18 deletions
diff --git a/playlist.lisp b/playlist.lisp
index f676936..f7f0b04 100644
--- a/playlist.lisp
+++ b/playlist.lisp
@@ -13,7 +13,8 @@
(np-title np-artist np-thumb np-dur np-time np-play
:std nil :doc "Now Playing Elements")
(pl-title pl-tracks pl-dur
- :std nil :doc "Playlist Elements"))
+ :std nil :doc "Playlist Elements")
+ (zipped :std nil :doc "Path to the zipped playlist, if it exists."))
(:documentation "Holds the complete state for this session's viewing of a particular playlist."))
(defclass/std track-ctl ()
@@ -438,11 +439,20 @@
(div (:class "row")
(div ()
+ (button (:content "Create Playlist Zip" :bind download))
+ (a (:link (zipped ctl) :content "Download" :bind dl-link)))
+ (div ()
(new-track-form (pl))
(editor-managment (pl)))))
+ (set-on-click download (thunk*
+ (setf (zipped ctl) (zip-playlist pl)
+ (link dl-link) (zipped ctl)
+ (display dl-link) "inline")))
+
(setf (pl-title ctl) title-elem
(pl-dur ctl) dur-elem
(display input) "none"
+ (display dl-link) "none"
(display title-elem) "inline")
(when (playlist-editors pl)
@@ -453,7 +463,7 @@
do (format out "<a href='/user/~a'>~a</a>"
(key u) (user-name u))
when more do (princ ", " out)))))
-
+
(when (editorp ctl)
(setf (attribute title-elem "title") "Click to edit the title."
(text edit-indicator) "(click the title to edit it)")
diff --git a/zipper.lisp b/zipper.lisp
index 25e05c9..2151019 100644
--- a/zipper.lisp
+++ b/zipper.lisp
@@ -3,33 +3,35 @@
(in-package :vampire)
(defun zip-playlist (playlist)
- (let* ((tracks (zip-playlist-filenames playlist))
- (out (format nil "/media/downloads/~a.zip" (clean-slashes (playlist-title playlist)))))
- (copy-audio-files-for-download playlist)
- (org.shirakumo.zippy:compress-zip tracks out)))
+ "Copies all playlist tracks into a download directory and compresses them into a zip archive.
+Returns the filename of the zip file."
+ (with-temp-dir (tmpdir)
+ (let* ((tracks (mapcar (lambda (track) (merge-pathnames tmpdir track))
+ (zip-playlist-filenames playlist)))
+ (zip-dir (merge-pathnames "media/bundled-playlists" (static-directory *config*)))
+ (out (format nil "~a/~a.zip" zip-dir (clean-slashes (playlist-title playlist)))))
+ (ensure-directories-exist zip-dir)
+ (copy-audio-files-for-download playlist tmpdir)
+ (org.shirakumo.zippy:compress-zip tracks out :if-exists :overwrite)
+ (format nil "/media/bundled-playlists/~a.zip" (clean-slashes (playlist-title playlist))))))
-(defun copy-audio-files-for-download (playlist)
- (ensure-directories-exist #P"/media/downloads/")
+(defun copy-audio-files-for-download (playlist dir)
(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)
+ (dest-files (zip-playlist-filenames playlist)))
(loop for file in audio-files
for dest in dest-files
- do (uiop:copy-file file (format nil "~a~a" dest-dir dest)))))
+ do (uiop:copy-file file (format nil "~a~a" dir dest)))))
(defun zip-playlist-filenames (playlist)
(loop for track in (playlist-tracks playlist)
for i from 1
- collect (zip-track-filename track i playlist)))
+ collect (zip-track-filename track i)))
-(defun zip-track-filename (track pos playlist)
+(defun zip-track-filename (track pos)
+ "Return a filename for a track. `NN-ARTIST-ALBUM-TITLE.CODEC'"
(with-slots (artist album title codec) track
- (format nil "~a/~2,'0d-~a-~a-~a.~a" (zip-playlist-dir playlist) pos
+ (format nil "~2,'0d-~a-~a-~a.~a" pos
(clean-slashes artist) (clean-slashes album) (clean-slashes title) codec)))
-(defun zip-playlist-dir (playlist)
- (format nil "/media/downloads/~a/" (clean-slashes (playlist-title playlist))))
-
(defun clean-slashes (str)
(cl-ppcre:regex-replace-all "/" str "-"))