Recently Written · git

librivox

Automated youtube uploading of audiobooks

git clone https://github.com/equwal/librivox

Log | Files | Refs


commit f00cf8e1e2eed0fad67e72fa449e415b20a0f5e9
jose <jose@linux-q5ep.lan>
2018-11-16 14:43:40 -0800

Loads up without prompting.

 librivox.asd    |  4 ++--
 packages.lisp   |  9 +++------
 src/csv.lisp    | 54 +++++++++++++++++++++++++++---------------------------
 src/ffmpeg.lisp | 20 ++++++++++----------
 4 files changed, 42 insertions(+), 45 deletions(-)
diff --git a/librivox.asd b/librivox.asd
index d5d2e72..b7b381f 100644
--- a/librivox.asd
+++ b/librivox.asd
@@ -5,10 +5,10 @@
   :depends-on (#-cl+ssl-broken :drakma
 			       :cl-ppcre
 			       :uiop
-			       :bordeaux-threads)
+			       :bordeaux-threads
+			       :utils)
   :description "Librivox auto downloader/youtube uploader."
   :components ((:file "packages")
-	       (:file "src/utils")
 	       (:file "src/csv")
 	       (:file "src/bash")
 	       (:file "src/workaround")
diff --git a/packages.lisp b/packages.lisp
index 6d314ad..52116ab 100644
--- a/packages.lisp
+++ b/packages.lisp
@@ -1,10 +1,6 @@
-(defpackage :utils
-  (:use :cl :cl-user)
-  (:export :mvbind :dbind :list-directory :dolines :doread :push-on
-	   :with-gensyms :once-only :aif :awhen))
 (defpackage :csv
   (:use :cl :utils)
-  (:import-from :utils :push-on :with-gensyms :make-reader :doread))
+  (:import-from :utils :push-on :with-gensyms :make-reader :doread :dolines))
 (defpackage :bash
   (:use :cl :uiop)
   (:export :run-line
@@ -23,9 +19,10 @@
 	:utils :uiop :bordeaux-threads)
   #+cl+ssl-broken (:import-from :workaround :http-request)
   #-cl+ssl-broken (:import-from :drakma :http-request)
-  (:import-from :utils :list-directory :mvbind :dbind :dolines
+  (:import-from :utils :mvbind :dbind :dolines
 		:with-gensyms :once-only :aif :awhen)
   (:import-from :bash :run-line :*bash-output* :run-line-integer-output)
+  (:import-from :uiop :subdirectories :directory-files)
   (:import-from :bordeaux-threads
 		:make-thread
 		:make-lock
diff --git a/src/csv.lisp b/src/csv.lisp
index 4124ca8..08d769a 100644
--- a/src/csv.lisp
+++ b/src/csv.lisp
@@ -9,40 +9,40 @@
 (defun open? (prev curr)
   (declare (ignore curr))
   (char= #\" prev))
-(define-modify-macro toggle () not)
-(defun make-switches ()
-  (let ((in nil)
-	(escape nil))
-    (lambda (prev curr str)
-      (if (null curr)
-	  (progn (setf in nil escape nil) str)
-	  (if in
-	      (if escape
-		  (progn (toggle escape) (push-on prev str))
-		  (if (make-escape? prev curr)
-		      (progn (toggle escape) str)
-		      (if (end-token? prev curr)
-			  (progn (toggle in) (push-on #\Nul str))
-			  (push-on prev str))))
-	      (if (open? prev curr)
-		  (progn (toggle in) str)
-		  str))))))
+(let ((in nil)
+      (escape nil))
+  (setf (fdefinition 'switches)
+	(lambda (prev curr str)
+	  (if (null curr)
+	      (progn (setf in nil escape nil) str)
+	      (if in
+		  (if escape
+		      (progn (toggle escape) (push-on prev str))
+		      (if (make-escape? prev curr)
+			  (progn (toggle escape) str)
+			  (if (end-token? prev curr)
+			      (progn (toggle in) (push-on #\Nul str))
+			      (push-on prev str))))
+		  (if (open? prev curr)
+		      (progn (toggle in) str)
+		      str))))))
 (defun splice (str &optional acc!)
   (if (string= "" str)
       (nreverse acc!)
     (let ((res (search (string #\Nul) str)))
       (splice (subseq str (1+ res)) (push (subseq str 0 res) acc!)))))
 (make-reader my-csv (stream #\# #\!)
-  (let ((switches (make-switches)))
-    (macrolet ((once (&body body) ``',,@body))
-     (do ((prev #1= (read-char stream nil nil) curr)
-	  (curr #1# #1#)
-	  (str (make-array 0 :adjustable t :element-type 'character)
-	       (funcall switches prev curr str)))
-	 ((and (char= curr #\#) (char= prev #\!)) (once (splice (funcall switches nil nil str))))))))
+  (macrolet ((once (&body body) ``',,@body))
+    (do ((prev #1= (read-char stream nil nil) curr)
+	 (curr #1# #1#)
+	 (str (make-array 0 :adjustable t :element-type 'character)
+	      (switches prev curr str)))
+	((and (char= curr #\#) (char= prev #\!)) (once (splice (switches nil nil str)))))))
 (defun read-to-string (stream)
-  (let ((str (make-array 0 :adjustable t :element-type 'character)))
-    (doread (ch stream) (push-on ch str)) str))
+  (with-output-to-string (s)
+    (dolines (line stream)
+      (princ line s)
+      (format s "~%"))))
 (defun slurp-csv (path)
   (with-open-file (s path)
     (concatenate 'string "#!" (read-to-string s) "!#")))
diff --git a/src/ffmpeg.lisp b/src/ffmpeg.lisp
index fa1ba2e..7d77a06 100644
--- a/src/ffmpeg.lisp
+++ b/src/ffmpeg.lisp
@@ -12,8 +12,9 @@
   (parse-integer (run-program (change-dir *downloads-dir* code)
 			      :output :string) :junk-allowed t))
 (defun m3u-down (path)
-  (dolines (line path)
-      (run-line* (format nil "wget -nc ~A" line)) (print line)))
+  (with-open-file (s path)
+    (dolines (line s)
+      (run-line* (format nil "wget -nc ~A" line)) (print line))))
 (defmacro with-dir (dir &body body)
   (with-gensyms (old)
     `(let ((,old ,*downloads-dir*))
@@ -27,7 +28,7 @@
   (let ((old-dir *downloads-dir*))
     (setf *downloads-dir* dir)
     (unwind-prog1
-     (progn (run-line* "rm temp.mp4")
+     (progn (run-line* "rm *.mp4")
 	    (run-line* "rm *.mp3")
 	    (run-line* "rm concat.txt")
 	    (setf *downloads-dir* old-dir))
@@ -61,11 +62,10 @@
 	  car
 	  (select pred (cdr list))))))
 (defun convert-all ()
-  (dolist (downdir (list-directory *downloads-dir*))
-    (dolist (dir (list-directory downdir))
-      (let ((contents (list-directory dir)))
-	(when (not (some #'video-type?
+  (dolist (dir (subdirectories *downloads-dir*))
+    (let ((contents (directory-files dir)))
+      (when (not (some #'video-type?
 		       contents))
-	    (convert :image (select #'image-type? contents)
-		     :input (select #'archive-type? contents)
-		     :dir downdir))))))
+	(convert :image (select #'image-type? contents)
+		 :input (select #'archive-type? contents)
+		 :dir dir)))))