X-Git-Url: https://git.madduck.net/code/pulserecorder.git/blobdiff_plain/7cd55a11575980fba5232c781b41fab469d00ec7..92376471ab255fa21a70a02cb16e2436c8bd058e:/pulserecorder diff --git a/pulserecorder b/pulserecorder index a9f4cdc..7d3860e 100755 --- a/pulserecorder +++ b/pulserecorder @@ -15,7 +15,7 @@ # # The third form waits for a new sink-input to appear, and will record that. # -# Copyright © 2020 martin f. krafft +# Copyright © 2020–2021 martin f. krafft # Released under the teams of the Artistic Licence 2.0 # set -eu @@ -44,6 +44,10 @@ export TMPDIR TMPDIR=$(mktemp -dp "$TMPDIR" parec.XXXXXXXXXX) cleanup_hook rm -r $TMPDIR +if command -v systemd-inhibit >/dev/null; then + systemd-inhibit --who=pulserecorder --why=recording sleep 99d 2>/dev/null & + cleanup_hook kill $! +fi state= outfile= index= clobber=0 for arg in "$@"; do @@ -68,7 +72,7 @@ pa_wait_for_event() { type="${1:-*}" event="${2:-*}" id="${3:-*}" pa_subscribe | ( read pid - #echo >&2 pa_subscribe started with PID $pid + #echo >&2 pa_subscribe started with PID $pid, waiting for $type/$event/$id while read lead xevent on xtype xid; do xid=${xid#\#} #echo >&2 "pa_subscribe: $xtype/$xevent/$xid ($type/$event/$id)" @@ -87,6 +91,28 @@ pa_get_next_index() { } } +uuidgen() { + hascmd() { command -v "$@" >/dev/null;} + if hascmd uuid; then uuid + elif hascmd uuidgen; then uuidgen + elif hascmd python3; then + python3 -c 'import uuid; print(uuid.uuid1())' + elif hascmd python; then + python -c 'import uuid; print(uuid.uuid1())' + else + dd if=/dev/urandom bs=16 count=1 status=none | base64 + fi +} + +if [ -z "$outfile" ]; then + uuid=$(uuidgen) + outfile="${uuid}.ogg" +fi + +if [ -f "$outfile" ] && [ $clobber -eq 0 ]; then + echo >&2 "E: file exists, and -f not given: $outfile" + exit 1 +fi case "$index" in (last) @@ -113,29 +139,7 @@ if [ -z "$index" ]; then exit 1 fi -uuidgen() { - hascmd() { command -v "$@" >/dev/null;} - if hascmd uuid; then uuid - elif hascmd uuidgen; then uuidgen - elif hascmd python3; then - python3 -c 'import uuid; print(uuid.uuid1())' - elif hascmd python; then - python -c 'import uuid; print(uuid.uuid1())' - else - dd if=/dev/urandom bs=16 count=1 status=none | base64 - fi -} - -uuid=$(uuidgen) - -[ -n "$outfile" ] || outfile="${uuid}.ogg" - -if [ -f "$outfile" ] && [ $clobber -eq 0 ]; then - echo >&2 "E: file exists, and -f not given: $outfile" - exit 1 -fi - -devname="record-to-file-${uuid}" +devname="record-to-file-$(echo -n ${outfile%.*} | tr -c '[:alnum:]' '_')" echo >&2 "Recording source $index to $outfile …"