From 63e3670ab59869f5f74904edbe64daa943fad15f Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 26 Feb 2023 01:01:13 -0500 Subject: [PATCH] various improvements --- beet-data | 4 + brc | 1 + brc2 | 210 ++++++++++++++++++++++++------ btrbk-run | 23 ++-- distro-end | 16 ++- subdir_files/.config/mpv/mpv.conf | 10 ++ 6 files changed, 207 insertions(+), 57 deletions(-) diff --git a/beet-data b/beet-data index 5d1799e..b41b05b 100644 --- a/beet-data +++ b/beet-data @@ -191,3 +191,7 @@ for r in {3..5}; do beetapl \ sy$r rating:${r}..5 genre::$upbeat_regex ^gimicky:t ^lesser_version:t 'artist:sonic youth' done + +for t in ${nav_tags[@]}; do + beetapl $t $t:t +done diff --git a/brc b/brc index 24a437c..6389c87 100644 --- a/brc +++ b/brc @@ -224,6 +224,7 @@ export PROFILE_TASKS_TASK_OUTPUT_LIMIT=100 # i for insensitive. the rest from # X means dont remove the current screenworth of output upon exit # R means to show colors n things +# a useful flag is -F aka --quit-if-one-screen export LESS=RXij12 export SYSTEMD_LESS=$LESS diff --git a/brc2 b/brc2 index 50ca303..a8a2de7 100644 --- a/brc2 +++ b/brc2 @@ -525,35 +525,73 @@ EOF # beet playlist. use beetag with a playlist name bpl() { - eval beetag "${bpla[$1]}" + eval beetag -r "$@" "${bpla[${@: -1}]}" } complete -W "${!bpla[*]}" bpl +# beet modify quietly +beetmq() { + local tmpf + tmpf="$(mktemp)" + # a bunch of effort to ignore output we dont care about... + sed 's/^format_item:.*/format_item: ignore_this/' ~/.config/beets/config.yaml >$tmpf + beet -c $tmpf modify -y "$@" > >(grep -vFx -e 'ignore_this' -e 'Modifying 1 items.' ||:) + rm "$tmpf" + scrolled+=1 +} + +# Must be called from beetag for variables to be setup +beetag-help() { + # - 3 is just a constant that helps things work in practice. + if [[ $LINES ]] && (( LINES - 3 < scrolled )); then + hr + for (( i=0; i<${#button_map[@]}; i++)); do + if (( i % 3 == 2 )); then + printf "%s %s\n" ${buttons[i]} ${button_map[i]} + else + printf "%s %-15s" ${buttons[i]} ${button_map[i]} + fi + done + echo + cat <<'EOF' +y other genres z fg player ' = toggle play +; previous _ = delete -/+ volume ->/<- skip +EOF + hr + scrolled=10 + fi +} + # tag with beets. -# usage: beetag QUERY +# usage: beetag [-r] [-s] QUERY # it lists the query, reads an input char for tagging one by one. -# 1-5 = set rating -# a-x 0 6-9 / . , = set genre/playlist. (available buttons: ` \ ) ] [ -# q = quit -# y = toggle to setting rare genres -# z = put the player in the foreground -# enter = next song -# ' = toggle playing of songs, also replays current song if hit twice -# ; = go to previous song -# _ = delete file, remove from library -# -/+ = decrease / increase volume # # note, you may want to change the play command for doing rapid taging # by immediately jumping forward into the song. this is set in the beets # config yaml. +# +# (available buttons: ` \ ) ] [ and non-printing chars, see +# https://stackoverflow.com/questions/10679188/casing-arrow-keys-in-bash +# +# +# note: after foregrounding the player, must quit it to get back. can't ctrl-c. +# +# keys I dont need help to remember: +# 1-5 rate +# q quit +# ret next beetag() { local last_genre_i fstring tag id char new_item char_i genre tag remove doplay i j random - local do_rare_genres read_wait - local -a pl_tags buttons button_map ids tags rare_genres tmp_tags + local do_rare_genres read_wait help line lsout tmp ls_line + local escape_char escaped_input expected_input skip_input_regex + local -a pl_tags buttons button_map ids tags rare_genres tmp_tags initial_ls ls_lines local -A button_i - local -i volume + local -i i j volume scrolled id_count line_int skip_start pre_j_count head_count + + escape_char=$(printf "\u1b") + scrolled=999 # more than any $LINES ### begin arg processing ### random=false case $1 in @@ -561,6 +599,10 @@ beetag() { random=true shift ;; + -s) + random=false + shift + ;; esac if (( ! $# )); then echo beetag: error expected a query arg >&2 @@ -594,32 +636,44 @@ beetag() { for (( i=0; i<${#buttons[@]}; i++ )); do button_i[${buttons[i]}]=$i done + + # TODO: use shuf --random-source=FILE to save the random sort order + # for reusing later, so we can pickup where we left off in a playlist. + # shellcheck disable=SC2016 # obvious reason - beet ls -f '%ifdef{rating,$rating }'"$fstring"', $genre $artist - $album - $title' "$@" | head -n 100 ||: - # shellcheck disable=SC2016 # obvious reason - mapfile -t ids < <(beet ls -f '$id' "$@" | { if $random; then sort -R; else cat; fi; } ) - for (( j=0; j<${#ids[@]}; j++ )); do - hr + mapfile -t initial_ls < <(beet ls -f '$id %ifdef{rating,$rating }'"$fstring"'$genre | $artist - $album - $title $length' "$@" | { if $random; then sort -R; else cat; fi; } ) + j=0 + # i only care to see the head of the list. + head_count=$(( LINES - 14 )) + for line in "${initial_ls[@]}"; do + id="${line%% *}" + ids+=("$id") + ls_line="${line#* }" + ls_line="$ls_line $id" + ls_lines+=("$ls_line") + if (( j < head_count )); then + echo "$ls_line" + fi + j=$(( j+1 )) + done + id_count=${#ids[@]} + for (( j=0; j < id_count; j++ )); do id=${ids[j]} - # shellcheck disable=SC2016 # obvious reason - lsout="$(beet ls -f '%ifdef{rating,$rating }'"$fstring"', $genre $id $artist - $album - $title' "id:$id")" + lsout="${ls_lines[j]}" tags=( ${lsout%%,*} ) - printf "%s\n" "$lsout" - for (( i=0; i<${#button_map[@]}; i++)); do - if (( i % 3 == 2 )); then - printf "%s %s\n" ${buttons[i]} ${button_map[i]} - else - printf "%s %-15s" ${buttons[i]} ${button_map[i]} - fi - done + beetag-help + printf "██ %s\n" "$lsout" + scrolled+=1 if $doplay; then - beet play --args=--volume=$volume "id:$id" & + # https://stackoverflow.com/a/7687716 + # note: duplicated down below + { beet play "--args=--volume=$volume" "id:$id" 2>&1 & } 2>/dev/null fi while true; do char= if $doplay; then ret=0 - read -r -N 1 -s -t $read_wait char || ret=$? + read -rsN1 -t $read_wait char || ret=$? read_wait=2 # Automatically skip to the next song if this one ends, unless # we turn off the autoplay. @@ -631,35 +685,40 @@ beetag() { fi fi else - read -r -N 1 -s char + read -rsN1 char fi + beetag-help if [[ $char == $'\n' ]]; then - kill %% ||: &>/dev/null + # https://stackoverflow.com/a/5722874 + kill %%; wait %% 2>/dev/null ||: break fi case $char in ";") - kill %% ||: &>/dev/null + kill %%; wait %% 2>/dev/null ||: j=$(( j - 2 )) break ;; "'") if $doplay; then + echo "play toggled off" doplay=false else doplay=true - kill %% ||: &>/dev/null - beet play --args=--volume=$volume "id:$id" & + kill %%; wait %% 2>/dev/null ||: + { beet play "--args=--volume=$volume" "id:$id" 2>&1 & } 2>/dev/null fi + scrolled+=1 continue ;; _) - kill %% ||: &>/dev/null + kill %%; wait %% 2>/dev/null ||: m beet rm --delete --force "id:$id" + scrolled+=4 # guessing. dont want to test atm break ;; [1-5]) - beet modify -y "id:$id" rating=$char + beetmq "id:$id" rating=$char continue ;; -) @@ -668,10 +727,11 @@ beetag() { volume=0 fi echo volume=$volume + scrolled+=1 continue ;; q) - kill %% ||: &>/dev/null + kill %%; wait %% 2>/dev/null ||: return ;; +) @@ -680,6 +740,7 @@ beetag() { volume=130 fi echo volume=$volume + scrolled+=1 continue ;; y) @@ -702,6 +763,7 @@ beetag() { continue ;; z) + scrolled+=3 # if we ctrl-z, it will put the whole function into sleep. so # basically, we can't return from a foregrounded mpv like we # would like to without some strange mechanism I can't think @@ -713,6 +775,68 @@ beetag() { fi continue ;; + "$escape_char") + expected_input=true + read -rsn2 escaped_input + skip_input_regex="^[0-9]+$" + skip_back=false + case $escaped_input in + '[D') + # skip backward + if (( j == 0 )); then + echo "no earlier songs" + continue + fi + skip_back=true + { + line_int=0 + for (( i=j-1; i >= 0; i-- )); do + echo "$line_int | ${ls_lines[i]}" + line_int+=1 + done + } | less -F + scrolled+=$j + ;; + '[C') + # skip forward, but show the last few songs anyways. + skip_start=0 + if (( j - 3 > skip_start )); then + skip_start=$(( j - 3 )) + fi + { + line_int=0 + for (( i=skip_start; i < id_count; i++ )); do + if (( i == j )); then + echo " * ${ls_lines[i]}" + continue + fi + echo "$line_int | ${ls_lines[i]}" + line_int+=1 + done + } | less -F + scrolled+=$(( id_count - skip_start - 1 )) + ;; + *) + expected_input=false + ;; + esac + if $expected_input; then + read -r skip_input + if [[ $skip_input =~ $skip_input_regex ]]; then + if $skip_back; then + j=$(( j - skip_input - 2 )) + else + pre_j_count=$(( j - skip_start )) + j=$(( j + skip_input - pre_j_count )) + if (( skip_input < pre_j_count )); then + j=$(( j - 1 )) + fi + fi + kill %%; wait %% 2>/dev/null ||: + break + fi + fi + ;; esac char_i=${button_i[$char]} new_item=${button_map[$char_i]} @@ -721,7 +845,7 @@ beetag() { continue fi if (( char_i <= last_genre_i )); then - m beet modify -y "id:$id" genre=$new_item + m beetmq "id:$id" genre=$new_item else remove=false tmp_tags=() @@ -734,10 +858,10 @@ beetag() { done if $remove; then tags=("${tags[@]}") - m beet modify -y "id:$id" "$new_item!" + m beetmq "id:$id" "$new_item!" else tags+=("$new_item") - m beet modify -y "id:$id" $new_item=t + m beetmq "id:$id" $new_item=t fi fi done diff --git a/btrbk-run b/btrbk-run index dcca4b7..2eb53c1 100644 --- a/btrbk-run +++ b/btrbk-run @@ -441,16 +441,21 @@ else root_size=$(( 1024 * 1024 * 2000 )) #2tb percent_used=10 zone=$(date +%z) - elif tmpstr=$(timeout -s 9 6 ssh root@$h "mkdir -p /mnt/root/btrbk /mnt/o/btrbk && date +%z && df --output=size,pcent / | tail -n1"); then - IFS=" " read -r -a remote_info <<<"$tmpstr" - - zone=${remote_info[0]} - root_size=${remote_info[1]} - percent_used=${remote_info[2]%%%} - - if (( ${#remote_info[@]} != 3 )); then - die "error: didnt get 3 fields in test ssh to target $h. investigate" + elif remote_str=$(timeout -s 9 6 ssh root@$h "mkdir -p /mnt/root/btrbk /mnt/o/btrbk && date +%z && df --output=size,pcent / | tail -n1"); then + mapfile -t tmp_array <<<"$remote_str" + zone="${tmp_array[0]}" + IFS=" " read -r root_size percent_used <<<"${tmp_array[1]}" + percent_used=${percent_used%%%} + + if (( ${#tmp_array[@]} != 2 )); then + die "error: didnt get 2 lines in test ssh to target $h. investigate" fi + case $percent_used in + [0-9]|[1-9][0-9]) : ;; + *) + die "error: didnt get percent disk use in test ssh to target $h. investigate" + ;; + esac else sshfail+=($h) continue diff --git a/distro-end b/distro-end index 2124a7c..6b49f9b 100755 --- a/distro-end +++ b/distro-end @@ -1837,6 +1837,10 @@ EOF rm -r "$tmpdir" fi +# get rid of annoying message +s sed -ri "s/^([[:space:]]*ui.print_\('Playing)/#\1/" /usr/share/beets/beetsplug/play.py + + # notes about barrier # run barrier, do the gui config, # setup the 2 screens, using hostnames for the new screen. @@ -1956,11 +1960,6 @@ esac ### begin prometheus ### -# cleanup old files. 2023-02 -x=(/var/lib/prometheus/node-exporter/*.premerge) -if [[ -e ${x[0]} ]]; then - s rm /var/lib/prometheus/node-exporter/* -fi pi prometheus-node-exporter-collectors case $HOSTNAME in @@ -2015,6 +2014,13 @@ EOF ;; esac +# cleanup old files. 2023-02 +x=(/var/lib/prometheus/node-exporter/*.premerge) +if [[ -e ${x[0]} ]]; then + s rm /var/lib/prometheus/node-exporter/* +fi + + case $HOSTNAME in # todo, for limiting node exporter http, # either use iptables or, in diff --git a/subdir_files/.config/mpv/mpv.conf b/subdir_files/.config/mpv/mpv.conf index 8322b10..8ad1916 100644 --- a/subdir_files/.config/mpv/mpv.conf +++ b/subdir_files/.config/mpv/mpv.conf @@ -27,3 +27,13 @@ display-tags= #really-quiet # note, useful cli option: # --script-opts=osc-visibility=always + +# gets rid of lines like: +# (+) Audio --aid=1 (flac 2ch 44100Hz) +# AO: [pulse] 44100Hz stereo 2ch s16 +# and +# ffmpeg/demuxer] mp3: Estimating duration from bitrate, this may be inaccurate +# +# Found via man mpv and its suggestion to use +# --msg-level=all=trace +msg-level=cplayer=warn,ffmpeg/demuxer=error -- 2.30.2