Probably working now

This commit is contained in:
Neale Pickett 2022-01-09 19:50:31 -07:00
parent 63114c469a
commit 16b5412875
7 changed files with 32 additions and 40 deletions

View File

@ -35,6 +35,5 @@ dvdbackup -p -F -n DVD \
' \ ' \
| while read val; do | while read val; do
setenv complete "$val" setenv complete "$val"
echo "Complete: $val"
done done

View File

@ -5,27 +5,29 @@
run_in () { run_in () {
( (
cd $1; shift cd $1; shift
setenv status "encoding"
"$@" "$@"
) )
} }
while sleep 2; do while sleep 2; do
echo "idle" > $OUTDIR/status.encoder
for mtype in audio video; do for mtype in audio video; do
ls $mtype | while read d; do ls $mtype | while read d; do
encode=/scripts/$mtype.encode.sh encode=/scripts/$mtype.encode.sh
workdir=$mtype/$d workdir=$mtype/$d
[ -f $workdir/read.finished ] || continue status=$(cd $workdir && getenv status)
[ "$status" = "read finished" ] || continue
echo "$workdir" > $OUTDIR/$mtype.status echo "encoding" > $OUTDIR/status.encoder
setenv status "encoding"
if ! run_in $workdir $encode; then if ! run_in $workdir $encode; then
log "$encode failed" log "$encode failed"
(cd $workdir && setenv status "encode failed")
else else
rm -rf $workdir rm -rf $workdir
fi fi
done done
done done
echo "idle" > $OUTDIR/$mtype.status
done done
# vi: ts=2 sw=2 et ai # vi: ts=2 sw=2 et ai

View File

@ -12,10 +12,12 @@ with_time_dir () {
setenv time "$now" setenv time "$now"
setenv mtype "$mtype" setenv mtype "$mtype"
setenv directory "$dir" setenv directory "$dir"
setenv status "reading"
echo "$mtype" > $OUTDIR/reader.status echo "$mtype" > $OUTDIR/status.reader
if ! "$@"; then if ! "$@"; then
log "$1 failed" log "$1 failed"
setenv status "read failed"
else else
log "$1 succeeded" log "$1 succeeded"
setenv status "read finished" setenv status "read finished"
@ -24,6 +26,7 @@ with_time_dir () {
} }
while sleep 2; do while sleep 2; do
echo "idle" > $OUTDIR/status.reader
case $(setcd -i) in case $(setcd -i) in
*"Disc found in drive: audio"*) *"Disc found in drive: audio"*)
log "Found audio disc" log "Found audio disc"
@ -36,7 +39,6 @@ while sleep 2; do
*) *)
;; ;;
esac esac
echo "idle" > $OUTDIR/reader.status
done done
# vi: sw=2 ts=2 et ai # vi: sw=2 ts=2 et ai

View File

@ -21,7 +21,7 @@ cat <<EOD
"queue": $(queue | jq --slurp), "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

@ -5,19 +5,18 @@
title=$(getenv title) title=$(getenv title)
HandBrakeCLI \ HandBrakeCLI \
--json \
-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 2>/dev/null \
pct=$(awk ' | sed 's/^[A-Za-z]*: //' \
/^Encoding/ { | sed '/^[A-Z]/ d' \
match($0, /([0-9]+) of ([0-9]+), ([0-9.]+)%/, a); | jq --unbuffered '(.Working.Progress // 0) * 100' \
print((100 * a[1] - 100 + a[3]) / a[2]); | while read pct; do
} setenv complete "$pct"
')
[ -n "$pct" ] && setenv complete "$pct"
done done
mv "${title}.mkv" "$OUTDIR" mv "${title}.mkv" "$OUTDIR"

View File

@ -17,18 +17,9 @@
<div class="card-header-title">Status</div> <div class="card-header-title">Status</div>
</div> </div>
<div class="card-content"> <div class="card-content">
<div class="block"> <span class="tag reader is-info is-hidden"></span>
<h2 class="subtitle">Reader</h2> <span class="tag encoder is-info is-hidden"></span>
<p class="reader"> <div class="jobs"></div>
<span class="text">unknown</span>
<progress class="progress is-primary" max="100" value="0"></progress>
</p>
</div>
<div class="block">
<h2 class="subtitle">Encoder</h2>
<div class="encoder"></div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -50,9 +41,10 @@
<div> <div>
</div> </div>
</section> </section>
<template class="encoder-item"> <template class="job-item">
<p> <p>
<span class="encoder-title"></span> [<span class="job-status"></span>]
<span class="job-title"></span>
<progress class="progress is-primary" max="100" value="0"></progress> <progress class="progress is-primary" max="100" value="0"></progress>
</p> </p>
</template> </template>

View File

@ -5,26 +5,24 @@ async function update() {
let resp = await fetch("status.json", {cache: "no-store"}) let resp = await fetch("status.json", {cache: "no-store"})
let s = await resp.json() let s = await resp.json()
for (let activity of ["reader"]) { for (let activity of ["reader", "encoder"]) {
let val = s.status[activity] let val = s.status[activity]
let e = document.querySelector(`.status .${activity}`) let e = document.querySelector(`.status .${activity}`)
let txt = e.querySelector(".text") e.textContent = val
let progress = e.querySelector("progress")
txt.textContent = val
if (val == "idle") { if (val == "idle") {
progress.value = 0 e.classList.add("is-hidden")
} else { } else {
// Removing the value makes it pulse e.classList.remove("is-hidden")
progress.removeAttribute("value")
} }
} }
let qtmpl = document.querySelector("template.encoder-item").content let qtmpl = document.querySelector("template.job-item").content
let qelem = document.querySelector(".encoder") let qelem = document.querySelector(".jobs")
while (qelem.firstChild) qelem.firstChild.remove() while (qelem.firstChild) qelem.firstChild.remove()
for (let qitem of s.queue) { for (let qitem of s.queue) {
let e = qtmpl.cloneNode(true) let e = qtmpl.cloneNode(true)
e.querySelector(".encoder-title").textContent = qitem.title e.querySelector(".job-title").textContent = qitem.title
e.querySelector(".job-status").textContent = qitem.status
e.querySelector("progress").value = qitem.complete e.querySelector("progress").value = qitem.complete
qelem.append(e) qelem.append(e)
} }