summaryrefslogtreecommitdiff
path: root/sh/dyafk
blob: 005b39fd54549f95b8410a2e8a1a4122d8654ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# DouYu AFK

# maybe another way: https://open.douyu.com/source

while :; do
	# credit: MIT licensed https://github.com/DIYgod/RSSHub/blob/master/lib/routes/douyu/room.ts
	if [ "$(curl -s https://www.douyu.com/betard/9640128 | jq '.room.show_status')" -eq 1 ]; then
		if ! pidof -q firefox; then
			firefox --headless --profile "$HOME/.mozilla/firefox/dyafk" https://www.douyu.com/9640128 &
		fi
	else
		if pidof -q firefox; then
			kill $(pidof firefox) 2>/dev/null
			# for logging, so I know when firefox killed, which also need that `if pidof -q firefox`
			echo 'kill firefox'
		fi
	fi
	# open.douyu.com AUP for api request seems very high, about 6k/min per api? see https://open.douyu.com/source/api/5
	# although I don't use open.douyu.com api but can be used as a reference, so I think 1 request per minute is ok
	sleep 60
done