From f7d9e0e20c6f060ec042575e1ca4fa6916a430e2 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 6 Jan 2022 17:33:25 -0700 Subject: [PATCH] Add http status thingy --- Dockerfile | 7 ++++- httpd.conf | 1 + scripts/common.sh | 14 +++++++--- scripts/encoder.sh | 3 ++- scripts/init.sh | 2 ++ scripts/reader.sh | 2 ++ scripts/status.json.sh | 16 +++++++++++ scripts/status.sh | 13 +++++++++ www/index.html | 60 ++++++++++++++++++++++++++++++++++++++++++ www/status.json | 45 +++++++++++++++++++++++++++++++ www/sucker.mjs | 38 ++++++++++++++++++++++++++ 11 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 httpd.conf create mode 100755 scripts/status.json.sh create mode 100755 scripts/status.sh create mode 100644 www/index.html create mode 100644 www/status.json create mode 100644 www/sucker.mjs diff --git a/Dockerfile b/Dockerfile index 8984217..44e35cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,10 +21,15 @@ RUN dpkg-reconfigure libdvd-pkg RUN true \ && DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install \ lame \ + busybox \ + jq \ procps \ cowsay COPY scripts /scripts -COPY abcde.conf /etc/ +COPY abcde.conf httpd.conf /etc/ +COPY --chown=linuxserver:linuxserver www /www USER linuxserver ENTRYPOINT ["/scripts/init.sh"] + +# vi: ts=2 sw=2 et ai diff --git a/httpd.conf b/httpd.conf new file mode 100644 index 0000000..b2cfc55 --- /dev/null +++ b/httpd.conf @@ -0,0 +1 @@ +.mjs:text/javascript diff --git a/scripts/common.sh b/scripts/common.sh index 82cc332..42483ff 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,9 +1,17 @@ #! /bin/sh +# If you haven't set OUTDIR, set it to the default +: ${OUTDIR:=/incoming} +export OUTDIR + log () { printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*" } -# If you haven't set OUTDIR, set it to the default -: ${OUTDIR:=/incoming} -export OUTDIR +status () { + task=$1 + status=$2 + + echo "$status" > $OUTDIR/status.$task +} + diff --git a/scripts/encoder.sh b/scripts/encoder.sh index a255766..d1cfedf 100755 --- a/scripts/encoder.sh +++ b/scripts/encoder.sh @@ -16,7 +16,7 @@ while sleep 2; do workdir=$mtype/$d [ -f $workdir/read.finished ] || continue - log "Encoding $workdir" + status "encoder" "$workdir" if ! run_in $workdir $encode; then log "$encode failed" else @@ -24,6 +24,7 @@ while sleep 2; do fi done done + status "encoder" "idle" done # vi: ts=2 sw=2 et ai diff --git a/scripts/init.sh b/scripts/init.sh index eb2917e..54f6c8c 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -4,7 +4,9 @@ cd /incoming mkdir -p audio video +busybox httpd -p 8080 -h /www nice /scripts/reader.sh & nice /scripts/encoder.sh & +nice /scripts/status.sh & wait diff --git a/scripts/reader.sh b/scripts/reader.sh index add4e57..f16d183 100755 --- a/scripts/reader.sh +++ b/scripts/reader.sh @@ -7,6 +7,7 @@ with_time_dir () { now=$(date --rfc-3339=s | tr ' ' T) mkdir -p $mtype/$now cd $mtype/$now + status "reader" "$mtype" if ! "$@"; then log "$1 failed" else @@ -29,6 +30,7 @@ while sleep 2; do *) ;; esac + status "reader" "idle" done # vi: sw=2 ts=2 et ai diff --git a/scripts/status.json.sh b/scripts/status.json.sh new file mode 100755 index 0000000..2adc897 --- /dev/null +++ b/scripts/status.json.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +. /scripts/common.sh + +cat < /www/status.json.new; then + log "Unable to render status!" + else + mv /www/status.json.new /www/status.json + fi + sleep 2 +done + diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..59474a9 --- /dev/null +++ b/www/index.html @@ -0,0 +1,60 @@ + + + + Media-Sucker + + + + + +
+
+
+ +
+
+
+
Status
+
+
+

+ Reader: + unknown + +

+

+ Encoder: + unknown + +

+
+
+
+ +
+
+
Completed Video
+
+
+
+ +
+
+
Completed Audio
+
+
+
+ +
+
+
+ + + + diff --git a/www/status.json b/www/status.json new file mode 100644 index 0000000..ba1b9e3 --- /dev/null +++ b/www/status.json @@ -0,0 +1,45 @@ +{ + "comment": "This file will be overwritten during runtime. It's only here for testing.", + "finished": { + "video": [ + "Video 1.mkv", + "Video 2.mkv", + "Video 3.mkv" + ], + "audio": [ + "Unknown_Artist/Unknown_Album_20220106.182628/01 - Track_1.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/02 - Track_2.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/03 - Track_3.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/04 - Track_4.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/05 - Track_5.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/06 - Track_6.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/07 - Track_7.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/08 - Track_8.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/09 - Track_9.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/10 - Track_10.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/11 - Track_11.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/12 - Track_12.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/13 - Track_13.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/14 - Track_14.mp3", + "Unknown_Artist/Unknown_Album_20220106.182628/15 - Track_15.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/01 - Track_1.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/02 - Track_2.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/03 - Track_3.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/04 - Track_4.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/05 - Track_5.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/06 - Track_6.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/07 - Track_7.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/08 - Track_8.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/09 - Track_9.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/10 - Track_10.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/11 - Track_11.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/12 - Track_12.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/13 - Track_13.mp3", + "Unknown_Artist/Unknown_Album_20220106.191506/14 - Track_14.mp3" + ] + }, + "status": { + "reader": "idle", + "encoder": "idle" + } +} diff --git a/www/sucker.mjs b/www/sucker.mjs new file mode 100644 index 0000000..d04907c --- /dev/null +++ b/www/sucker.mjs @@ -0,0 +1,38 @@ +const MILLISECOND = 1 +const SECOND = 1000 + +async function update() { + let resp = await fetch("status.json", {cache: "no-store"}) + let s = await resp.json() + + 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 + if (val == "idle") { + progress.value = 0 + } else { + // Removing the value makes it pulse + progress.removeAttribute("value") + } + } + + let fileItem = document.querySelector("template.panel-file-item").content + + for (let section of ["video", "audio"]) { + let e = document.querySelector(`.${section} .items`) + while (e.firstChild) e.firstChild.remove() + for (let fn of s.finished[section]) { + let item = fileItem.cloneNode(true) + item.querySelector(".filename").textContent = fn + e.append(item) + } + } +} + +setInterval(update, 2 * SECOND) +update() + +// vi: ts=2 sw=2 et ai