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
setenv complete "$val"
echo "Complete: $val"
done

View File

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

View File

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

View File

@ -21,7 +21,7 @@ cat <<EOD
"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

@ -5,19 +5,18 @@
title=$(getenv title)
HandBrakeCLI \
--json \
-i DVD/VIDEO_TS \
--main-feature \
--native-language eng \
-Z "Chromecast 1080p30 Surround" \
-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"
2>/dev/null \
| sed 's/^[A-Za-z]*: //' \
| sed '/^[A-Z]/ d' \
| jq --unbuffered '(.Working.Progress // 0) * 100' \
| while read pct; do
setenv complete "$pct"
done
mv "${title}.mkv" "$OUTDIR"

View File

@ -17,18 +17,9 @@
<div class="card-header-title">Status</div>
</div>
<div class="card-content">
<div class="block">
<h2 class="subtitle">Reader</h2>
<p class="reader">
<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>
<span class="tag reader is-info is-hidden"></span>
<span class="tag encoder is-info is-hidden"></span>
<div class="jobs"></div>
</div>
</div>
</div>
@ -50,9 +41,10 @@
<div>
</div>
</section>
<template class="encoder-item">
<template class="job-item">
<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>
</p>
</template>

View File

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