summaryrefslogtreecommitdiffstats
path: root/.local/bin/booksplit
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2020-05-27 09:22:40 -0400
committerLuke Smith <luke@lukesmith.xyz>2020-05-27 09:22:40 -0400
commita6cee230d0cad7b1037e3bca0e7e78123cc432cc (patch)
tree9ca13b1161a14aae7acc91a855dc974f592479f2 /.local/bin/booksplit
parenta8ff531a3c4671dda3f2710ffdebde9820635912 (diff)
downloadeibhear-a6cee230d0cad7b1037e3bca0e7e78123cc432cc.tar.gz
eibhear-a6cee230d0cad7b1037e3bca0e7e78123cc432cc.tar.zst
eibhear-a6cee230d0cad7b1037e3bca0e7e78123cc432cc.zip
for video;
remember to install opustags, ffmpeg and youtube-dl
Diffstat (limited to '.local/bin/booksplit')
-rwxr-xr-x.local/bin/booksplit44
1 files changed, 44 insertions, 0 deletions
diff --git a/.local/bin/booksplit b/.local/bin/booksplit
new file mode 100755
index 0000000..0029d0b
--- /dev/null
+++ b/.local/bin/booksplit
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# Requires ffmpeg (audio splitting) and my `tag` wrapper script.
+
+[ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit
+
+echo "Enter the album/book title:"; read -r booktitle
+
+echo "Enter the artist/author:"; read -r author
+
+echo "Enter the publication year:"; read -r year
+
+inputaudio="$1"
+
+# Get a safe file name from the book.
+escbook="$(echo "$booktitle" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
+
+! mkdir -p "$escbook" && echo "Do you have write access in this directory?" && exit 1
+
+# As long as the extension is in the tag script, it'll work.
+ext="opus"
+#ext="${1#*.}"
+
+# Get the total number of tracks from the number of lines.
+total="$(wc -l < "$2")"
+
+while read -r x;
+do
+ end="$(echo "$x" | cut -d' ' -f1)"
+ [ -n "$start" ] &&
+ echo "From $start to $end; $track $title"
+ file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext"
+ [ -n "$start" ] && echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn "$file" &&
+ echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"
+ title="$(echo "$x" | cut -d' ' -f 2-)"
+ esctitle="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
+ track="$((track+1))"
+ start="$end"
+done < "$2"
+# The last track must be done outside the loop.
+echo "From $start to the end: $title"
+file="$escbook/$track-$esctitle.$ext"
+echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -vn "$file" &&
+ echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"