mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-09-27 20:48:53 +02:00
improve playtwitch
This commit is contained in:
parent
e726d419e3
commit
d1bf3c7857
2 changed files with 10 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in a new issue