1414# You should have received a copy of the GNU General Public License
1515# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17+ # History:
18+ # 2026-03-04, Ferus (feruscastor@proton.me)
19+ # 0.5.0: Update syntax from py2 to py3
20+ # Make player configurable
21+ # Add toggle for displaying cli output in buffer
22+
23+ settings = {
24+ "player" : ("streamlink -p /usr/bin/mpv" , "Full command for player" ),
25+ "output" : ("true" , "Display player output in buffer" ),
26+ }
27+
1728import weechat
1829
19- weechat .register ("weestreamer" , "Miblo" , "0.4.2 " , "GPL3" , "Streamlink companion for WeeChat" , "" , "" )
30+ weechat .register ("weestreamer" , "Miblo" , "0.5.0 " , "GPL3" , "Streamlink companion for WeeChat" , "" , "" )
2031
2132def stream (data , buffer , args ):
2233 bufserver = weechat .buffer_get_string (weechat .current_buffer (), "localvar_server" )
@@ -34,43 +45,60 @@ def stream(data, buffer, args):
3445 server = input [0 ]
3546 channel = input [1 ]
3647 else :
37- weechat .prnt (weechat .current_buffer (), "%sToo many arguments (%s ). Please see /help weestreamer"
38- % (weechat .prefix ("error" ),( len (input ) )))
48+ weechat .prnt (weechat .current_buffer (), "{}Too many arguments ({!s} ). Please see /help weestreamer"
49+ . format (weechat .prefix ("error" ), len (input )))
3950 return weechat .WEECHAT_RC_ERROR
4051
4152 # NOTE(matt): https://streamlink.github.io/plugin_matrix.html
42- servers = { "afreeca" :"http://play.afreeca.com/%s" % (channel ),
43- "hitbox" :"http://www.hitbox.tv/%s" % (channel ),
44- "twitch" :"http://www.twitch.tv/%s" % (channel ),
45- "ustream" :"http://www.ustream.tv/%s" % (channel .replace ("-" , "" ))}
53+ servers = {"afreeca" :"https://play.afreeca.com/{channel}"
54+ ,"hitbox" :"https://www.hitbox.tv/{channel}"
55+ ,"twitch" :"https://www.twitch.tv/{channel}"
56+ ,"ustream" :"https://www.ustream.tv/{channel}"
57+ }
4658
4759 streamurl = ""
4860 for key in servers .keys ():
4961 if key in server :
5062 streamurl = servers [key ]
5163 if not streamurl :
52- weechat .prnt (weechat .current_buffer (), "%sUnsupported server: %s "
53- % (weechat .prefix ("error" ), server ))
64+ weechat .prnt (weechat .current_buffer (), "{}Unsupported server: {} "
65+ . format (weechat .prefix ("error" ), server ))
5466 weechat .prnt (weechat .current_buffer (), "Currently supported servers:" )
5567 for key in sorted (servers .keys ()):
56- weechat .prnt (weechat .current_buffer (), " %s" % key )
68+ weechat .prnt (weechat .current_buffer (), " {}" . format ( key ) )
5769 return weechat .WEECHAT_RC_ERROR
5870
59- command = "streamlink %s %s" % (streamurl , quality )
71+ streamurl = streamurl .format (channel = channel )
72+
73+ if server == "ustream" :
74+ streamurl = streamurl .replace ("-" , "" )
6075
61- weechat .prnt (weechat .current_buffer (), "%sLAUNCHING: %s" % (weechat .prefix ("action" ), command ))
62- weechat .hook_process ("%s" % (command ), 0 , "handle_output" , "" )
76+ comm = weechat .config_get_plugin ("player" )
77+ command = "{} {} {}" .format (comm , streamurl , quality )
78+
79+ weechat .prnt (weechat .current_buffer (), "{}LAUNCHING: {}"
80+ .format (weechat .prefix ("action" ), command ))
81+ weechat .hook_process (command , 0 , "handle_output" , "" )
6382 return weechat .WEECHAT_RC_OK
6483
6584def handle_output (data , command , rc , out , err ):
6685 global process_output
6786 process_output = ""
6887 if out != "" :
6988 process_output += out
70- if int (rc ) >= 0 :
89+ if int (rc ) >= 0 and weechat . config_string_to_boolean ( weechat . config_get_plugin ( "output" )) :
7190 weechat .prnt (weechat .current_buffer (), process_output )
7291 return weechat .WEECHAT_RC_OK
7392
93+
94+ for option , value in settings .items ():
95+ if not weechat .config_is_set_plugin (option ):
96+ weechat .config_set_plugin (option , value [0 ])
97+ if int (weechat .info_get ("version_number" , "" )) >= 0x00030500 :
98+ weechat .config_set_desc_plugin (
99+ option , '{} (default: "{}")' .format (value [1 ], value [0 ])
100+ )
101+
74102weechat .hook_command ("weestreamer" , "Streamlink companion for WeeChat" ,
75103 "server channel" ,
76104
0 commit comments