(require '[clojure.java.io :as io]
'[clojure.string :refer [split]]
- '[lib :refer [run-cmd extract-file-from-zip]])
+ '[lib :refer [run-cmd extract-file-from-zip unixify]])
;; TODO Check if all required utilities are installed
;; TODO Use festival-tts or say depending on OS
-(let [book-file (first *command-line-args*)
- title (first (split book-file #"\."))
- txtz-file (str title ".txtz")
- txt-file (str title ".txt")
- aiff-file (str title ".aiff")
- mp3-file (str title ".mp3")]
- (println "Converting to text...")
- (run-cmd ["ebook-convert" book-file txtz-file])
- (extract-file-from-zip txtz-file "index.txt" txt-file)
- (println "Converting text to audio. Don't hold your breath!")
- (run-cmd ["say" "-f" txt-file "-o" aiff-file])
- (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])
- (println (str "Done! Check out " mp3-file)))
+(defn- convert
+ [book-file]
+ (let [title (first (split book-file #"\."))
+ txtz-file (str title ".txtz")
+ txt-file (str title ".txt")
+ aiff-file (str title ".aiff")
+ mp3-file (str title ".mp3")]
+ (println "Converting to text...")
+ (run-cmd ["ebook-convert" book-file txtz-file])
+ (extract-file-from-zip txtz-file "index.txt" txt-file)
+ (println "Converting text to audio. Don't hold your breath!")
+ (run-cmd ["say" "-f" txt-file "-o" aiff-file])
+ (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])
+ (println (str "Done! Check out " mp3-file))))
+
+(unixify convert)
; Install a deb package from URL
-(require '[clojure.java.io :as io] '[lib :refer [download-binary run-cmd]])
+(require '[clojure.java.io :as io]
+ '[lib :refer [download-binary run-cmd unixify]])
-(when (= *file* (System/getProperty "babashka.file"))
- (let [url (first *command-line-args*)]
- (println "Downloading deb package...")
+(defn- install-deb
+ [url]
+ (println "Downloading deb package..."
(download-binary url "package.deb")
(println "Installing...")
(run-cmd ["sudo" "gdebi" "--non-interactive" "package.deb"])
(println "Cleaning up..")
(io/delete-file "package.deb")
(println "Done.")))
+
+(unixify install-deb)
(:require [babashka.process :as p]
[org.httpkit.client :as http]
[clojure.java.io :as io]
- [clojure.string :refer [replace-first]])
+ [clojure.string :refer [replace-first split-lines]])
(:import [java.nio.file Files FileSystems CopyOption StandardCopyOption]))
(defn run-cmd
(defn download-binary
[url destination]
(io/copy (:body @(http/get url)) (io/file destination)))
+
+(defn unixify
+ "Make a function `f` behave like a UNIX shell command."
+ [f]
+ (when (= *file* (System/getProperty "babashka.file"))
+ (let [content (if (> (.available System/in) 0)
+ (slurp *in*)
+ (first *command-line-args*))]
+ (doseq [arg (filter #(not= "" %) (split-lines content))]
+ (f arg)))))