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 \ busybox \
jq \ jq \
procps \ procps \
moreutils \
cowsay cowsay
COPY scripts /scripts COPY scripts /scripts

View File

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

View File

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

View File

@ -1,15 +1,12 @@
#! /bin/sh #! /bin/sh
setenv status "ripping"
abcde -N -a cddb,read abcde -N -a cddb,read
discid=$(cd-discid | awk '{print $1}') 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 sed -i s/'Unknown Album$'/"Unknown Album $now"/ abcde.$discid/cddbread.0
# vi: sw=2 ts=2 et ai # vi: sw=2 ts=2 et ai

View File

@ -8,10 +8,13 @@ log () {
printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*" printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*"
} }
status () { getenv () {
task=$1 jq -r --arg key "$1" '.[$key]' < env.json
status=$2 }
echo "$status" > $OUTDIR/status.$task 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 #! /bin/sh -e
. /scripts/common.sh . $(dirname $0)/common.sh
setenv status "scanning"
log "Scanning for DVD title" log "Scanning for DVD title"
title=$(dvdbackup -I | awk -F \" '/DVD with title/ {print $2}') 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 dvdbackup -p -F -n DVD \
mtype=dvd | tr '\r' '\n' \
title="$title" | awk -F '[ /:]+' '
EOD 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 #! /bin/sh
. /scripts/common.sh . $(dirname $0)/common.sh
run_in () { run_in () {
( (
@ -16,7 +16,8 @@ while sleep 2; do
workdir=$mtype/$d workdir=$mtype/$d
[ -f $workdir/read.finished ] || continue [ -f $workdir/read.finished ] || continue
status "encoder" "$workdir" echo "$workdir" > $OUTDIR/$mtype.status
setenv status "encoding"
if ! run_in $workdir $encode; then if ! run_in $workdir $encode; then
log "$encode failed" log "$encode failed"
else else
@ -24,7 +25,7 @@ while sleep 2; do
fi fi
done done
done done
status "encoder" "idle" echo "idle" > $OUTDIR/$mtype.status
done done
# vi: ts=2 sw=2 et ai # vi: ts=2 sw=2 et ai

View File

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

View File

@ -1,6 +1,16 @@
#! /bin/sh #! /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 cat <<EOD
{ {
@ -8,9 +18,10 @@ cat <<EOD
"video": $(ls *.mkv 2>/dev/null | jq -nR '[inputs]'), "video": $(ls *.mkv 2>/dev/null | jq -nR '[inputs]'),
"audio": $(ls */*/.mp3 2>/dev/null | jq -nR '[inputs]') "audio": $(ls */*/.mp3 2>/dev/null | jq -nR '[inputs]')
}, },
"queue": $(queue | jq --slurp),
"status": { "status": {
"reader": $(cat status.reader | jq -nR '[inputs][0]'), "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 EOD

View File

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

View File

@ -1,17 +1,25 @@
#! /bin/sh -e #! /bin/sh -e
. /scripts/common.sh . $(dirname $0)/common.sh
. ./env title=$(getenv title)
status encoder "Encoding $title"
HandBrakeCLI \ HandBrakeCLI \
-i DVD/VIDEO_TS \ -i DVD/VIDEO_TS \
--main-feature \ --main-feature \
--native-language eng \ --native-language eng \
-Z "Chromecast 1080p30 Surround" \ -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" mv "${title}.mkv" "$OUTDIR"
# vi: sw=2 ts=2 et ai # vi: sw=2 ts=2 et ai