From 30e64861c757d694e9f60547eef64af023621dbe Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 24 May 2022 17:56:07 -0600 Subject: [PATCH] Works, CI/CD still busted tho --- Dockerfile | 4 ++-- README.md | 38 ++++------------------------- scripts/audio.encode.sh | 10 -------- scripts/cd.audio.read.sh | 12 ---------- scripts/common.sh | 28 ---------------------- scripts/dvd.video.read.sh | 39 ------------------------------ scripts/encoder.sh | 31 ------------------------ scripts/init.sh | 12 ---------- scripts/reader.sh | 44 ---------------------------------- scripts/status.json.sh | 29 ---------------------- scripts/status.sh | 13 ---------- scripts/video.encode.sh | 24 ------------------- encoder.py => src/encoder.py | 0 reader.py => src/reader.py | 0 statuser.py => src/statuser.py | 0 sucker.py => src/sucker.py | 0 16 files changed, 6 insertions(+), 278 deletions(-) delete mode 100755 scripts/audio.encode.sh delete mode 100755 scripts/cd.audio.read.sh delete mode 100755 scripts/common.sh delete mode 100755 scripts/dvd.video.read.sh delete mode 100755 scripts/encoder.sh delete mode 100755 scripts/init.sh delete mode 100755 scripts/reader.sh delete mode 100755 scripts/status.json.sh delete mode 100755 scripts/status.sh delete mode 100755 scripts/video.encode.sh rename encoder.py => src/encoder.py (100%) rename reader.py => src/reader.py (100%) rename statuser.py => src/statuser.py (100%) rename sucker.py => src/sucker.py (100%) diff --git a/Dockerfile b/Dockerfile index 174973a..b5e232f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,10 +27,10 @@ RUN true \ moreutils \ cowsay -COPY sucker.py /usr/bin +COPY src/* /app/ COPY abcde.conf httpd.conf /etc/ COPY --chown=linuxserver:linuxserver www /www USER linuxserver -ENTRYPOINT ["/usr/bin/sucker.py"] +ENTRYPOINT ["python3", "/app/sucker.py"] # vi: ts=2 sw=2 et ai diff --git a/README.md b/README.md index 8fd8504..16ac18b 100644 --- a/README.md +++ b/README.md @@ -16,40 +16,10 @@ At the time I'm writing this README, it will: ## How To Run This -First you have to build it. -It will build on a raspberry pi. +You need a place to store your stuff. +Mine is `/srv/ext/incoming`. - docker build --tag=media-sucker . - -You'll need a place to store all your precious media: - - incoming=/path/to/incoming - mkdir -P $incoming - chown 911:911 $incoming - -Then you can run it: - - docker run -d --restart=unless-stopped \ - --name=sucker \ - --device cdrom --device dvd --device sr0 \ - -v $incoming:/incoming \ - -p 5880:8080 \ - media-sucker - -Or you can put it in a `docker-compose.yaml` file: - -```yaml -services: - sucker: - image: media-sucker - volumes: - - type: bind - source: /path/to/incoming - target: /incoming - ports: - - published: 5880 - target: 8080 -``` + docker run -d -p 8080:8080 --device /dev/sr0 -v /srv/ext/incoming:/incoming registry.gitlab.com/dartcatcher/media-sucker/media-sucker Stick a video DVD or audio CD in, and the drive should spin up for a while, @@ -57,7 +27,7 @@ then spit your media back out. Then, eventually, you'll have a new `.mkv` file (for video) or a new directory of `.mp3` files (for audio). -You can watch what it's doing at http://localhost:5880/ +You can watch what it's doing at http://localhost:8080/ ## A note on filenames and tags diff --git a/scripts/audio.encode.sh b/scripts/audio.encode.sh deleted file mode 100755 index 8b76e18..0000000 --- a/scripts/audio.encode.sh +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/sh - -. $(dirname $0)/common.sh - -discid=$(getenv discid) - -abcde -C $discid -o mp3:-V2 -cp -r mp3/* $OUTDIR - -# vi: sw=2 ts=2 et ai diff --git a/scripts/cd.audio.read.sh b/scripts/cd.audio.read.sh deleted file mode 100755 index 29a5c15..0000000 --- a/scripts/cd.audio.read.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/sh - -setenv status "ripping" -abcde -N -a cddb,read - -discid=$(cd-discid | awk '{print $1}') -setenv discid "$discid" -now=$(getenv time) - -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 deleted file mode 100755 index 6a8b26e..0000000 --- a/scripts/common.sh +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/sh - -# If you haven't set OUTDIR, set it to the default -: ${OUTDIR:=/incoming} -export OUTDIR - -# This gets set to the directory containing what's currently running -: ${SCRIPTS:=$(dirname $0)} - -log () { - printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*" -} - -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' \ - > env.json.new \ - && mv env.json.new env.json -} - -status () { - echo "$2" > status.$1.new - mv status.$1.new status.$1 -} diff --git a/scripts/dvd.video.read.sh b/scripts/dvd.video.read.sh deleted file mode 100755 index 05b986e..0000000 --- a/scripts/dvd.video.read.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /bin/sh -e - -. $(dirname $0)/common.sh - -log "Scanning for DVD title" -title=$(dvdbackup -I | awk -F \" '/DVD with title/ {print $2}') -setenv title "$title" - -# How big is this DVD? -totalSize=$(dvdbackup -I | awk '/[MK]iB$/ { b += $2 } END { print b }') - -dvdbackup -p -F -n DVD \ -| tr '\r' '\n' \ -| awk -v total=$totalSize -F '[ /:()]+' ' - function update(bytes) { - pct = 100 * bytes / total - if (pct >= nextpct) { - print pct - fflush() - nextpct = pct + 0.5 - } - } - - /[MK]iB.$/ { - read = $(NF-3) * 1024 - if ($(NF-1) == "MiB") { - read *= 1024 - } - if (read < last) { - totalRead += last - } - update(totalRead + read) - last = read - } - ' \ -| while read val; do - setenv complete "$val" -done - diff --git a/scripts/encoder.sh b/scripts/encoder.sh deleted file mode 100755 index a8dd4db..0000000 --- a/scripts/encoder.sh +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/sh - -. $(dirname $0)/common.sh - -while sleep 2; do - status encoder idle - for mtype in audio video; do - ls $mtype | while read d; do - encode=$SCRIPTS/$mtype.encode.sh - workdir=$mtype/$d - status=$(cd $workdir && getenv status) - case "$status" in - "encoding") - (cd $workdir && setenv status "encode interrupted") - ;; - "read finished") - status encoder encoding - (cd $workdir && setenv status "encoding") - if ! (cd $workdir && $encode); then - log "$encode failed" - (cd $workdir && setenv status "encode failed") - else - rm -rf $workdir - fi - ;; - esac - done - done -done - -# vi: ts=2 sw=2 et ai diff --git a/scripts/init.sh b/scripts/init.sh deleted file mode 100755 index 54f6c8c..0000000 --- a/scripts/init.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/sh -e - -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 deleted file mode 100755 index 273c3a3..0000000 --- a/scripts/reader.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/sh - -. $(dirname $0)/common.sh - -with_time_dir () { - mtype=$1; shift - now=$(date --rfc-3339=s | tr ' ' T) - dir="$mtype/$now" - mkdir -p "$dir" - cd "$dir" - - setenv time "$now" - setenv mtype "$mtype" - setenv directory "$dir" - setenv status "reading" - - tatusreader "$mtype" - if ! "$@"; then - log "$1 failed" - setenv status "read failed" - else - log "$1 succeeded" - setenv status "read finished" - eject - fi -} - -while sleep 2; do - status reader idle - case $(setcd -i) in - *"Disc found in drive: audio"*) - log "Found audio disc" - ( with_time_dir audio /scripts/cd.audio.read.sh ) - ;; - *"Disc found in drive: data"*) - log "Found DVD" - ( with_time_dir video /scripts/dvd.video.read.sh ) - ;; - *) - ;; - esac -done - -# vi: sw=2 ts=2 et ai diff --git a/scripts/status.json.sh b/scripts/status.json.sh deleted file mode 100755 index ca952a8..0000000 --- a/scripts/status.json.sh +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/sh - -set -x # Why the heck is this eating 100% CPU in an unkillable state? - -. $(dirname $0)/common.sh - -queue () { - find audio video -name env.json \ - | while read envjson # This is the line that's dying at 100% CPU - 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]') - } -} -EOD diff --git a/scripts/status.sh b/scripts/status.sh deleted file mode 100755 index 9284df1..0000000 --- a/scripts/status.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh - -. $(dirname $0)/common.sh - -while true; do - if ! /scripts/status.json.sh > /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/scripts/video.encode.sh b/scripts/video.encode.sh deleted file mode 100755 index bbd7d6c..0000000 --- a/scripts/video.encode.sh +++ /dev/null @@ -1,24 +0,0 @@ -#! /bin/sh -e - -. $(dirname $0)/common.sh - -title=$(getenv title) - -HandBrakeCLI \ - --json \ - -i DVD/VIDEO_TS \ - --main-feature \ - --native-language eng \ - -Z "Chromecast 1080p30 Surround" \ - -o "${title}.mkv" \ - 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" - -# vi: sw=2 ts=2 et ai diff --git a/encoder.py b/src/encoder.py similarity index 100% rename from encoder.py rename to src/encoder.py diff --git a/reader.py b/src/reader.py similarity index 100% rename from reader.py rename to src/reader.py diff --git a/statuser.py b/src/statuser.py similarity index 100% rename from statuser.py rename to src/statuser.py diff --git a/sucker.py b/src/sucker.py similarity index 100% rename from sucker.py rename to src/sucker.py