summaryrefslogtreecommitdiffstats
path: root/.local/bin/music
blob: bb1869be4cfec3862dcf8d546ad7d73c5660a81d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

library="$(awk '/-----/{y=1;next}y' "$HOME/vault/src/blog.$DOMAIN/content/music.md")"
artists="$(printf %s "$library" | awk -F"|" '{print $2}')"
titles="$(printf %s "$library" | awk -F"[][]" '{print $2}')"

function _play() {
	if [ -z "$1" ]; then
		echo "Selection is empty, quitting"
		exit 1
	fi
	printf "Playing %s\\n" "$1"
	mpv --volume=75 --no-video --ytdl-format=bestaudio ytdl://ytsearch:"$1 audio"
}
function find_song() {
	choice=$(paste <(echo "$artists") <(echo "$titles") --delimiters '' | fzf)
	_play "$choice"
}
function main {
	case "$1" in
	a | alb | album) find_album ;;
	g | gen | genre) find_genre ;;
	p | pls | playlist) gen_playlist ;;
	*) find_song ;;
	esac
}

main "$@"