From de749f527293b96ef8f3c54575e6bacb436b17b5 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:20:18 +0900 Subject: deleted bin/booksplit, created bin/albumsplit --- ar/.local/bin/albumsplit | 45 +++++++++++++++++++++++++++++++++++++++++++++ ar/.local/bin/booksplit | 45 --------------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) create mode 100755 ar/.local/bin/albumsplit delete mode 100755 ar/.local/bin/booksplit diff --git a/ar/.local/bin/albumsplit b/ar/.local/bin/albumsplit new file mode 100755 index 0000000..bdf637a --- /dev/null +++ b/ar/.local/bin/albumsplit @@ -0,0 +1,45 @@ +#!/bin/sh + +# Requires ffmpeg + +[ ! -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" +ext="${1##*.}" + +# Get a safe file name from the book. +escbook="$(echo "$booktitle" | iconv -c -f 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 + +# Get the total number of tracks from the number of lines. +total="$(wc -l <"$2")" + +cmd="ffmpeg -i \"$inputaudio\" -nostdin -y" + +while read -r x; do + end="$(echo "$x" | cut -d' ' -f1)" + file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" + if [ -n "$start" ]; then + cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -metadata total=\"$total\" -ss \"$start\" -to \"$end\" -vn -c:a copy \"$file\" " + fi + title="$(echo "$x" | cut -d' ' -f2-)" + esctitle="$(echo "$title" | iconv -c -f UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + track="$((track + 1))" + start="$end" +done <"$2" + +# Last track must be added out of the loop. +file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" +cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -ss \"$start\" -vn -c copy \"$file\"" + +eval "$cmd" diff --git a/ar/.local/bin/booksplit b/ar/.local/bin/booksplit deleted file mode 100755 index bdf637a..0000000 --- a/ar/.local/bin/booksplit +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -# Requires ffmpeg - -[ ! -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" -ext="${1##*.}" - -# Get a safe file name from the book. -escbook="$(echo "$booktitle" | iconv -c -f 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 - -# Get the total number of tracks from the number of lines. -total="$(wc -l <"$2")" - -cmd="ffmpeg -i \"$inputaudio\" -nostdin -y" - -while read -r x; do - end="$(echo "$x" | cut -d' ' -f1)" - file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" - if [ -n "$start" ]; then - cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -metadata total=\"$total\" -ss \"$start\" -to \"$end\" -vn -c:a copy \"$file\" " - fi - title="$(echo "$x" | cut -d' ' -f2-)" - esctitle="$(echo "$title" | iconv -c -f UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" - track="$((track + 1))" - start="$end" -done <"$2" - -# Last track must be added out of the loop. -file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" -cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -ss \"$start\" -vn -c copy \"$file\"" - -eval "$cmd" -- cgit v1.2.3