-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathweestreamer.py
More file actions
133 lines (115 loc) · 4.94 KB
/
weestreamer.py
File metadata and controls
133 lines (115 loc) · 4.94 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Copyright (c) 2015 by Miblo <miblodelcarpio@gmail.com>
# All rights reserved
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# History:
# 2026-03-04, Ferus (feruscastor@proton.me)
# 0.5.0: Update syntax from py2 to py3
# Make player configurable
# Add toggle for displaying cli output in buffer
settings = {
"player": ("streamlink -p /usr/bin/mpv", "Full command for player"),
"output": ("true", "Display player output in buffer"),
}
import weechat
weechat.register("weestreamer", "Miblo", "0.5.0", "GPL3", "Streamlink companion for WeeChat", "", "")
def stream(data, buffer, args):
bufserver = weechat.buffer_get_string(weechat.current_buffer(), "localvar_server")
bufchannel = weechat.buffer_get_string(weechat.current_buffer(), "localvar_channel").lstrip("#")
quality = "best"
input = args.split()
if not input:
server = bufserver
channel = bufchannel
elif len(input) == 1:
server = bufserver
channel = input[0]
elif len(input) == 2:
server = input[0]
channel = input[1]
else:
weechat.prnt(weechat.current_buffer(), "{}Too many arguments ({!s}). Please see /help weestreamer"
.format(weechat.prefix("error"), len(input)))
return weechat.WEECHAT_RC_ERROR
# NOTE(matt): https://streamlink.github.io/plugin_matrix.html
servers = {"afreeca":"https://play.afreeca.com/{channel}"
,"hitbox":"https://www.hitbox.tv/{channel}"
,"twitch":"https://www.twitch.tv/{channel}"
,"ustream":"https://www.ustream.tv/{channel}"
}
streamurl = ""
for key in servers.keys():
if key in server:
streamurl = servers[key]
if not streamurl:
weechat.prnt(weechat.current_buffer(), "{}Unsupported server: {}"
.format(weechat.prefix("error"), server))
weechat.prnt(weechat.current_buffer(), "Currently supported servers:")
for key in sorted(servers.keys()):
weechat.prnt(weechat.current_buffer(), " {}".format(key))
return weechat.WEECHAT_RC_ERROR
streamurl = streamurl.format(channel=channel)
if server == "ustream":
streamurl = streamurl.replace("-", "")
comm = weechat.config_get_plugin("player")
command = "{} {} {}".format(comm, streamurl, quality)
weechat.prnt(weechat.current_buffer(), "{}LAUNCHING: {}"
.format(weechat.prefix("action"), command))
weechat.hook_process(command, 0, "handle_output", "")
return weechat.WEECHAT_RC_OK
def handle_output(data, command, rc, out, err):
global process_output
process_output = ""
if out != "":
process_output += out
if int(rc) >= 0 and weechat.config_string_to_boolean(weechat.config_get_plugin("output")):
weechat.prnt(weechat.current_buffer(), process_output)
return weechat.WEECHAT_RC_OK
for option, value in settings.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, value[0])
if int(weechat.info_get("version_number", "")) >= 0x00030500:
weechat.config_set_desc_plugin(
option, '{} (default: "{}")'.format(value[1], value[0])
)
weechat.hook_command("weestreamer", "Streamlink companion for WeeChat",
"server channel",
"Run /weestreamer without any arguments while in a channel on a supported irc\n"
"server to launch the stream associated with that channel.\n"
"\n"
"You may optionally pass the server and / or channel (in that order) to launch\n"
"the required stream from any channel, e.g.:\n"
" /weestreamer twitch handmade_hero\n"
" /weestreamer handmade_hero\n"
"\n"
"Currently supported servers:\n"
" afreeca\n"
" hitbox\n"
" twitch\n"
" ustream\n"
"\n"
"\n"
"Troubleshooting: If you expect that your current server should be supported but\n"
"weestreamer keeps erroring, please check the name of the server by running:\n"
"\n"
" /buffer localvar\n"
"\n"
"If you have named the server such that it doesn't contain the string in\n"
"\"Currently supported servers\" (above), weestreamer will not recognise it.",
# NOTE(matt): list of valid parameters
"afreeca"
" || hitbox"
" || twitch"
" || ustream",
"stream", "")