add romote, yt, and yt_music scripts

This commit is contained in:
steven 2025-04-21 00:07:11 -04:00
parent 347b8b1d1c
commit 97ebea9a88
4 changed files with 78 additions and 2 deletions

61
scripts/romote Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/python
from blessed import Terminal
from pathlib import Path
import urllib.parse
import httpx
def roku(key):
match key:
case 'INSERT':key='PowerOn'
case 'DELETE':key='PowerOff'
case 'ESCAPE':key='Back'
case 'HOME'|'UP'|'LEFT'|'RIGHT'|'DOWN'|'BACKSPACE':pass
case 'ENTER':key='Select'
case 'PGUP':key='VolumeUp'
case 'PGDOWN':key='VolumeDown'
case 'END':key='VolumeMute'
case '?':key='InstantReplay'
case '/':key='Info'
case '<':key='Rev'
case 'TAB':key='Play'
case '>':key='Fwd'
case _:key=f'Lit_{urllib.parse.quote(key)}'
httpx.post(f"http://{IP}:8060/keypress/{key}")
path = Path("~/.romote").expanduser()
if not path.exists():
path.touch()
with path.open("r") as f:
IPs = [line.strip("\n").split(",") for line in f]
if IPs:
print("\n".join([f"{i+1}. {' - '.join(l)}" for i,l in enumerate(IPs)]))
IP = input("Choose one from the list, or add a new one: ")
IP = IPs[int(IP)-1][0] if int(IP) <= len(IPs) else "192.168.1."+IP
else:
IP = input("Enter the IP you want to use: ")
if len(IP) <= 3:IP = "192.168.1."+IP
if not any(existing[0] == IP for existing in IPs):
with path.open("a") as f:f.write(f"{IP}\n")
t = Terminal()
print(t.clear + IP)
print("Insert/Delete to power on or off")
print("Escape to go back")
print("Home to go home")
print("Arrow keys to navigate")
print("Enter for OK")
print("PageUp/PageDn to control volume")
print("End to mute")
print("? to replay")
print("/ to get info")
print("< to rewind")
print("Tab to play/pause")
print("> to fast-forward")
print("Use other keys to type")
while True:
with t.cbreak():
key = t.inkey()
if key.name:
roku(key.name.split("_")[1])
else:
roku(key)

13
scripts/yt Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
search="https://music.youtube.com/search?q="
if [ -z "$format" ]; then
options="--keep-open=yes"
search="ytsearch"
format="bv[height<=720]+ba/b"
fi
[ "$#" -gt 0 ] && url="$*" || url="$(timeout 0.1 cat)"
[ -z "$url" ] && url="$(wl-paste)"
[ -z "$url" ] && url="https://youtu.be/dQw4w9WgXcQ"
notify-send -t 1000 "$url" & mpv $options --ytdl-raw-options=default-search=$search --ytdl-format="$format" ytdl://"$url" || notify-send -t 3000 "Failed to play youtube video"

2
scripts/yt_music Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
format=ba yt "$@"

View file

@ -70,8 +70,8 @@ bindgesture swipe:left workspace next
# Shortcuts
bindsym $mod+Return exec foot
bindsym $mod+d exec wmenu-run
bindsym $mod+y exec 'yt "$(wl-paste)"'
bindsym $mod+p exec foot -T "$(wl-paste)" -e sh -c 'yt_music "$(wl-paste -n)"'
bindsym $mod+y exec '~/.local/bin/yt "$(wl-paste)"'
bindsym $mod+p exec foot -T "$(wl-paste)" -e sh -c '~/.local/bin/yt_music "$(wl-paste -n)"'
bindsym $mod+s exec 'grim -g "$(slurp -d)" - | wl-copy'
bindsym Print exec 'grim - | swayimg -f -'
bindsym Mod4+e exec thunar