diff options
| author | marcellus <msimon_fr@hotmail.com> | 2023-05-02 18:30:47 +0200 |
|---|---|---|
| committer | marcellus <msimon_fr@hotmail.com> | 2023-05-02 18:30:47 +0200 |
| commit | 7e1032434d90db737e319d3eb21721b7fed388be (patch) | |
| tree | 292b4bc560edd33f1fbcd9655c9b76b49b75b404 /scripts | |
| parent | 7d1e4e8fbcb57d7e3b04f730f6e51c0e00b76456 (diff) | |
add: scripts from ratakor's repo
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/dmenuhandler | 40 | ||||
| -rwxr-xr-x | scripts/dmenuoff | 15 | ||||
| -rwxr-xr-x | scripts/music | 30 | ||||
| -rwxr-xr-x | scripts/musiccmd | 116 | ||||
| -rwxr-xr-x | scripts/screenshot | 11 | ||||
| -rw-r--r-- | scripts/test | 1 | ||||
| -rwxr-xr-x | scripts/ytdl | 33 |
7 files changed, 246 insertions, 0 deletions
diff --git a/scripts/dmenuhandler b/scripts/dmenuhandler new file mode 100755 index 0000000..b3eb9c8 --- /dev/null +++ b/scripts/dmenuhandler @@ -0,0 +1,40 @@ +#!/bin/sh +# Feed this script a link and it will give dmenu +# some choice programs to use to open it. + +FEED="${1:-$(printf "" | dmenu -p 'Paste URL or file path')}" + +[ -z "$FEED" ] && exit + +case "$(printf '%s\nbrowser\nmusic\nmpv\nmpv loop\nnsxiv\nPDF\nvim\nyt-dlp\nmusic-dlp' "$FEED" | dmenu -i -p "Open with ")" in + "$FEED") + printf '%s\n' "$FEED" | xclip -selection clipboard ;; # Copy URL + browser) + setsid -f "$BROWSER" "$FEED" >/dev/null 2>&1 ;; + music) + setsid -f music "$FEED" >/dev/null 2>&1 ;; + mpv) + setsid -f mpv --quiet --ytdl-format="bv,ba" "$FEED" >/dev/null 2>&1 ;; + "mpv loop") + setsid -f mpv --quiet --ytdl-format="bv,ba" --loop "$FEED" >/dev/null 2>&1 ;; + nsxiv) + curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" && + nsxiv -a "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + PDF) + curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" && + zathura "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + vim) + curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" && + setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + yt-dlp) + setsid -f ytdl v "$FEED" >/dev/null 2>&1 ;; + music-dlp) + if [ "$(printf 'no\nyes' | dmenu -i -p 'Playlist?')" = "yes" ]; then + setsid -f ytdl p "$FEED" >/dev/null 2>&1 + else + setsid -f ytdl m "$FEED" >/dev/null 2>&1 + fi + #setbg) + # curl -sL "$FEED" > "$XDG_CACHE_HOME/pic" && + # hsetroot -cover "$XDG_CACHE_HOME/pic" >/dev/null 2>&1 ;; +esac
\ No newline at end of file diff --git a/scripts/dmenuoff b/scripts/dmenuoff new file mode 100755 index 0000000..e278c8a --- /dev/null +++ b/scripts/dmenuoff @@ -0,0 +1,15 @@ +#!/bin/sh +# menu for shutdown or lock +# require nopass for poweroff and reboot and my build of dmenu for -hf + +QUERY=$(printf 'no\nlock\npoweroff\nreboot' | dmenu -i -sb '#cc241d' -hf '#689d6a' -p 'Shutdown?') +ROOTCMD="${ROOTCMD:-$(command -v doas || command -v sudo)}" + +case "$QUERY" in +"lock") + slock ;; +"poweroff") + "$ROOTCMD" poweroff ;; +"reboot") + "$ROOTCMD" reboot ;; +esac
\ No newline at end of file diff --git a/scripts/music b/scripts/music new file mode 100755 index 0000000..42ceeeb --- /dev/null +++ b/scripts/music @@ -0,0 +1,30 @@ +#!/bin/sh +# simple music selector with dmenu that uses and interacts with mpv +# have a look at musiccmd, dwmblocks/sb_music and .local/etc/mpv/music +# shellcheck disable=SC2012 + +MUSICDIR="${XDG_MUSIC_DIR:-$HOME/music}" + +if [ "$1" = "--shuffle" ]; then + SHUFFLE=yes + shift +fi + +MUSIC="${1:-$MUSICDIR/$(ls "$MUSICDIR" | dmenu -i -p "Play ")}" +SCRIPT="$XDG_CONFIG_HOME/mpv/music/local.lua" + +if [ "$MUSIC" = "$MUSICDIR/urls" ]; then + MUSIC="$(cat "$MUSICDIR/urls/$(ls "$MUSICDIR/urls" | dmenu -i -p "Play ")")" + SCRIPT="$XDG_CONFIG_HOME/mpv/music/online.lua" +fi + +[ "$MUSIC" = "$MUSICDIR/" ] || [ -z "$MUSIC" ] && exit 1 + +if [ -z "$SHUFFLE" ] && [ -d "$MUSIC" ] || printf '%s' "$MUSIC" | grep -q playlist; then + SHUFFLE="$(printf 'yes\nno' | dmenu -i -p 'Shuffle?')" + [ -z "$SHUFFLE" ] && exit 1 +fi + +printf 'stop\n' | socat - /tmp/mpvsocket 2> /dev/null +mpv --vid=no --input-ipc-server=/tmp/mpvsocket --loop-playlist --volume=75\ + --ytdl-format="wv*+ba" --script="$SCRIPT" --shuffle="$SHUFFLE" "$MUSIC" diff --git a/scripts/musiccmd b/scripts/musiccmd new file mode 100755 index 0000000..73c961b --- /dev/null +++ b/scripts/musiccmd @@ -0,0 +1,116 @@ +#!/bin/sh +# helper for the music script +# dependencies: music, mpv, socat, yt-dlp, ffmpeg, imagemagick +# optional dependencies: dwmblocks, libnotify, herbe + +FAVDIR="${XDG_MUSIC_DIR:-$HOME/Music}/favorite" +DLDIR="${XDG_MUSIC_DIR:-$HOME/Music}/download" +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" +IMG="nsxiv" + +getpath() { + tmp="$(printf '{ "command": ["get_property", "path"] }\n'\ + | socat - /tmp/mpvsocket)" + tmp="${tmp#{\"data\":\"}" + path="${tmp%\",\"request_id\":0,\"error\":\"success\"\}}" +} + +getvol() { + tmp="$(printf '{ "command": ["get_property", "volume"] }\n'\ + | socat - /tmp/mpvsocket)" + tmp="${tmp#{\"data\":}" + printf '%s\n' "${tmp%.000000,\"request_id\":0,\"error\":\"success\"\}}" +} + +download() { + mkdir -p "$1" + notify-send "Downloading '$path' to '$1'" + if yt-dlp -f "ba" -x --embed-thumbnail --audio-format mp3\ + -o"%(title)s [%(id)s].%(ext)s" -P "$1" "$path"; then + notify-send "'$path' successfuly downloaded to '$2'" + return 0 + else + notify-send "Error: '$path' couldn't be downloaded" + return 1 + fi +} + +addtofav() { + case $path in + *youtube.com*) + download "$FAVDIR" ;; + *) + mkdir -p "$FAVDIR" + if cp "$path" "$FAVDIR"; then + notify-send "'$path' was copied to '$FAVDIR'" + return 0 + else + notify-send "'$path' couldn't be copied to '$FAVDIR'" + return 1 + fi ;; + esac +} + +getthumbnail() { + mkdir -p "$CACHE" + case $path in + *youtube.com*) + yt-dlp --skip-download --force-overwrites --write-thumbnail\ + -o "$CACHE/thumbnail" "$path" > /dev/null 2>&1 &&\ + magick "$CACHE/thumbnail.webp" "$CACHE/thumbnail.jpg" ;; + *) + ffmpeg -y -i "$path" "$CACHE/thumbnail.jpg" 2> /dev/null ;; + esac +} + + +main() { + if ! pgrep -x music >/dev/null; then + kill -35 "$(pidof dwmblocks)" + herbe "Error: There is no music playing"\ + "Do you want to play some ?" && + music + return 1 + fi + + cmd="${1:-$(printf '⏯️pause/play\n⏭️next\n⏮️prev\n📢volume\n🔳stop +⭐favorite\n⬇️download\n🖼️thumbnail' | dmenu -i -p "musiccmd")}" + + case "$cmd" in + cycle|*pause|*play) + printf 'cycle pause\n' | socat - /tmp/mpvsocket + kill -35 "$(pidof dwmblocks)" ;; + *next) + printf 'playlist-next\n' | socat - /tmp/mpvsocket ;; + *prev) + printf 'playlist-prev\n' | socat - /tmp/mpvsocket ;; + *volume) + printf '{ "command": ["set_property", "volume", %s] }\n'\ + "${2:-$(true | dmenu -p "Current volume: $(getvol)")}"\ + | socat - /tmp/mpvsocket 1> /dev/null ;; + *stop) + printf 'stop\n' | socat - /tmp/mpvsocket + kill -35 "$(pidof dwmblocks)" ;; + *favorite|fav) + getpath + addtofav ;; + *download) + getpath + download "$DLDIR" ;; + *thumbnail) + getpath + if getthumbnail; then + $IMG "$CACHE/thumbnail.jpg" + else + notify-send "Error: can't get thumbnail" + return 1 + fi ;; + path) + getpath + printf '%s\n' "$path" ;; + vol) + getvol ;; + esac +} + +main "$@"
\ No newline at end of file diff --git a/scripts/screenshot b/scripts/screenshot new file mode 100755 index 0000000..8226205 --- /dev/null +++ b/scripts/screenshot @@ -0,0 +1,11 @@ +#!/bin/sh + +OUTPUT="$XDG_PICTURES_DIR/screenshots/$(date '+%Y-%m-%d_%H:%M:%S').png" +XCLIPCMD="xclip -sel clip -t image/png" + +case "$(printf "save select\nsave screen\ncopy select\ncopy screen" | dmenu -i -p "Screenshot")" in + "copy screen") maim -q -u -d 0.5 | $XCLIPCMD ;; + "save select") maim -u -s "$OUTPUT" ;; + "save screen") maim -q -u -d 0.5 "$OUTPUT" ;; + "copy select") maim -u -s | $XCLIPCMD ;; +esac diff --git a/scripts/test b/scripts/test new file mode 100644 index 0000000..999bef1 --- /dev/null +++ b/scripts/test @@ -0,0 +1 @@ +fzdlfhzdk
\ No newline at end of file diff --git a/scripts/ytdl b/scripts/ytdl new file mode 100755 index 0000000..e69cf26 --- /dev/null +++ b/scripts/ytdl @@ -0,0 +1,33 @@ +#!/bin/sh +# wrapper for yt-dlp + +MUSICDIR="${XDG_MUSIC_DIR:-$HOME/Music}" +VIDEODIR="${XDG_VIDEOS_DIR:-$HOME/Videos}" + +case $1 in +v) + mkdir -p "$VIDEODIR" + notify-send "Video download started" + yt-dlp -f 'bv,ba' -o '%(title)s [%(id)s].%(ext)s'\ + -P "$VIDEODIR" "$2" && + notify-send "Video downloaded" || + (notify-send "Error: No internet connection" && exit 1) ;; +m) + mkdir -p "$MUSICDIR/download" + notify-send "Music download started" + yt-dlp -f 'ba' -x --embed-thumbnail --audio-format mp3\ + -o '%(title)s [%(id)s].%(ext)s' -P "$MUSICDIR/download" "$2" && + notify-send "Music downloaded" || + (notify-send "Error: No internet connection" && exit 1) ;; +p) + NAME=$(printf '' | dmenu -p 'Name ') + mkdir -p "$MUSICDIR/$NAME" + notify-send "Playlist download started" + yt-dlp -f 'ba' -x --embed-thumbnail --audio-format mp3\ + -o '%(playlist_index)s - %(title)s [%(id)s].%(ext)s'\ + -P "$MUSICDIR/$NAME" "$2" && + notify-send "Playlist downloaded" || + (notify-send "Error: No internet connection" && exit 1) ;; +*) + exit 1 ;; +esac
\ No newline at end of file |
