Go Go Gadget Bash

main
Jay Moore 4 days ago
commit f315c44d4e

@ -0,0 +1,16 @@
MIT No Attribution
Copyright 2025 Jay Moore
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,31 @@
# konversation-mpd - an mpd script for the Konversation IRC client
Currently only spams an IRC channel (or msg window) with some stats about what mpd is currently playing using whatever shortcut you assign it to. You can customize the output sent by editing the script; however I haven't generated a list of currently available variables.
Future plans include doing nice things if you're not in playback mode; as well as basic playback control from within Konversation.
## Requirements
- mpd
- bc
mpd is obvious. bc is used to do math on sample rates.
## Installation/Usage
- Make any changes to the formatting of the output you wish, and copy the script to wherever Konversation looks for scripts on your system.
- Assign `/exec mpdirc` to an alias of your choosing.
- Start playback in mpd.
- Issue your alias in the channel you wish to spam.
- Annoy your friends!
That's it.
## How It Works
The script talks to mpd (directly) using a file-handler to /dev/tcp/localhost/6600. After dropping it's banner response, we send it the `status` and `currentsong` commands; mpd responds with a ton of fields. We convert all of those fields in to a variable=value. We then check if the format is DSD or a sample rate and either specify a rate or divide by 1000. The extension of the file is obtained and some logic is done to determine which codec information we're going to display. We slap all of this in to a variable formatted the way we want; and send it to koversation over dBus.
## TODO
- List of variables, in case there's something you want I'm not already listing.
- Playback controls: start, stop, pause, skip...all from within IRC.

129
mpdirc

@ -0,0 +1,129 @@
#!/bin/bash
SERVER=$1
TARGET=$2
_qdbus=${KONVERSATION_DBUS_BIN:-qdbus-qt6}
if ! [ "$(which $_qdbus 2> /dev/null)" ]; then
_qdbus=qdbus
if ! [ "$(which $_qdbus 2> /dev/null)" ]; then
echo "Error: The qdbus (or qdbus-qt6) utility is missing."
exit 1
fi
fi
seconds_to_mmss() {
local total_seconds="$1"
# Convert to integer (truncate decimal part)
local int_seconds=$(printf "%.0f" "$total_seconds")
# Calculate minutes and seconds
local minutes=$((int_seconds / 60))
local seconds=$((int_seconds % 60))
# Format with leading zeros
printf "%02d:%02d" "$minutes" "$seconds"
}
format_audio() {
local audio_format="$1"
# Split the format string on colons
IFS=':' read -r samplerate bitdepth channels <<< "$audio_format"
# Fix it all to stereo!
local channel_text="Stereo"
case $samplerate in
dsd64)
local samplerate="2.822MHz"
local bitdepth="1"
dsd="DSD64"
;;
dsd128)
local samplerate="5.644MHz"
local bitdepth="1"
dsd="DSD128"
;;
dsd256)
local samplerate="11.288MHz"
local bitdepth="1"
dsd="DSD256"
;;
dsd512)
local samplerate="22.576MHz"
local bitdepth="1"
dsd="DSD512"
;;
*)
local trate="$(echo "scale=1; $samplerate / 1000" | bc)"
samplerate="${trate%.0}kHz"
dsd=""
;;
esac
# Return formatted string - we can't set global variables here so we have to split it out later. Thanks bash!
echo "${samplerate}/${bitdepth}-bit/${channel_text}|${dsd}"
}
get_extension() {
local filepath="$1"
# Get just the filename without the path
local filename="${filepath##*/}"
# Extract extension and convert to uppercase
local extension="${filename##*.}"
echo "${extension^^}"
}
get_mpd_data() {
# Send commands
printf "command_list_begin\r\nstatus\r\ncurrentsong\r\ncommand_list_end\r\n" >&3
# Read responses until we get empty line or OK
while IFS=': ' read -r name value <&3; do
[[ "$name" == "" ]] && break # Empty line = end of response
[[ "$name" == "OK" ]] && break
# Process the data
if [[ -n "$name" && -n "$value" && "$name" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
declare -g "$name=$value" # Use -g for global scope
fi
done
}
# Open non-blocking connection MPD
exec 3<>/dev/tcp/localhost/6600
# Clears the connection string from the buffer
read -r greeting <&3
# Request Data
get_mpd_data
# This is part of the global varible hack junk.
audio_result=$(format_audio $audio)
# It splits the result in to new variables
format_part="${audio_result%|*}" # Everything before the |
dsd_part="${audio_result#*|}" # Everything after the |
# Generate codec - either extension, DSD??, or DSD64/Super Audio CD.
fileext=$(get_extension "$file")
if [[ -z "$dsd_part" ]]; then
codec_result="$fileext"
elif [[ -n "dsd_part" && "$fileext" == "ISO" ]]; then
codec_result="$dsd_part/Super Audio CD"
else
codec_result="$dsd_part"
fi
# Format output to send to konversation
spam="/me mpd: $Artist - $Title (From: $Album) [$(seconds_to_mmss $elapsed)/$(seconds_to_mmss $duration) | $format_part | $bitrate kbps | $codec_result]"
# Spam that IRC channel!
$_qdbus org.kde.konversation /irc say $SERVER "$TARGET" "$spam"
exec 3<&-
Loading…
Cancel
Save