improve playtwitch

This commit is contained in:
LordMZTE 2022-07-09 15:54:58 +02:00
parent e726d419e3
commit d1bf3c7857
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 10 additions and 3 deletions

View file

@ -117,6 +117,7 @@ fn readChannels(alloc: std.mem.Allocator) ![]u8 {
const home = try std.os.getenv("HOME") orelse error.HomeNotSet;
const fname = try std.fmt.allocPrint(alloc, "{s}/.config/playtwitch/channels", .{home});
defer alloc.free(fname);
std.log.info("Reading channels from {s}", .{fname});
const file = try std.fs.cwd().openFile(fname, .{});
return try file.readToEndAlloc(alloc, 1024 * 1024 * 5);
}
@ -161,10 +162,13 @@ fn onOtherStreamActivate(entry: *c.GtkEntry, data: *OtherStreamActivateData) voi
fn start(state: *GuiState, chatty: bool, channel: []const u8) !void {
if (channel.len == 0) {
std.log.warn("Exiting due to attempt to start empty channel", .{});
return;
}
std.log.info("Starting for channel {s} (chatty: {})", .{ channel, chatty });
const url = try std.fmt.allocPrint(state.alloc, "https://twitch.tv/{s}", .{channel});
defer state.alloc.free(url);
const streamlink_argv = [_][]const u8{ "streamlink", url };
var streamlink_child = std.ChildProcess.init(&streamlink_argv, state.alloc);
try streamlink_child.spawn();

View file

@ -9,6 +9,10 @@ pub fn log(
comptime format: []const u8,
args: anytype,
) void {
const Buf = struct {
pub threadlocal var fmt_buf: [512]u8 = undefined;
};
const g_level = switch (level) {
.err => c.G_LOG_LEVEL_ERROR,
.warn => c.G_LOG_LEVEL_WARNING,
@ -16,12 +20,11 @@ pub fn log(
.debug => c.G_LOG_LEVEL_DEBUG,
};
const s = std.fmt.allocPrintZ(
std.heap.c_allocator,
const s = std.fmt.bufPrintZ(
&Buf.fmt_buf,
format,
args,
) catch return;
defer std.heap.c_allocator.free(s);
var fields = [_]c.GLogField{
c.GLogField{