Works, CI/CD still busted tho

This commit is contained in:
Neale Pickett 2022-05-24 17:56:07 -06:00
parent 2173760523
commit 30e64861c7
16 changed files with 6 additions and 278 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <<EOD
{
"finished": {
"video": $(ls *.mkv 2>/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

View File

@ -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

View File

@ -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