mirror of
https://git.sr.ht/~coasteen/dotfiles
synced 2025-11-04 14:47:38 +01:00
suicide
This commit is contained in:
parent
9eb4717f59
commit
b7c8f7234f
5 changed files with 254 additions and 273 deletions
168
config/nvim-root/init.lua
Normal file
168
config/nvim-root/init.lua
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
vim.cmd [[
|
||||
set nocompatible
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
call plug#begin('~/.local/share/nvim/plugged')
|
||||
Plug 'tpope/vim-sensible'
|
||||
Plug 'junegunn/fzf.vim'
|
||||
Plug 'tpope/vim-surround'
|
||||
Plug 'tpope/vim-commentary'
|
||||
Plug 'jiangmiao/auto-pairs'
|
||||
Plug 'tpope/vim-repeat'
|
||||
Plug 'mattn/emmet-vim'
|
||||
Plug 'norcalli/nvim-colorizer.lua'
|
||||
call plug#end()
|
||||
]]
|
||||
|
||||
vim.opt.clipboard = "unnamedplus"
|
||||
vim.opt.updatetime = 300
|
||||
vim.opt.timeoutlen = 500
|
||||
vim.opt.signcolumn = "yes"
|
||||
vim.opt.completeopt = { "menuone", "noinsert", "noselect" }
|
||||
vim.opt.encoding = "utf-8"
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.opt.numberwidth = 4
|
||||
vim.opt.tabstop = 4
|
||||
vim.opt.shiftwidth = 4
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.incsearch = true
|
||||
vim.opt.hlsearch = true
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.opt.wrap = true
|
||||
vim.opt.mouse = "a"
|
||||
vim.opt.scrolloff = 5
|
||||
vim.opt.cursorline = true
|
||||
vim.opt.showmode = false
|
||||
vim.opt.shortmess:append("I")
|
||||
vim.opt.autoindent = true
|
||||
vim.opt.termguicolors = true
|
||||
vim.opt.list = true
|
||||
vim.opt.undodir = vim.fn.stdpath("cache") .. "/undo"
|
||||
vim.opt.undofile = true
|
||||
vim.opt.wrapscan = true
|
||||
vim.opt.shortmess:append("c")
|
||||
vim.opt.autoread = true
|
||||
vim.opt.cmdheight = 1
|
||||
vim.opt.belloff = "all"
|
||||
vim.opt.laststatus = 2
|
||||
vim.opt.scrolljump = 3
|
||||
vim.opt.hidden = true
|
||||
vim.opt.splitbelow = true
|
||||
vim.opt.splitright = true
|
||||
vim.opt.backup = false
|
||||
vim.opt.writebackup = false
|
||||
vim.opt.lazyredraw = true
|
||||
vim.opt.smoothscroll = true
|
||||
|
||||
vim.api.nvim_set_hl(0, "Normal", { fg = "#a6536f", bg = "NONE", ctermfg = 132, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "NormalNC", { fg = "#bb6c82", bg = "NONE", ctermfg = 168, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "LineNr", { fg = "#743c5e", bg = "NONE", ctermfg = 132, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "CursorLine", { bg = "#3f1f32", fg = "NONE", blend = 30 })
|
||||
vim.api.nvim_set_hl(0, "VertSplit", { fg = "#3f1f32", bg = "NONE", ctermfg = 237, ctermbg = "NONE" })
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusLine", {
|
||||
fg = "#a6536f",
|
||||
bg = "#2a1c2e",
|
||||
ctermfg = 132,
|
||||
ctermbg = 235,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusLineMode", {
|
||||
fg = "#f7d8e5",
|
||||
bg = "#5e2f4c",
|
||||
bold = true,
|
||||
ctermfg = 224,
|
||||
ctermbg = 131,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "Visual", { bg = "#5a2c3a", fg = "NONE", ctermbg = 52, ctermfg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "VisualNOS", { bg = "#5a2c3a", fg = "NONE", ctermbg = 52, ctermfg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "VisualSB", { bg = "#5a2c3a", fg = "NONE", ctermbg = 52, ctermfg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "Search", { fg = "#b0576f", bg = "#1c1533", ctermfg = 131, ctermbg = 234 })
|
||||
vim.api.nvim_set_hl(0, "IncSearch", { fg = "#f5a3ba", bg = "#1c1533", ctermfg = 218, ctermbg = 234 })
|
||||
vim.api.nvim_set_hl(0, "Pmenu", { fg = "#b0576f", bg = "NONE", ctermfg = 131, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "PmenuSel", { fg = "#000000", bg = "#b0576f", ctermfg = 0, ctermbg = 131 })
|
||||
vim.api.nvim_set_hl(0, "WildMenu", { fg = "#b0576f", bg = "NONE", ctermfg = 131, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "Folded", { fg = "#c18299", bg = "NONE", ctermfg = 174, ctermbg = "NONE" })
|
||||
vim.api.nvim_set_hl(0, "SignColumn", { fg = "#f0b6c8", bg = "NONE", ctermfg = 224, ctermbg = "NONE" })
|
||||
|
||||
local mode_names = {
|
||||
n = "ROOT NRM",
|
||||
i = "ROOT INS",
|
||||
v = "ROOT VSL",
|
||||
V = "ROOT VLI",
|
||||
[""] = "ROOT VBL",
|
||||
R = "ROOT RPL",
|
||||
c = "ROOT CMD",
|
||||
}
|
||||
|
||||
function _G.ModeName()
|
||||
return mode_names[vim.fn.mode()] or "UNK"
|
||||
end
|
||||
|
||||
vim.opt.statusline = table.concat {
|
||||
"%#StatusLineMode# ",
|
||||
"%{v:lua.ModeName()} ",
|
||||
"%#StatusLine# ",
|
||||
"%f %m %r ",
|
||||
"%=",
|
||||
"Ln:%l/%L ",
|
||||
"Col:%c ",
|
||||
"[%p%%]",
|
||||
}
|
||||
|
||||
vim.g.mapleader = " "
|
||||
local map = vim.keymap.set
|
||||
map("n", "<leader>w", ":w<CR>")
|
||||
map("n", "<leader>q", ":q<CR>")
|
||||
map("n", "<leader>h", ":nohlsearch<CR>", { silent = true })
|
||||
map("n", "<leader>n", ":set relativenumber!<CR>")
|
||||
map("n", "<C-h>", "<C-w>h")
|
||||
map("n", "<C-j>", "<C-w>j")
|
||||
map("n", "<C-k>", "<C-w>k")
|
||||
map("n", "<C-l>", "<C-w>l")
|
||||
map("n", "<leader>v", ":Ex<CR>")
|
||||
map("", "j", "gj")
|
||||
map("", "k", "gk")
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<leader>cd", vim.cmd.Ex)
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<leader>d", '"_d', { desc = "Delete without yanking" })
|
||||
vim.keymap.set("n", "<leader>bn", ":bnext<CR>", { desc = "Next buffer" })
|
||||
vim.keymap.set("n", "<leader>bp", ":bprevious<CR>", { desc = "Previous buffer" })
|
||||
|
||||
vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Move to left window" })
|
||||
vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Move to bottom window" })
|
||||
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Move to top window" })
|
||||
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window" })
|
||||
|
||||
local modes_to_disable = { "n", "v", "x", "s", "c" }
|
||||
local arrows = { "<Up>", "<Down>", "<Left>", "<Right>" }
|
||||
|
||||
for _, mode in ipairs(modes_to_disable) do
|
||||
for _, key in ipairs(arrows) do
|
||||
vim.keymap.set(mode, key, "<Nop>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>sv", ":vsplit<CR>", { desc = "Split window vertically" })
|
||||
vim.keymap.set("n", "<leader>sh", ":split<CR>", { desc = "Split window horizontally" })
|
||||
vim.keymap.set("n", "<C-Up>", ":resize +2<CR>", { desc = "Increase window height" })
|
||||
vim.keymap.set("n", "<C-Down>", ":resize -2<CR>", { desc = "Decrease window height" })
|
||||
vim.keymap.set("n", "<C-Right>", ":vertical resize -2<CR>", { desc = "Decrease window width" })
|
||||
vim.keymap.set("n", "<C-Left>", ":vertical resize +2<CR>", { desc = "Increase window width" })
|
||||
|
||||
vim.keymap.set("n", "<A-j>", ":m .+1<CR>==", { desc = "Move line down" })
|
||||
vim.keymap.set("n", "<A-k>", ":m .-2<CR>==", { desc = "Move line up" })
|
||||
vim.keymap.set("v", "<A-j>", ":m '>+1<CR>gv=gv", { desc = "Move selection down" })
|
||||
vim.keymap.set("v", "<A-k>", ":m '<-2<CR>gv=gv", { desc = "Move selection up" })
|
||||
|
||||
require('colorizer').setup {
|
||||
'*',
|
||||
css = { names = true },
|
||||
html = { names = true },
|
||||
}
|
||||
|
||||
|
|
@ -1,99 +1,89 @@
|
|||
#!/bin/sh
|
||||
#inspired by 'firemenu' by <swindlesmccoop> on github
|
||||
# BRWMENU:
|
||||
set -e
|
||||
DMENU_OPTS="-i -fn DepartureMono:size=10 -nb #151515 -nf #bbbbbb -sb #884757 -sf #eeeeee"
|
||||
BROWSER="mullvad-browser-bin"
|
||||
SWALLOW=""
|
||||
NOTIFIER="notify-send"
|
||||
for cmd in dmenu "$BROWSER"; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
echo "Error: Required command '$cmd' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
CHOICES="Startpage\nURL\nIncognito URL\nYouTube\nGithub\nCodeberg\ncoasteen.github.io\nIPLeak\nSafebooru\nWikipedia"
|
||||
PROMPT="Where to?"
|
||||
open_url() {
|
||||
if [ -z "$1" ]; then
|
||||
$NOTIFIER "Error" "No URL specified" 2>/dev/null || echo "Error: No URL specified" >&2
|
||||
exit 1
|
||||
fi
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import sys
|
||||
import shutil
|
||||
import urllib.parse
|
||||
|
||||
if ! $SWALLOW $BROWSER "$1" >/dev/null 2>&1; then
|
||||
$NOTIFIER "Error" "Failed to open browser with URL: $1" 2>/dev/null || \
|
||||
echo "Error: Failed to open browser with URL: $1" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
get_input() {
|
||||
prompt="$1"
|
||||
prefix="$2"
|
||||
input=$(printf '' | dmenu $DMENU_OPTS -p "$prompt" 2>/dev/null)
|
||||
DMENU_OPTS = ["-i", "-fn", "DepartureMono:size=10", "-nb", "#151515", "-nf", "#bbbbbb", "-sb", "#2a1f4d", "-sf", "#eeeeee"]
|
||||
BROWSER = "mullvad-browser-bin"
|
||||
NOTIFIER = "notify-send"
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
$NOTIFIER "Error" "No input provided" 2>/dev/null || echo "Error: No input provided" >&2
|
||||
exit 1
|
||||
fi
|
||||
CHOICES = [
|
||||
"Startpage", "URL", "Incognito URL", "YouTube", "Github", "Codeberg",
|
||||
"coasteen.github.io", "IPLeak", "Safebooru", "Wikipedia"
|
||||
]
|
||||
|
||||
input=$(printf "%s" "$input" | sed 's/ /%20/g')
|
||||
echo "${prefix}${input}"
|
||||
}
|
||||
CHOICE=$(printf "$CHOICES" | dmenu $DMENU_OPTS -p "$PROMPT" 2>/dev/null)
|
||||
case "$CHOICE" in
|
||||
Github)
|
||||
url=$(get_input "Username & repo:" "https://github.com/")
|
||||
open_url "$url"
|
||||
;;
|
||||
Codeberg)
|
||||
url=$(get_input "Username & repo:" "https://codeberg.org/")
|
||||
open_url "$url"
|
||||
;;
|
||||
IPLeak)
|
||||
open_url "https://ipleak.net"
|
||||
;;
|
||||
Startpage)
|
||||
query=$(get_input "Search Startpage:" "")
|
||||
open_url "https://www.startpage.com/do/search?q="
|
||||
;;
|
||||
Wikipedia)
|
||||
query=$(get_input "Search Wikipedia:" "")
|
||||
open_url "https://en.wikipedia.org/wiki/Special:Search?search=$query"
|
||||
;;
|
||||
URL)
|
||||
url=$(get_input "Enter URL:" "")
|
||||
case "$url" in
|
||||
http://*|https://*) ;;
|
||||
*) url="https://$url" ;;
|
||||
esac
|
||||
open_url "$url"
|
||||
;;
|
||||
Incognito\ URL)
|
||||
url=$(get_input "Enter incognito URL:" "")
|
||||
case "$url" in
|
||||
http://*|https://*) ;;
|
||||
*) url="https://$url" ;;
|
||||
esac
|
||||
if ! $SWALLOW brave-bin --incognito "$url" >/dev/null 2>&1; then
|
||||
$NOTIFIER "Error" "Failed to open incognito window" 2>/dev/null || \
|
||||
echo "Error: Failed to open incognito window" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
YouTube)
|
||||
query=$(get_input "Search YouTube:" "")
|
||||
open_url "https://youtube.com/results?search_query=$query"
|
||||
;;
|
||||
Safebooru)
|
||||
query=$(get_input "Search Safebooru:" "")
|
||||
open_url "https://safebooru.org/index.php?page=post&s=list&tags=$query"
|
||||
;;
|
||||
coasteen.github.io)
|
||||
open_url "https://coasteen.github.io/www/"
|
||||
;;
|
||||
*)
|
||||
$NOTIFIER "Error" "Invalid selection: $CHOICE" 2>/dev/null || \
|
||||
echo "Error: Invalid selection: $CHOICE" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
def notify(title, message):
|
||||
subprocess.run([NOTIFIER, title, message], stderr=subprocess.DEVNULL)
|
||||
|
||||
def run_dmenu(prompt, options=None):
|
||||
cmd = ["dmenu", *DMENU_OPTS, "-p", prompt]
|
||||
stdin = None
|
||||
if options:
|
||||
stdin = "\n".join(options)
|
||||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
|
||||
out, _ = proc.communicate(stdin)
|
||||
return out.strip()
|
||||
|
||||
def get_input(prompt, prefix=""):
|
||||
text = run_dmenu(prompt)
|
||||
if not text:
|
||||
notify("Error", "No input provided")
|
||||
sys.exit(1)
|
||||
return prefix + urllib.parse.quote_plus(text)
|
||||
|
||||
def open_url(url):
|
||||
try:
|
||||
subprocess.Popen([BROWSER, url])
|
||||
except:
|
||||
notify("Error", f"Failed to open browser: {url}")
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
choice = run_dmenu("Where to?", CHOICES)
|
||||
if not choice:
|
||||
notify("Error", "No selection made")
|
||||
sys.exit(1)
|
||||
|
||||
if choice == "Github":
|
||||
open_url(get_input("Username & repo:", "https://github.com/"))
|
||||
elif choice == "Codeberg":
|
||||
open_url(get_input("Username & repo:", "https://codeberg.org/"))
|
||||
elif choice == "IPLeak":
|
||||
open_url("https://ipleak.net")
|
||||
elif choice == "Startpage":
|
||||
open_url("https://www.startpage.com/do/search?q=" + get_input("Search Startpage:"))
|
||||
elif choice == "Wikipedia":
|
||||
open_url("https://en.wikipedia.org/wiki/Special:Search?search=" + get_input("Search Wikipedia:"))
|
||||
elif choice == "URL":
|
||||
url = run_dmenu("Enter URL:")
|
||||
if not url:
|
||||
notify("Error", "No URL entered")
|
||||
sys.exit(1)
|
||||
if not url.startswith("http"):
|
||||
url = "https://" + url
|
||||
open_url(url)
|
||||
elif choice == "Incognito URL":
|
||||
url = run_dmenu("Enter incognito URL:")
|
||||
if not url:
|
||||
notify("Error", "No URL entered")
|
||||
sys.exit(1)
|
||||
if not url.startswith("http"):
|
||||
url = "https://" + url
|
||||
subprocess.Popen(["brave-bin", "--incognito", url])
|
||||
elif choice == "YouTube":
|
||||
open_url("https://youtube.com/results?search_query=" + get_input("Search YouTube:"))
|
||||
elif choice == "Safebooru":
|
||||
open_url("https://safebooru.org/index.php?page=post&s=list&tags=" + get_input("Search Safebooru:"))
|
||||
elif choice == "coasteen.github.io":
|
||||
open_url("https://coasteen.github.io/www/")
|
||||
else:
|
||||
notify("Error", f"Invalid selection: {choice}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
for cmd in ["dmenu", BROWSER]:
|
||||
if shutil.which(cmd) is None:
|
||||
print(f"Error: Required command '{cmd}' not found", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
main()
|
||||
|
|
|
|||
100
local/brwmenu
100
local/brwmenu
|
|
@ -1,100 +0,0 @@
|
|||
#!/bin/sh
|
||||
#inspired by 'firemenu' by <swindlesmccoop> on github
|
||||
# BRWMENU:
|
||||
set -e
|
||||
DMENU_OPTS="-i -fn monospace:size=12 -nb #151515 -nf #bbbbbb -sb #663300 -sf #eeeeee"
|
||||
BROWSER="brave-bin"
|
||||
SWALLOW=""
|
||||
NOTIFIER="notify-send"
|
||||
for cmd in dmenu "$BROWSER"; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
echo "Error: Required command '$cmd' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
CHOICES="YouTube\nSafebooru\nWikipedia\nGithub\nCodeberg\nIPLeak\nQwant\nDuckDuckGo\nURL\nIncognito URL"
|
||||
PROMPT="Where to?"
|
||||
open_url() {
|
||||
if [ -z "$1" ]; then
|
||||
$NOTIFIER "Error" "No URL specified" 2>/dev/null || echo "Error: No URL specified" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! $SWALLOW $BROWSER "$1" >/dev/null 2>&1; then
|
||||
$NOTIFIER "Error" "Failed to open browser with URL: $1" 2>/dev/null || \
|
||||
echo "Error: Failed to open browser with URL: $1" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
get_input() {
|
||||
prompt="$1"
|
||||
prefix="$2"
|
||||
input=$(printf '' | dmenu $DMENU_OPTS -p "$prompt" 2>/dev/null)
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
$NOTIFIER "Error" "No input provided" 2>/dev/null || echo "Error: No input provided" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input=$(printf "%s" "$input" | sed 's/ /%20/g')
|
||||
echo "${prefix}${input}"
|
||||
}
|
||||
CHOICE=$(printf "$CHOICES" | dmenu $DMENU_OPTS -p "$PROMPT" 2>/dev/null)
|
||||
case "$CHOICE" in
|
||||
Github)
|
||||
url=$(get_input "Username & repo:" "https://github.com/")
|
||||
open_url "$url"
|
||||
;;
|
||||
Codeberg)
|
||||
url=$(get_input "Username & repo:" "https://codeberg.org/")
|
||||
open_url "$url"
|
||||
;;
|
||||
IPLeak)
|
||||
open_url "https://ipleak.net"
|
||||
;;
|
||||
Qwant)
|
||||
query=$(get_input "Search Qwant:" "")
|
||||
open_url "https://qwant.com/search?q=$query"
|
||||
;;
|
||||
DuckDuckGo)
|
||||
query=$(get_input "Search DuckDuckGo:" "")
|
||||
open_url "https://duckduckgo.com/?q=$query"
|
||||
;;
|
||||
Wikipedia)
|
||||
query=$(get_input "Search Wikipedia:" "")
|
||||
open_url "https://en.wikipedia.org/wiki/Special:Search?search=$query"
|
||||
;;
|
||||
URL)
|
||||
url=$(get_input "Enter URL:" "")
|
||||
case "$url" in
|
||||
http://*|https://*) ;;
|
||||
*) url="https://$url" ;;
|
||||
esac
|
||||
open_url "$url"
|
||||
;;
|
||||
Incognito\ URL)
|
||||
url=$(get_input "Enter incognito URL:" "")
|
||||
case "$url" in
|
||||
http://*|https://*) ;;
|
||||
*) url="https://$url" ;;
|
||||
esac
|
||||
if ! $SWALLOW brave-bin --incognito "$url" >/dev/null 2>&1; then
|
||||
$NOTIFIER "Error" "Failed to open incognito window" 2>/dev/null || \
|
||||
echo "Error: Failed to open incognito window" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
YouTube)
|
||||
query=$(get_input "Search YouTube:" "")
|
||||
open_url "https://youtube.com/results?search_query=$query"
|
||||
;;
|
||||
Safebooru)
|
||||
query=$(get_input "Search Safebooru:" "")
|
||||
open_url "https://safebooru.org/index.php?page=post&s=list&tags=$query"
|
||||
;;
|
||||
*)
|
||||
$NOTIFIER "Error" "Invalid selection: $CHOICE" 2>/dev/null || \
|
||||
echo "Error: Invalid selection: $CHOICE" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
77
local/radio
77
local/radio
|
|
@ -1,77 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
import threading
|
||||
import json
|
||||
import tempfile
|
||||
import urllib.request
|
||||
import websocket
|
||||
import signal
|
||||
|
||||
URL = "https://radio.animebits.moe/stream/stream128.ogg"
|
||||
CONF = Path.home() / ".config" / "radiorc"
|
||||
PID = Path.home() / ".config" / "radio-pid"
|
||||
|
||||
with open(CONF) as f:
|
||||
VOL = f.read().strip()
|
||||
|
||||
def notify(title, image_url=None):
|
||||
icon_path = None
|
||||
if image_url:
|
||||
try:
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
||||
urllib.request.urlretrieve(image_url, tmp.name)
|
||||
icon_path = tmp.name
|
||||
except:
|
||||
icon_path = None
|
||||
args = ["notify-send", title]
|
||||
if icon_path:
|
||||
args += ["-i", icon_path]
|
||||
subprocess.run(args)
|
||||
|
||||
def ws_listener():
|
||||
def on_message(ws, message):
|
||||
data = json.loads(message)
|
||||
if "data" in data and "title" in data["data"]:
|
||||
title = data["data"]["title"]
|
||||
image = data["data"].get("album_cover")
|
||||
notify(title, image)
|
||||
|
||||
def on_error(ws, error): pass
|
||||
def on_close(ws, close_status_code, close_msg):
|
||||
time.sleep(1)
|
||||
run_ws()
|
||||
def on_open(ws): pass
|
||||
|
||||
def run_ws():
|
||||
ws = websocket.WebSocketApp(
|
||||
"wss://radio.animebits.moe/api/events/basic",
|
||||
on_message=on_message,
|
||||
on_error=on_error,
|
||||
on_close=on_close,
|
||||
on_open=on_open,
|
||||
)
|
||||
ws.run_forever()
|
||||
|
||||
run_ws()
|
||||
|
||||
threading.Thread(target=ws_listener, daemon=True).start()
|
||||
|
||||
while True:
|
||||
try:
|
||||
print("Playing now...")
|
||||
subprocess.run(["notify-send", "Playing now..."])
|
||||
proc = subprocess.Popen(["mpv", "--no-video", f"--volume={VOL}", URL], preexec_fn=os.setsid)
|
||||
with open(PID, "w") as f:
|
||||
f.write(str(os.getpgid(proc.pid)))
|
||||
proc.wait()
|
||||
except KeyboardInterrupt:
|
||||
subprocess.run(["notify-send", "Stopping now..."])
|
||||
print("\nStopping now...")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Something broke... trying again... Error: {e}")
|
||||
time.sleep(2)
|
||||
|
||||
Loading…
Add table
Reference in a new issue