This commit is contained in:
thek4n 2026-02-20 00:43:08 +03:00
parent 90c81c3043
commit 2b9b903803
4 changed files with 141 additions and 123 deletions

View File

@ -24,6 +24,6 @@ ipython:.ipython/profile_default/ipython_config.py
gdb:.config/gdb
sandbox:
chromium:.local/bin/pchromium .local/share/applications/pchromium.desktop
scripts:.local/bin/httpstatus .local/bin/apco .local/bin/bb .local/bin/emoji .local/bin/mksh .local/bin/nato .local/bin/pastas .local/bin/timer .local/bin/tryna .local/bin/trynafail .local/bin/bak .local/bin/cleanup-directory .local/bin/cleanup-directory-log .local/bin/cleanup-downloads .local/bin/gobuild .local/bin/json .local/bin/open .local/bin/py .local/bin/sha .local/bin/showtips .local/bin/weather .local/bin/radio .local/bin/rmt .local/bin/scratch .local/bin/tunes .local/bin/wake .local/bin/myip .local/bin/genpass .local/bin/gensalt .local/bin/django-create-project .local/bin/mirror-site .local/bin/split-file .local/bin/extract .local/bin/destroy .local/bin/serveit .local/bin/highlight-logs %copypasta
scripts:.local/bin/httpstatus .local/bin/apco .local/bin/bb .local/bin/emoji .local/bin/mksh .local/bin/nato .local/bin/pastas .local/bin/timer .local/bin/tryna .local/bin/trynafail .local/bin/bak .local/bin/cleanup-directory .local/bin/cleanup-directory-log .local/bin/cleanup-downloads .local/bin/gobuild .local/bin/json .local/bin/open .local/bin/py .local/bin/sha .local/bin/showtips .local/bin/weather .local/bin/radio .local/bin/rmt .local/bin/scratch .local/bin/player .local/bin/wake .local/bin/myip .local/bin/genpass .local/bin/gensalt .local/bin/django-create-project .local/bin/mirror-site .local/bin/split-file .local/bin/extract .local/bin/destroy .local/bin/serveit .local/bin/highlight-logs %copypasta
copypasta:.local/bin/copy .local/bin/pasta
all:%less %t %note %tmux %zsh %nvim %git"

139
home/user/.local/bin/player Executable file
View File

@ -0,0 +1,139 @@
#!/bin/sh
set -eu
PROG="$(basename "${0}")"
SOCKET_PATH="/tmp/mpv-${USER}.sock"
die() {
echo "Error: $*" >&2
exit 1
}
usage() {
cat <<EOF
Usage: ${PROG} <command> [args]
Commands:
run music [PATH] Play local music (default: ~/Music)
run radio <CHANNEL> Start a radio station
radio <CHANNEL> Switch current playing instance to a radio station
next, n Next track
prev, p Previous track
pause, space Toggle pause
help Show this message
Radio Channels:
lofi, fallout, wasteland, retrofm, rusradio, rock, phonk, dorognoe
EOF
}
get_radio_url() {
channel="${1:-}"
case "${channel}" in
lofi) echo 'https://radiorecord.hostingradio.ru/lofi96.aacp' ;;
fallout) echo 'http://fallout.fm:8000/falloutfm1.ogg' ;;
wasteland) echo 'http://wasteland.su:8080/radio' ;;
retrofm) echo 'http://hls-01-retro.emgsound.ru/12/128/playlist.m3u8' ;;
rusradio) echo 'https://rusradio.hostingradio.ru/rusradio128.mp3' ;;
rock) echo 'https://radiorecord.hostingradio.ru/rock96.aacp' ;;
phonk) echo 'https://radiorecord.hostingradio.ru/phonk96.aacp' ;;
dorognoe) echo 'https://dorognoe.hostingradio.ru:8000/dorognoe' ;;
*) die "Unknown radio channel '${channel}'. Available: lofi/fallout/wasteland/retrofm/rusradio/rock/phonk/dorognoe" ;;
esac
}
send_cmd() {
if [ ! -S "${SOCKET_PATH}" ]; then
die "MPV socket not found at '${SOCKET_PATH}'. Is mpv running?"
fi
printf '{ "command": %s }\n' "${1}" | socat - "${SOCKET_PATH}" >/dev/null
}
launch_mpv() {
rm -f "${SOCKET_PATH}"
trap 'rm -f "${SOCKET_PATH}"' INT HUP EXIT TERM
exec mpv --input-ipc-server="${SOCKET_PATH}" --no-video --ytdl-format=worstaudio "${@}"
}
play_playlist() {
playlist="${1:-${HOME}/Music}"
shift || true
launch_mpv --shuffle "$@" -- "${playlist}"
}
play_radio() {
channel="${1:-}"
if [ -z "${channel}" ]; then
die "Radio channel required. Usage: ${PROG} run radio <channel>"
fi
url="$(get_radio_url "${channel}")"
launch_mpv "${url}"
}
tune_radio() {
channel="${1:-}"
if [ -z "${channel}" ]; then
die "Radio channel required. Usage: ${PROG} radio <channel>"
fi
url="$(get_radio_url "${channel}")"
send_cmd "[\"loadfile\", \"${url}\", \"replace\"]"
echo "📻 Switched to: ${channel}"
}
handle_control() {
action="${1}"
case "${action}" in
next|n)
send_cmd '["playlist-next"]'
echo "➡️ Next"
;;
prev|p)
send_cmd '["playlist-prev"]'
echo "⬅️ Prev"
;;
pause|space)
send_cmd '["cycle", "pause"]'
echo "⏯️ Pause toggled"
;;
*)
usage
exit 1
;;
esac
}
ACTION="${1:-}"
shift 2>/dev/null || true
case "${ACTION}" in
run)
subcmd="${1:-help}"
shift || true
case "${subcmd}" in
music) play_playlist "$@" ;;
radio) play_radio "$@" ;;
*) usage; exit 1 ;;
esac
;;
radio)
tune_radio "$@"
;;
next|n|prev|p|pause|space)
handle_control "${ACTION}"
;;
help|"")
usage
;;
*)
echo "Unknown command: ${ACTION}" >&2
usage
exit 1
;;
esac

