~nature/yt-cli

ref: 07fe930443d8e522d29ad924b126bfd859df4dd1 yt-cli/wrapper.sh -rwxr-xr-x 1.3 KiB
07fe9304LordNature wrapper.sh: Added integration with dmenu and mpv. 1 year, 6 months ago
                                                                                
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# wrapper.sh example
# Dep: youtube-dl, mpv, notify-send, dmenu
# This script will be a wrapper of the Go programming using handling pipe data.
# The idea is that this will allow keep the program to stick to doing one thing.
# While it is possible to use pipes in Golang, I find this approach to be better
# for integration into a Linux system. However, this could be changed in the
# future and integrated into the Go program. We'll see. THIS IS AN EXAMPLE.

# Set timeout to 4s
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|--add|-add|-a)
		add $2
		;;
	list|--list|-list|-l)
		list	
		;;
	help|--help|-help|-h)
		usage
		;;
	*)
		usage
		exit 1
		;;
esac

exit