~nature/yt-cli

07fe930443d8e522d29ad924b126bfd859df4dd1 — LordNature 1 year, 5 months ago 5aed3fa
wrapper.sh: Added integration with dmenu and mpv.

- `add` function simply adds a channelID to the subscription list.
- `list` function gets the list, pipes it to dmenu, and then uses POSIX RegEx to
  resolve the title and video ID and pass to mpv.
- `usage` prints the commands to use the program.
1 files changed, 35 insertions(+), 5 deletions(-)

M wrapper.sh
M wrapper.sh => wrapper.sh +35 -5
@@ 12,14 12,44 @@ alias notify-send="notify-send -t 4000"
# Set dmenu prompt
alias dmenu="dmenu -p 'play >' -l 10"

add() {
	yt-cli -add $1 && notify-send "YouTube CLI" "Added $1"
}

list() {
	# todo: error check
	id=$(yt-cli -list | dmenu)
	# remove [date] and (id) for title
	title=${id#\[*\]}
	title=${title%(*)}
	# get ID from title
	id=${id#*(}
	id=${id%)}
	mpv "https://youtube.com/watch?v=$id" > /dev/null < /dev/null &
	notify-send "YouTube CLI" "Playing $title"
}

usage() {
	printf "Usage of %s\n" "$0"
	printf "  -a, add, -add <channelID>\n"
	printf "\tAdd a channel to subscription list.\n"
	printf "  -l, list, -list\n"
	printf "\tList subscriptions out to dmenu and play video.\n"
}

case $1 in
	add)
		channelName="example"
		notify-send "YouTube CLI" "Added $channelName."
		printf "%s\n" "Default placeholder."
	add|--add|-add|-a)
		add $2
		;;
	list|--list|-list|-l)
		list	
		;;
	help|--help|-help|-h)
		usage
		;;
	*)
		printf "%s\n" "Default placeholder."
		usage
		exit 1
		;;
esac