]> njoseph.me Git - babashka-scripts.git/commitdiff
git-pull-all & ebook-to-audio-book
authorJoseph Nuthalapati <njoseph@riseup.net>
Tue, 9 Feb 2021 16:56:43 +0000 (22:26 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Tue, 9 Feb 2021 16:56:43 +0000 (22:26 +0530)
ebook-to-audio-book.clj [new file with mode: 0755]
git-pull-all.clj [new file with mode: 0755]

diff --git a/ebook-to-audio-book.clj b/ebook-to-audio-book.clj
new file mode 100755 (executable)
index 0000000..e6fa40a
--- /dev/null
@@ -0,0 +1,39 @@
+#! /usr/bin/env bb
+
+; A utility to listen to your ebooks using TTS programs
+
+(require '[babashka.process :as p]
+         '[clojure.java.io :as io]
+         '[clojure.string :refer [split]])
+
+;; TODO Check if all required utilities are installed
+
+;; TODO Allow voice selection
+(println "Selected voice is Samantha")
+
+;; TODO Use festival-tts or say depending on OS
+
+(defn run-cmd
+  [command]
+  (->> command 
+       p/process
+       :out
+       slurp))
+       
+(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])
+  (spit txt-file (run-cmd ["unzip" "-p" txtz-file "index.txt"]))
+  (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...")
+  (doseq [temp-file [txtz-file txt-file aiff-file]]
+    (io/delete-file temp-file))
+  (println (str "Done! Check out " mp3-file)))
diff --git a/git-pull-all.clj b/git-pull-all.clj
new file mode 100755 (executable)
index 0000000..a8152d1
--- /dev/null
@@ -0,0 +1,31 @@
+#! /usr/bin/env bb
+
+; Runs `git pull` on all the git repositories in a directory
+
+(require '[babashka.process :as p]
+         '[clojure.java.io :as io])
+
+(def default-root ".")
+  
+(defn list-dirs
+  [root]
+  (filter #(.isDirectory %) (.listFiles (io/file root))))
+
+(defn git-pull
+  [dir]
+  (p/process ["git" "-C" dir "pull" "--rebase"]))
+
+(when (= *file* (System/getProperty "babashka.file"))
+  (let [root  (get (into [] *command-line-args*) 0 default-root)
+        dirs  (list-dirs root)
+        pulls (->> root
+                   list-dirs
+                   (map git-pull)
+                   doall)
+        outputs (map #(->> % p/check :out slurp) pulls)]
+
+        ;; Print corresponding directory name when pulling
+        ;; Skip printing already up to date repos
+       (doseq [[dir out](filter #(not (.contains (second %) "is up to date."))
+                                (map vector dirs outputs))]
+         (println (str dir "\n" out)))))