Working to get completion percentage

This commit is contained in:
Neale Pickett 2022-01-09 16:26:12 -07:00
parent 98a36761b7
commit f739a18c23
11 changed files with 113 additions and 37 deletions

View File

@ -24,6 +24,7 @@ RUN true \
busybox \
jq \
procps \
moreutils \
cowsay
COPY scripts /scripts

View File

@ -10,6 +10,7 @@ To Do
* Completion percentage scraping
* Handbrake: `Encoding: task 2 of 2, 20.58%`
* dvdbackup: `Copying Title, part 2/4: 72% done`
* Set title for audio CDs on read
Done

View File

@ -1,8 +1,8 @@
#! /bin/sh
. /scripts/common.sh
. $(dirname $0)/common.sh
. ./env
discid=$(getenv discid)
abcde -C $discid -o mp3:-V2
cp -r mp3/* $OUTDIR

View File

@ -1,15 +1,12 @@
#! /bin/sh
setenv status "ripping"
abcde -N -a cddb,read
discid=$(cd-discid | awk '{print $1}')
setenv discid "$discid"
now=$(getenv time)
cat <<EOD >env
mtype=cd
discid=$discid
EOD
now=$(date +%Y%m%d.%H%M%S)
sed -i s/'Unknown Album$'/"Unknown Album $now"/ abcde.$discid/cddbread.0
# vi: sw=2 ts=2 et ai

View File

@ -8,10 +8,13 @@ log () {
printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*"
}
status () {
task=$1
status=$2
echo "$status" > $OUTDIR/status.$task
getenv () {
jq -r --arg key "$1" '.[$key]' < env.json
}
setenv () {
(cat env.json 2>/dev/null || echo '{}') \
| jq --arg key "$1" --arg val "$2" '.[$key] = $val' \
| sponge env.json
}

View File

@ -1,16 +1,64 @@
#! /bin/sh -e
. /scripts/common.sh
. $(dirname $0)/common.sh
setenv status "scanning"
log "Scanning for DVD title"
title=$(dvdbackup -I | awk -F \" '/DVD with title/ {print $2}')
setenv title "$title"
log "DVD Title: $title"
# How big is this DVD?
totalSize=$(dvdbackup -I | awk '/[MK]iB$/ { b += $2 } END { print b }')
cat <<EOD >env
mtype=dvd
title="$title"
EOD
dvdbackup -p -F -n DVD \
| tr '\r' '\n' \
| awk -F '[ /:]+' '
function update() {
print "% " pct;
fflush();
}
dvdbackup -p -M -n DVD
/Found [0-9]+ VTS/ {
numTitles = $3;
title = 1;
pct = 0;
print "# I found " numTitles " titles"
update()
}
/Copying menu:/ {
# Not sure how to know in advance how many of these there will be.
print "# We are reading the menu: " $0
update();
}
/Copying Title,/ {
# Copying Title, part 1/5: 23% done (239/1024 MiB)
part = $4
parts = $5
done = $6
print "# Title " part " of " parts " pct " done
titleDone = (part * 100 - 100 + done) / parts;
if (titleDone < titleLast) {
title += 1;
}
titleLast = titleDone;
pct = (title * 100 - 100 + pctDone) / numTitles;
update();
}
{
print "## " $0;
update();
}
' \
| while read t val; do
case "$t" in
"%")
setenv complete "$val"
echo "Complete: $val"
;;
*)
echo "$t $val"
;;
esac
done

View File

@ -1,6 +1,6 @@
#! /bin/sh
. /scripts/common.sh
. $(dirname $0)/common.sh
run_in () {
(
@ -16,7 +16,8 @@ while sleep 2; do
workdir=$mtype/$d
[ -f $workdir/read.finished ] || continue
status "encoder" "$workdir"
echo "$workdir" > $OUTDIR/$mtype.status
setenv status "encoding"
if ! run_in $workdir $encode; then
log "$encode failed"
else
@ -24,7 +25,7 @@ while sleep 2; do
fi
done
done
status "encoder" "idle"
echo "idle" > $OUTDIR/$mtype.status
done
# vi: ts=2 sw=2 et ai

View File

@ -1,18 +1,24 @@
#! /bin/sh
. /scripts/common.sh
. $(dirname $0)/common.sh
with_time_dir () {
mtype=$1; shift
now=$(date --rfc-3339=s | tr ' ' T)
mkdir -p $mtype/$now
cd $mtype/$now
status "reader" "$mtype"
dir="$mtype/$now"
mkdir -p "$dir"
cd "$dir"
setenv time "$now"
setenv mtype "$mtype"
setenv directory "$dir"
echo "$mtype" > $OUTDIR/reader.status
if ! "$@"; then
log "$1 failed"
else
log "$1 succeeded"
touch read.finished
setenv status "read finished"
eject
fi
}
@ -30,7 +36,7 @@ while sleep 2; do
*)
;;
esac
status "reader" "idle"
echo "idle" > $OUTDIR/reader.status
done
# vi: sw=2 ts=2 et ai

View File

@ -1,6 +1,16 @@
#! /bin/sh
. /scripts/common.sh
. $(dirname $0)/common.sh
queue () {
ls audio/*/env.json video/*/env.json 2>/dev/null \
| while read envjson
do
dir=${envjson%/env.json}
cat $envjson \
| jq --arg dir "$dir" '.directory = $dir'
done
}
cat <<EOD
{
@ -8,9 +18,10 @@ cat <<EOD
"video": $(ls *.mkv 2>/dev/null | jq -nR '[inputs]'),
"audio": $(ls */*/.mp3 2>/dev/null | jq -nR '[inputs]')
},
"queue": $(queue | jq --slurp),
"status": {
"reader": $(cat status.reader | jq -nR '[inputs][0]'),
"encoder": $(cat status.encoder | jq -nR '[inputs][0]')
"encoder": $(cat status.encoder | jq -nR '[inputs][0]'),
}
}
EOD

View File

@ -1,6 +1,6 @@
#! /bin/sh
. /scripts/common.sh
. $(dirname $0)/common.sh
while true; do
if ! /scripts/status.json.sh > /www/status.json.new; then

View File

@ -1,17 +1,25 @@
#! /bin/sh -e
. /scripts/common.sh
. $(dirname $0)/common.sh
. ./env
status encoder "Encoding $title"
title=$(getenv title)
HandBrakeCLI \
-i DVD/VIDEO_TS \
--main-feature \
--native-language eng \
-Z "Chromecast 1080p30 Surround" \
-o "${title}.mkv"
-o "${title}.mkv" \
| while read line; do
pct=$(awk '
/^Encoding/ {
match($0, /([0-9]+) of ([0-9]+), ([0-9.]+)%/, a);
print((100 * a[1] - 100 + a[3]) / a[2]);
}
')
[ -n "$pct" ] && setenv complete "$pct"
done
mv "${title}.mkv" "$OUTDIR"
# vi: sw=2 ts=2 et ai