View File

@ -1,121 +0,0 @@
#!/bin/sh
set -eu
ACTION="${1:-}"
PROG="$(basename "${0}")"
SOCKET_PATH="/tmp/mpv-${USER}.sock"
send_cmd() {
echo "{ \"command\": ${1} }" | socat - "${SOCKET_PATH}"
}
play_playlist() {
playlist="${1:-}"
if [ -z "${playlist}" ]; then
playlist="${HOME}/Music"
fi
#shellcheck disable=SC2064
trap "rm -f '${SOCKET_PATH}'" INT HUP EXIT
mpv --input-ipc-server="${SOCKET_PATH}" --shuffle --no-video --ytdl-format=worstaudio "${@}" -- "${playlist}"
}
play_radio() {
channel="${1:-}"
if [ "${channel}" = lofi ]; then
url='https://radiorecord.hostingradio.ru/lofi96.aacp'
elif [ "${channel}" = fallout ]; then
url='http://fallout.fm:8000/falloutfm1.ogg'
elif [ "${channel}" = wasteland ]; then
url='http://wasteland.su:8080/radio'
elif [ "${channel}" = retrofm ]; then
url='http://hls-01-retro.emgsound.ru/12/128/playlist.m3u8'
elif [ "${channel}" = rusradio ]; then
url='https://rusradio.hostingradio.ru/rusradio128.mp3'
elif [ "${channel}" = rock ]; then
url='https://radiorecord.hostingradio.ru/rock96.aacp'
elif [ "${channel}" = phonk ]; then
url='https://radiorecord.hostingradio.ru/phonk96.aacp'
elif [ "${channel}" = dorognoe ]; then
url='https://dorognoe.hostingradio.ru:8000/dorognoe'
else
echo "${PROG} run radio: don't know \"${channel}\": lofi/fallout/wasteland/retrofm/rusradio/rock/phonk/dorognoe" 1>&2
exit 1
fi
#shellcheck disable=SC2064
trap "rm -f '${SOCKET_PATH}'" INT HUP EXIT
mpv --input-ipc-server="${SOCKET_PATH}" --no-video "${url}"
}
cmd_run() {
case "${1:-}" in
music) shift;
play_playlist "${@}"
;;
radio) shift;
play_radio "${@}"
;;
help|""|*)
echo "Usage: ${PROG} run {music PLAYLIST|radio CHANNEL}"
echo "Example: ${PROG} run music"
;;
esac
}
tune_radio() {
channel="${1:-}"
if [ "${channel}" = lofi ]; then
url='https://radiorecord.hostingradio.ru/lofi96.aacp'
elif [ "${channel}" = fallout ]; then
url='http://fallout.fm:8000/falloutfm1.ogg'
elif [ "${channel}" = wasteland ]; then
url='http://wasteland.su:8080/radio'
elif [ "${channel}" = retrofm ]; then
url='http://hls-01-retro.emgsound.ru/12/128/playlist.m3u8'
elif [ "${channel}" = rusradio ]; then
url='https://rusradio.hostingradio.ru/rusradio128.mp3'
elif [ "${channel}" = rock ]; then
url='https://radiorecord.hostingradio.ru/rock96.aacp'
elif [ "${channel}" = phonk ]; then
url='https://radiorecord.hostingradio.ru/phonk96.aacp'
elif [ "${channel}" = dorognoe ]; then
url='https://dorognoe.hostingradio.ru:8000/dorognoe'
else
echo "${PROG} radio: don't know \"${channel}\": lofi/fallout/wasteland/retrofm/rusradio/rock/phonk/dorognoe" 1>&2
exit 1
fi
send_cmd "[\"loadfile\", \"${url}\", \"replace\"]"
}
case "${ACTION}" in
next|n) shift;
send_cmd '["playlist-next"]'
echo "➡️ Next"
;;
prev|p) shift;
send_cmd '["playlist-prev"]'
echo "⬅️ Prev"
;;
pause|space) shift;
send_cmd '["cycle", "pause"]'
echo "⏯️ Pause"
;;
run) shift;
cmd_run "${@}"
;;
radio) shift;
tune_radio "${@}"
;;
help|""|*)
echo "Usage: ${PROG} {next|prev|pause|run|radio CHANNEL}"
echo "Example: ${PROG} next"
;;
esac

View File

@ -10,7 +10,7 @@ readonly WORKING_PROJECT="${HOME}"
if ! tmux has-session -t="${SESSION}"; then
tmux new-session -s "${SESSION}" -d -n "${MAINW}" -c "${WORKING_PROJECT}"
tmux rename-window -t "${SESSION}:1" "${MAINW}"
tmux send-keys -t "${SESSION}:${MAINW}.1" "tunes run music" Enter
tmux send-keys -t "${SESSION}:${MAINW}.1" "player run music" Enter
fi
tmux switch-client -t "${SESSION}"