summaryrefslogtreecommitdiff
path: root/zipper.lisp
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-12-27 19:22:46 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2023-01-07 14:22:47 -0600
commit7a1e8d41ce96a7514adb31529f05aaed6a13c259 (patch)
tree0526cfea392394a9c8e1d51e37c1565877f10f46 /zipper.lisp
parent3f7990b73a0a5c72550b34400270615771fffed8 (diff)
Clean: zipper.lisp implementation and defuns, fewer iterations
Diffstat (limited to 'zipper.lisp')
-rw-r--r--zipper.lisp48
1 files changed, 25 insertions, 23 deletions
diff --git a/zipper.lisp b/zipper.lisp
index 2151019..36e62f9 100644
--- a/zipper.lisp
+++ b/zipper.lisp
@@ -3,29 +3,12 @@
(in-package :vampire)
(defun zip-playlist (playlist)
- "Copies all playlist tracks into a download directory and compresses them into a zip archive.
-Returns the filename of the zip file."
+ "Compresses playlist tracks into a zip archive."
(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)))))
+ (let ((zip-dir (zipped-playlist-path)))
(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 dir)
- (let ((audio-files (mapcar #'track-file (playlist-tracks playlist)))
- (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" dir dest)))))
-
-(defun zip-playlist-filenames (playlist)
- (loop for track in (playlist-tracks playlist)
- for i from 1
- collect (zip-track-filename track i)))
+ (org.shirakumo.zippy:compress-zip
+ (copy-audio-files-for-download playlist tmpdir) zip-dir :if-exists :overwrite))))
(defun zip-track-filename (track pos)
"Return a filename for a track. `NN-ARTIST-ALBUM-TITLE.CODEC'"
@@ -33,5 +16,24 @@ Returns the filename of the zip file."
(format nil "~2,'0d-~a-~a-~a.~a" pos
(clean-slashes artist) (clean-slashes album) (clean-slashes title) codec)))
-(defun clean-slashes (str)
- (cl-ppcre:regex-replace-all "/" str "-"))
+(defun zipped-playlist-filename (playlist)
+ "Return a url-safe zip filename for a playlist."
+ (concatenate 'string (clean-slashes (playlist-title playlist)) ".zip"))
+
+(defun zipped-playlist-path (playlist)
+ "Returns the zipped playlist path relative to the configured static directory."
+ (merge-pathnames (pathname-utils:to-relative (zipped-playlist-url playlist))
+ (static-directory *config*)))
+
+(defun zipped-playlist-url (playlist)
+ "Returns the url where the playlist's zip file is expected to exist."
+ (merge-pathnames (zipped-playlist-filename playlist) "/media/bundled-playlists/"))
+
+(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)
+ for pos from 1
+ for file = (track-file track)
+ for dest = (merge-pathnames (zip-track-filename track pos) dir)
+ do (uiop:copy-file file dest)
+ collect dest))