-
Notifications
You must be signed in to change notification settings - Fork 0
/
p
executable file
·44 lines (34 loc) · 1.3 KB
/
p
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
#!/usr/bin/env fish
# p - Play media with mpv, joining its twitch chat via irc (weechat) if it's a twitch stream.
# once the stream is stopped, the channel will be exited.
# this is just a wrapper for mpv and doesn't alter its behavior other than that.
# you'll need to have weechat's fifo plugin enabled for this to work.
# usage:
# p <mpv-arguments...>
# example:
# play my twitch stream and join its chat:
# p 'https://www.twitch.tv/defaultxr/'
# code:
argparse -n p --ignore-unknown 'h/help' -- $argv
if test -n "$_flag_h"
echo "p - Play media with mpv."
echo "Usage: p [arguments]"
echo
echo " -h/--help - Print help and exit."
exit
end
set url $argv[1]
set user ""
set is_twitch (test -e ~/.weechat/weechat_fifo; and string match --quiet --regex -- '^https\?://\(www.\|go.\)\?twitch.tv/' $url; echo $status)
set weechat_open (pidof weechat; echo $status)
if test "$is_twitch" = '0'; and test "$weechat_open" = '0'
set user (string lower (string split / $url)[4])
echo Joining \#$user...
echo "*/window 1" >~/.weechat/weechat_fifo
echo "irc.server.twitch */join #$user" >~/.weechat/weechat_fifo
end
mpv $argv
if test "$is_twitch" = '0'; and test "$weechat_open" = '0'
echo Closing \#$user...
echo "irc.server.twitch */close irc.twitch.#$user" >~/.weechat/weechat_fifo
end