Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions python/weestreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
# 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.4.2", "GPL3", "Streamlink companion for 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")
Expand All @@ -34,43 +45,60 @@ def stream(data, buffer, args):
server = input[0]
channel = input[1]
else:
weechat.prnt(weechat.current_buffer(), "%sToo many arguments (%s). Please see /help weestreamer"
% (weechat.prefix("error"),(len(input))))
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":"http://play.afreeca.com/%s" % (channel),
"hitbox":"http://www.hitbox.tv/%s" % (channel),
"twitch":"http://www.twitch.tv/%s" % (channel),
"ustream":"http://www.ustream.tv/%s" % (channel.replace("-", ""))}
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(), "%sUnsupported server: %s"
% (weechat.prefix("error"), server))
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(), " %s" % key)
weechat.prnt(weechat.current_buffer(), " {}".format(key))
return weechat.WEECHAT_RC_ERROR

command = "streamlink %s %s" % (streamurl, quality)
streamurl = streamurl.format(channel=channel)

if server == "ustream":
streamurl = streamurl.replace("-", "")

weechat.prnt(weechat.current_buffer(), "%sLAUNCHING: %s" % (weechat.prefix("action"), command))
weechat.hook_process("%s" % (command), 0, "handle_output", "")
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:
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",

Expand Down