From 4ca7908c5713cf1cdd142efd54b04c08ff8b9c7b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 19 Aug 2019 15:09:50 -0400 Subject: various changes --- dot/local/bin/google | 6 +++++- dot/local/bin/hard-restart-wifi | 14 ++++++++----- dot/local/bin/lptext | 7 +++++++ dot/local/bin/musopen | 34 ++++++++++++++++++++++++++++--- dot/local/bin/selfie | 44 +++++++++++++++++++++++++++++++++++++---- 5 files changed, 92 insertions(+), 13 deletions(-) (limited to 'dot/local/bin') diff --git a/dot/local/bin/google b/dot/local/bin/google index 25604fb..94ebf0f 100755 --- a/dot/local/bin/google +++ b/dot/local/bin/google @@ -1,5 +1,9 @@ #!/usr/bin/perl -w +$useragent = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0'; $_ = join ' ', map { m/ / ? qq<"$_"> : $_ } @ARGV; s/([^a-zA-Z0-9])/sprintf "%%%x", ord $1/ge; -exec qw(w3m), "http://www.google.com/search?q=$_" +$url = "https://www.google.com/search?q=$_"; + +if ($ENV{NO_FAKE_UA}) { exec qw(w3m), "$url" } +else { exec qw(w3m -o), "user_agent=$useragent", "$url" } diff --git a/dot/local/bin/hard-restart-wifi b/dot/local/bin/hard-restart-wifi index 78f7144..52f21d3 100755 --- a/dot/local/bin/hard-restart-wifi +++ b/dot/local/bin/hard-restart-wifi @@ -10,14 +10,18 @@ with_pwd_path() "$@" } -[ $(id -u) = 0 ] || die "you are not root." - restart=$(with_pwd_path which restart-linux-device) || die "command 'restart-linux-device' is not available." +if [ $(id -u) = 0 ]; then + sudo= +else + sudo=sudo +fi + dev=${1:-$default_dev} rawdev=${dev%=*} [ "$VERBOSE" ] && set -x -$restart $rawdev -ifdown --force $rawdev # It's not clear to me why this is necessary, but it is. -ifup $dev +$sudo $restart $rawdev +$sudo ifdown --force $rawdev # It's not clear to me why this is necessary, but it is. +$sudo ifup $dev diff --git a/dot/local/bin/lptext b/dot/local/bin/lptext index 064e98e..645e4a4 100755 --- a/dot/local/bin/lptext +++ b/dot/local/bin/lptext @@ -1,2 +1,9 @@ #!/bin/sh +case "$1" in + -*|'') ;; + *) echo "Warning: $0: ignoring stdin and using first argument as input ($1)" >&2 + exec < "$1" + shift + ;; +esac text2png | lp "$@" diff --git a/dot/local/bin/musopen b/dot/local/bin/musopen index 3ed9962..7d007fb 100755 --- a/dot/local/bin/musopen +++ b/dot/local/bin/musopen @@ -1,5 +1,26 @@ #!/bin/sh +usage() +{ + cat <&2 + DO_SAVE= +else + printf '%s: %s - %s\n' "${DO_SAVE+Saving}${DO_SAVE-Playing}" "$composer" "$title" >&2 +fi + -exec mpv "$STREAM_URL" ${CAPTURE_NAME+ --stream-capture="$CAPTURE_NAME"} +exec mpv "$STREAM_URL" ${DO_SAVE+ --stream-capture="$CAPTURE_NAME"} diff --git a/dot/local/bin/selfie b/dot/local/bin/selfie index 9fa2a45..ef0adb2 100755 --- a/dot/local/bin/selfie +++ b/dot/local/bin/selfie @@ -1,24 +1,60 @@ #!/bin/bash +video_devices() +{ + v4l2-ctl --list-devices | sed -ne 's/^\t//p' +} + AUDIO_DEVICE=pulse -VIDEO_DEVICE=/dev/video0 +VIDEO_DEVICE=$(video_devices | head -n1) + +[ "$VIDEO_DEVICE" ] || exit 1 MAX_RECORDING_TIME=00:05:00 +[ "$RECORD_FOREVER" ] && unset MAX_RECORDING_TIME NOW=$(date -Iseconds) OUTPUT=recording.${NOW//[:T]/.}.avi OUTPUT_LINK=recording.latest.avi +XVID_QUALITY=10 + +info() +{ + ffmpeg -hide_banner -f v4l2 -list_formats all -i "$VIDEO_DEVICE" + v4l2-ctl --list-formats-ext + + # Such commands as these do nothing. ffmpeg overrides them. + #v4l2-ctl --set-fmt-video=width=800,height=600,pixelformat=MJPG + #v4l2-ctl --set-fmt-video=width=1600,height=1200,pixelformat=MJPG +} + +# The higher resolution matches the display, and so fills the screen while +# recording, but the field of view is larger in the 800x600 resolution, which +# also supports a higher framerate. Thus 800x600 seems like the "natural" +# resolution of the camera. Though, it is still quite low. :( + +V4L2_OPTIONS='-input_format mjpeg -framerate 30 -video_size 800x600' +# V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1280x800' +# V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1600x1200' + +drawtext='text=%{pts\\:hms}:x=5:y=h-lh-5:fontsize=18:fontcolor=white:box=1:boxcolor=0x00000099' record() { local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" ffmpeg -hide_banner -loglevel error -stats \ - $timeout -f video4linux2 -i "$VIDEO_DEVICE" \ + $timeout -f video4linux2 ${V4L2_OPTIONS} -i "$VIDEO_DEVICE" \ $timeout -f "$AUDIO_DEVICE" -i default \ - -c:v rawvideo -pix_fmt yuv420p -f xv win \ - -c:a mp3 \ + \ + -c:v rawvideo \ + -vf scale=iw/2:ih/2,drawtext="${drawtext}" \ + -pix_fmt yuv420p \ + -f xv selfie \ + \ -c:v libxvid \ + -c:a libmp3lame \ + -q:v $XVID_QUALITY \ "$1" } -- cgit v1.2.3