nixos/home/hyprland/ironbar/reference/scripts/music
Evie Litherland-Smith be1d5fa798 Switch to minimal ironbar implementation
Save reference for later
Enable upower daemon and add simple bar with the essentials for now,
TODO more later
2023-10-11 08:28:27 +01:00

274 lines
7.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# ╔╦╗ ╦ ╦ ╔═╗ ╦ ╔═╗
# ║║║ ║ ║ ╚═╗ ║ ║
# ╩ ╩ ╚═╝ ╚═╝ ╩ ╚═╝
# author Niraj
# github niraj998
# ┌─┐┌─┐┌┐┌┌─┐┬┌─┐┬ ┬┬─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
# │ │ ││││├┤ ││ ┬│ │├┬┘├─┤ │ ││ ││││└─┐
# └─┘└─┘┘└┘└ ┴└─┘└─┘┴└─┴ ┴ ┴ ┴└─┘┘└┘└─┘
# uncomment your music players below.
#
Control="not_MPD"
# [ -n "$(pgrep spotify)" ] && Control="spotify"
[ -n "$(pgrep brave-bin)" ] && Control="brave-bin"
# [ -n "$(pgrep rhythmbox)" ] && Control="rhythmbox"
# [ -n "$(pgrep audacious)" ] && Control="audacious"
# [ -n "$(pgrep clementine)" ] && Control="clementine"
# [ -n "$(pgrep strawberry)" ] && Control="strawberry"
# saves covers here
Cover=/tmp/music.jpg
# if cover not found in metadata use this instead
bkpCover=~/.config/eww/music.png
# mpd music directory
mpddir="$HOME/Music/iTunes Media"
# ┌─┐┬ ┌─┐┬ ┬┌─┐┬─┐┌─┐┌┬┐┬ ┌─┐┌─┐┬─┐┬┌─┐┌┬┐┌─┐
# ├─┘│ ├─┤└┬┘├┤ ├┬┘│ │ │ └─┐│ ├┬┘│├─┘ │ └─┐
# ┴ ┴─┘┴ ┴ ┴ └─┘┴└─└─┘ ┴ ┴─┘ └─┘└─┘┴└─┴┴ ┴ └─┘
########################## Title ##########################
title() {
title=$(playerctl metadata --format {{title}})
[ -z "$title" ] && title="Play Something"
echo "$title"
}
########################## Artist ##########################
artist() {
artist=$(playerctl metadata --format {{artist}})
[ -z "$artist" ] && artist="Artist"
echo "$artist"
}
########################## Album ##########################
album() {
album=$(playerctl metadata --format {{album}})
[ -z "$album" ] && album="Album"
echo "$album"
}
########################## Status ##########################
status() {
status=$(playerctl status)
[ -z "$status" ] && status="Stopped"
echo "$status"
}
########################## Time ##########################
ctime() {
time=$(playerctl position --format "{{ duration(position) }}")
[ -z "$time" ] && time="0:00"
echo "$time"
}
########################## Length ##########################
length() {
length=$(playerctl metadata --format "{{ duration(mpris:length) }}")
[ -z "$length" ] && length="0:00"
echo "$length"
}
########################## trackNumber ##########################
playlist() {
playlist=$(playerctl metadata xesam:trackNumber)
[ -z "$playlist" ] && playlist="0"
echo "$playlist"
}
########################## Cover ##########################
cover() {
albumart="$(playerctl metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
[ $(playerctl metadata mpris:artUrl) ] && curl -s "$albumart" --output /tmp/fuck.png || cp $bkpCover $Cover
convert /tmp/fuck.png $Cover
echo "$Cover"
}
########################## Statusicon ##########################
statusicon() {
icon=""
[ $(playerctl status) = "Playing" ] && icon=""
[ $(playerctl status) = "Paused" ] && icon=""
echo "$icon"
}
########################## Lyrics ##########################
lyrics() {
Title=$(playerctl metadata --format {{title}})
Artist=$(playerctl metadata --format {{artist}})
URL="https://api.lyrics.ovh/v1/$Artist/$Title"
lyrics=$(curl -s "$(echo "$URL" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)" | jq '.lyrics')
[ "$lyrics" = "null" ] && lyrics=$(curl -s --get "https://makeitpersonal.co/lyrics" --data-urlencode "artist=$Artist" --data-urlencode "title=$Title")
printf "$lyrics" | less
}
# ┌┬┐┌─┐┌┬┐ ┌─┐┌─┐┬─┐┬┌─┐┌┬┐┌─┐
# │││├─┘ ││ └─┐│ ├┬┘│├─┘ │ └─┐
# ┴ ┴┴ ─┴┘ └─┘└─┘┴└─┴┴ ┴ └─┘
########################## Title ##########################
mpctitle() {
title=$(mpc -f %title% current)
[ -z "$title" ] && title="Play Something"
echo "$title"
}
########################## Artist ##########################
mpcartist() {
artist=$(mpc -f %artist% current)
[ -z "$artist" ] && artist="Artist"
echo "$artist"
}
########################## Album ##########################
mpcalbum() {
album=$(mpc -f %album% current)
[ -z "$album" ] && album="Album"
echo "$album"
}
########################## Cover ##########################
mpccover() {
ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" "${Cover}" -y || cp $bkpCover $Cover
echo "$Cover" && exit
}
########################## Time ##########################
mpctime() {
time=$(mpc status %currenttime%)
[ -z "$time" ] && time="0:00"
echo "$time"
}
########################## Length ##########################
mpclength() {
length=$(mpc status %totaltime%)
[ -z "$length" ] && length="0:00"
echo "$length"
}
########################## Icon ##########################
mpcicon() {
status=$(mpc status | head -2 | tail -1 | cut -c2-7)
icon=""
[ "$status" = "playin" ] && icon=""
[ "$status" = "paused" ] && icon=""
echo "$icon"
}
########################## Status ##########################
mpcstatus() {
stat=$(mpc status | head -2 | tail -1 | cut -c2-7)
status="Stopped"
[ "$stat" = "playin" ] && status="Playing"
[ "$stat" = "paused" ] && status="Paused"
echo "$status"
}
########################## Percent ##########################
mpcperc() {
perc=$(mpc status %percenttime%)
[ -z "$perc" ] && perc="0"
echo "$perc"
}
########################## Playlist ##########################
mpcsongpos() {
pos=$(mpc status %songpos%)
allsongs=$(mpc status %length%)
playlist="$pos/$allsongs"
[ -z "$pos" ] && playlist="0/0"
echo "$playlist"
}
########################## Lyrics ##########################
mpclyrics() {
Title=$(mpc -f %title% current)
Artist=$(mpc -f %artist% current)
URL="https://api.lyrics.ovh/v1/$Artist/$Title"
lyrics=$(curl -s "$(echo "$URL" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)" | jq '.lyrics')
[ "$lyrics" = "null" ] && lyrics=$(curl -s --get "https://makeitpersonal.co/lyrics" --data-urlencode "artist=$Artist" --data-urlencode "title=$Title")
printf "$lyrics" | less
}
# ┬ ┬┌─┐┬ ┌─┐
# ├─┤├┤ │ ├─┘
# ┴ ┴└─┘┴─┘┴
doc() {
echo "Usage:
music [Options]
Options:
previous previous song
next next song
toggle toggle between play-pause song
title shows title of current song
album shows album of current song
artist shows artist of current song
status music status (playing/paused/stopped)
statusicon music status icons (playing/paused/stopped)
coverloc saves cover and shows location to cover of current song
showcover opens cover using feh
time shows current time of song
length shows length of song
percent shows percent song
playlist shows playlist position of current song
lyrics shows lyrics"
}
# ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
# │ │├─┘ │ ││ ││││└─┐
# └─┘┴ ┴ ┴└─┘┘└┘└─┘
case $Control in
MPD)
case $1 in
next) mpc -q next ;;
previous) mpc -q prev ;;
toggle) mpc -q toggle ;;
title) mpctitle ;;
artist) mpcartist ;;
album) mpcalbum ;;
status) mpcstatus ;;
statusicon) mpcicon ;;
player) echo "$Control" ;;
coverloc) mpccover ;;
showcover) mpccover | xargs feh ;;
time) mpctime ;;
length) mpclength ;;
percent) mpcperc ;;
playlist) mpcsongpos ;;
lyrics) mpclyrics ;;
*) doc ;;
esac
;;
*)
case $1 in
next) playerctl next ;;
previous) playerctl previous ;;
toggle) playerctl play-pause ;;
title) title ;;
artist) artist ;;
album) album ;;
status) status ;;
statusicon) statusicon ;;
player) echo "$Control" ;;
coverloc) cover ;;
showcover) cover | xargs feh ;;
time) ctime ;;
length) length ;;
percent) echo "0" ;;
playlist) playlist ;;
lyrics) lyrics ;;
*) doc ;;
esac
;;
esac 2>/dev/null