diff --git a/Dockerfile b/Dockerfile index 44e35cd..8d841e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ RUN true \ busybox \ jq \ procps \ + moreutils \ cowsay COPY scripts /scripts diff --git a/TODO.md b/TODO.md index fe23fdf..31881b6 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/scripts/audio.encode.sh b/scripts/audio.encode.sh index 865bae8..8b76e18 100755 --- a/scripts/audio.encode.sh +++ b/scripts/audio.encode.sh @@ -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 diff --git a/scripts/cd.audio.read.sh b/scripts/cd.audio.read.sh index 902a4ec..29a5c15 100755 --- a/scripts/cd.audio.read.sh +++ b/scripts/cd.audio.read.sh @@ -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 <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 diff --git a/scripts/common.sh b/scripts/common.sh index 42483ff..f0bcaf9 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -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 } diff --git a/scripts/dvd.video.read.sh b/scripts/dvd.video.read.sh index 7354af7..a30f486 100755 --- a/scripts/dvd.video.read.sh +++ b/scripts/dvd.video.read.sh @@ -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 <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 diff --git a/scripts/encoder.sh b/scripts/encoder.sh index d1cfedf..10b0222 100755 --- a/scripts/encoder.sh +++ b/scripts/encoder.sh @@ -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 diff --git a/scripts/reader.sh b/scripts/reader.sh index f16d183..72c88b6 100755 --- a/scripts/reader.sh +++ b/scripts/reader.sh @@ -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 diff --git a/scripts/status.json.sh b/scripts/status.json.sh index 3b579df..c34ff13 100755 --- a/scripts/status.json.sh +++ b/scripts/status.json.sh @@ -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 </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 diff --git a/scripts/status.sh b/scripts/status.sh index efbed0d..9284df1 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -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 diff --git a/scripts/video.encode.sh b/scripts/video.encode.sh index 423b4cc..d0fa0c3 100755 --- a/scripts/video.encode.sh +++ b/scripts/video.encode.sh @@ -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