X-Git-Url: https://git.madduck.net/code/pulserecorder.git/blobdiff_plain/0419e8fbc114f36a087acd8ea6de65cbfcfec788..4854b887e565b8cab682819affd25fdb9d8f45de:/pulserecorder?ds=sidebyside diff --git a/pulserecorder b/pulserecorder index 211c6d5..5dad254 100755 --- a/pulserecorder +++ b/pulserecorder @@ -91,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) @@ -117,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 …" @@ -152,13 +152,23 @@ load_module() { } move_source_to_sink() { - local c; + local c d; c=$(pactl list short sink-inputs | sed -rne "s,^${1}[[:space:]]+([[:digit:]]+).+,\1,p") + d="$(pactl list short sinks | sed -rne "s,^${c}[[:space:]]+([^[:space:]]+).+,\1,p")" + case "$d" in + (record-to-file-*) + # Never restore to a record-to-file destination, or it could botch + # another recording + c="@DEFAULT_SINK@" + ;; + (*) :;; + esac + echo >&2 "Moving input $1 to sink $2 (restore to $c) …" cleanup_hook pactl move-sink-input $1 $c pactl move-sink-input $1 $2 } -if false; then +if [ -n "${PAREC_PIPE:-}" ]; then # This would be great, but it does not work. For instance, trying this on # audible meant that audible would play at maximum speed (3h played in 3 # minutes), but the result would be full of skips, making me think that @@ -167,8 +177,11 @@ if false; then load_module module-pipe-sink "$devname" "$devname" file="$TMPDIR/outfifo" move_source_to_sink $index "$devname" - oggenc --raw -q5 -o "$outfile" "$TMPDIR/outfifo" || : - #pv -pterb "$TMPDIR/outfifo" > $TMPDIR/outfile.wav || : + #oggenc --raw -q5 -o "$outfile" "$TMPDIR/outfifo" || : + pv -pterb "$TMPDIR/outfifo" > $TMPDIR/outfile.wav & + pid=$! + pa_wait_for_event sink-input remove $index >/dev/null + kill $pid else # More traditional approach, which just takes 1:1 time.