104 lines
1.7 KiB
Bash
Executable File
104 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
## Get data
|
|
STATUS="$(playerctl status)"
|
|
COVER="/tmp/.music_cover.jpg"
|
|
MUSIC_DIR="$HOME/Music"
|
|
|
|
## Get status
|
|
get_status() {
|
|
if [[ $STATUS == *"Playing"* ]]; then
|
|
echo ""
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
## Get song
|
|
get_song() {
|
|
playerctl-hyprlock --title
|
|
}
|
|
|
|
## Get artist
|
|
get_artist() {
|
|
playerctl-hyprlock --artist
|
|
}
|
|
|
|
## Get time
|
|
get_time() {
|
|
time=$(mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)')
|
|
if [[ -z "$time" ]]; then
|
|
echo "0"
|
|
else
|
|
echo "$time"
|
|
fi
|
|
}
|
|
get_ctime() {
|
|
ctime=$(mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g')
|
|
if [[ -z "$ctime" ]]; then
|
|
echo "0:00"
|
|
else
|
|
echo "$ctime"
|
|
fi
|
|
}
|
|
get_ttime() {
|
|
ttime=$(mpc -f %time% current)
|
|
if [[ -z "$ttime" ]]; then
|
|
echo "0:00"
|
|
else
|
|
echo "$ttime"
|
|
fi
|
|
}
|
|
|
|
## Get cover
|
|
get_cover() {
|
|
|
|
DOWNLOAD_PATH="$HOME/.cache/cover.png"
|
|
FALLBACK_PATH="./images/music.png" # Change this to your static image path
|
|
|
|
# Get the image URL from playerctl
|
|
URL=$(playerctl metadata mpris:artUrl 2>/dev/null)
|
|
|
|
# If the URL is empty or playerctl fails, return the fallback path
|
|
if [[ -z "$URL" ]]; then
|
|
echo "$FALLBACK_PATH"
|
|
return
|
|
fi
|
|
|
|
# Try downloading the image
|
|
if curl -s -o "$DOWNLOAD_PATH" "$URL"; then
|
|
echo "$DOWNLOAD_PATH"
|
|
else
|
|
echo "$FALLBACK_PATH"
|
|
fi
|
|
}
|
|
|
|
## Execute accordingly
|
|
if [[ "$1" == "--song" ]]; then
|
|
get_song
|
|
elif [[ "$1" == "--artist" ]]; then
|
|
get_artist
|
|
elif [[ "$1" == "--status" ]]; then
|
|
get_status
|
|
elif [[ "$1" == "--time" ]]; then
|
|
get_time
|
|
elif [[ "$1" == "--ctime" ]]; then
|
|
get_ctime
|
|
elif [[ "$1" == "--ttime" ]]; then
|
|
get_ttime
|
|
elif [[ "$1" == "--cover" ]]; then
|
|
get_cover
|
|
elif [[ "$1" == "--toggle" ]]; then
|
|
mpc -q toggle
|
|
elif [[ "$1" == "--next" ]]; then
|
|
{
|
|
mpc -q next
|
|
get_cover
|
|
}
|
|
elif [[ "$1" == "--prev" ]]; then
|
|
{
|
|
mpc -q prev
|
|
get_cover
|
|
}
|
|
fi
|