]> Freerunner's - dotfiles.git/commitdiff
local: rnd helper scripts
authorAndre Ramnitz <tux.rising@gmail.com>
Sat, 8 Jun 2024 00:43:00 +0000 (02:43 +0200)
committerAndre Ramnitz <tux.rising@gmail.com>
Sun, 18 Aug 2024 16:18:53 +0000 (18:18 +0200)
local/bin/albumart_ncmpcpp [new file with mode: 0755]
local/bin/albumart_ncmpcpp2 [new file with mode: 0755]
local/bin/bin2hex [new file with mode: 0755]
local/bin/upgrayyedd [new file with mode: 0755]

diff --git a/local/bin/albumart_ncmpcpp b/local/bin/albumart_ncmpcpp
new file mode 100755 (executable)
index 0000000..663bca0
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Script intended to be executed from ncmpcpp (execute_on_song_change
+# preference) running from urxvt to set album cover as background image
+
+# Copyright (c) 2013  Vyacheslav Levit
+# Licensed under The MIT License: http://opensource.org/licenses/MIT
+
+MUSIC_DIR="/mnt/multimedia/Musik"
+DARKEN=50         # 0 - original image colors, 100 - absolutely black background
+
+TMP=/tmp
+COVER=/tmp/cover.jpg
+IM_ARGS=(-limit memory 32mb -limit map 64mb)
+
+function reset_background
+{
+    # is there any better way?
+    printf "\e]20;;100x100+1000+1000\a"
+}
+
+{
+    album="$(mpc --format %album% current)"
+    file="$(mpc --format %file% current)"
+    album_dir="${file%/*}"
+    [[ -z "$album_dir" ]] && exit 1
+    album_dir="$MUSIC_DIR/$album_dir"
+
+    covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)" \; )"
+    src="$(echo -n "$covers" | head -n1)"
+    darkenimg="$TMP/darken.jpg"
+    rm -f "$COVER" "$darkenimg"
+    if [[ -n "$src" ]] ; then
+        light="$((100 - $DARKEN))"
+        convert "${IM_ARGS[@]}" "$src" -fill "gray${light}" +level ${light}%,${light}% \
+            +matte "$darkenimg"
+        composite "${IM_ARGS[@]}" "$darkenimg" -compose Multiply "$src" "$COVER"
+        if [[ -f "$COVER" ]] ; then
+            bgcolor=$(convert "${IM_ARGS[@]}" "$COVER" -scale 1x1 -format \
+                '%[fx:int(255*r+.5)] %[fx:int(255*g+.5)] %[fx:int(255*b+.5)]' info:-)
+            for c in $bgcolor ; do
+                bghex=$bghex/$(printf %02x $c)
+            done
+            bghex=${bghex:1}
+
+            printf "\e]11;rgb:${bghex}\a"
+            printf "\e]708;rgb:${bghex}\a"
+            printf "\e]20;${COVER};100x100+50+50:op=keep-aspect\a"
+        else
+            reset_background
+        fi
+    else
+        reset_background
+    fi
+} &
+
diff --git a/local/bin/albumart_ncmpcpp2 b/local/bin/albumart_ncmpcpp2
new file mode 100755 (executable)
index 0000000..4b2b280
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+XDG_DATA_HOME="$HOME/.local/share"
+
+music_dir="/mnt/multimedia/Musik"
+previewdir="$XDG_DATA_HOME/ncmpcpp"
+filename="$(mpc --format "$music_dir"/%file% current)"
+previewname="$previewdir/$(mpc --format %album% current | base64).png"
+
+[ -e "$previewname" ] || ffmpeg -y -i "$filename" -an -vf scale=256:256 "$previewname" > /dev/null 2>&1
+
+notify-send -r 27072 "Now Playing" "$(mpc --format '%title% \n%artist% - %album%' current)" -i "$previewname"
diff --git a/local/bin/bin2hex b/local/bin/bin2hex
new file mode 100755 (executable)
index 0000000..3e5b384
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+bin2hex() {
+       echo "obase=16;ibase=2;$1"|bc
+}
+
diff --git a/local/bin/upgrayyedd b/local/bin/upgrayyedd
new file mode 100755 (executable)
index 0000000..60d2dca
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+case "$1" in
+    refresh)
+        doas emaint sync -A
+        doas emerge -avuDN @world
+        ;;
+    log)
+        cat /var/log/emerge.log | grep -i --color=auto -i "completed"
+        echo "use: date -d @[unixtime] to convert the timestamp"
+        ;;
+    clean)
+        doas emerge -a --depclean
+        ;;
+    *)
+        doas emerge -avuDN @world
+        ;;
+esac
+