From 77ea815c23a0a10bcb80e878f47705b7210d5d4d Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Sun, 18 Dec 2022 20:20:41 -0600 Subject: Clean: reorganize and fix hardcoded directories --- zipper.lisp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/zipper.lisp b/zipper.lisp index 4d80f59..25e05c9 100644 --- a/zipper.lisp +++ b/zipper.lisp @@ -2,29 +2,14 @@ (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))))) + (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))) -(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/") + (ensure-directories-exist #P"/media/downloads/") (let ((audio-files (mapcar #'track-file (playlist-tracks playlist))) (dest-files (zip-playlist-filenames playlist)) (dest-dir (zip-playlist-dir playlist))) @@ -32,3 +17,19 @@ (loop for file in audio-files for dest in dest-files do (uiop:copy-file file (format nil "~a~a" dest-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))) + +(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 "/media/downloads/~a/" (clean-slashes (playlist-title playlist)))) + +(defun clean-slashes (str) + (cl-ppcre:regex-replace-all "/" str "-")) -- cgit v1.2.3