]> njoseph.me Git - babashka-scripts.git/blobdiff - ebook-to-audio-book.clj
Add utils and shell aliases
[babashka-scripts.git] / ebook-to-audio-book.clj
index 8305c2e92b45429be875c6f40df61ba7d228a17c..39da869ed28aff7630f3ebac1b1d483e218ddbc2 100755 (executable)
@@ -2,11 +2,9 @@
 
 ; A utility to listen to your ebooks using TTS programs
 
-(import '[java.nio.file Files FileSystems CopyOption])
-
-(require '[babashka.process :as p]
-         '[clojure.java.io :as io]
-         '[clojure.string :refer [split]])
+(require '[clojure.java.io :as io]
+         '[clojure.string :refer [split]]
+         '[lib :refer [run-cmd extract-file-from-zip]])
 
 ;; TODO Check if all required utilities are installed
 
 
 ;; TODO Use festival-tts or say depending on OS
 
-
-(defn run-cmd
-  [command]
-  (->> command
-       p/process
-       :out
-       slurp))
-
-(defn extract-file-from-zip
-  [zip-file-name source destination]
-  (let [zip-file (io/file zip-file-name)
-        src (io/file source)
-        dest (io/file destination)
-        fs (FileSystems/newFileSystem (.toPath zip-file) nil)
-        file-in-zip (.getPath fs source (into-array String []))]
-    (Files/copy file-in-zip (.toPath dest)
-                (into-array CopyOption []))))
-
 (let [book-file (first *command-line-args*)
       title (first (split book-file #"\."))
       txtz-file (str title ".txtz")
@@ -47,5 +27,5 @@
   (println "Creating mp3 file...")
   (run-cmd ["ffmpeg" "-i" aiff-file mp3-file])
   (println "Cleaning up...")
-  (run! #(io/delete-file %) [txtz-file txt-file aiff-file])
+  (run! io/delete-file [txtz-file txt-file aiff-file])
   (println (str "Done! Check out " mp3-file)))