Added some things
This commit is contained in:
parent
d32c6cc594
commit
c752cc613f
2 changed files with 18 additions and 1 deletions
|
@ -26,4 +26,6 @@ pub fn main() !void {
|
||||||
|
|
||||||
try json.decode_song_data(allocator, data);
|
try json.decode_song_data(allocator, data);
|
||||||
|
|
||||||
|
try url.download(allocator, "https://sp-pr-cf.audio.tidal.com/mediatracks/CAEaKwgDEidkYjY2ZWFkZTEwYmRmYjYyZTRiYjRiZmViNmU1YzNkM182MS5tcDQ/0.flac?Expires=1743711930&Signature=PRw1k4gM7m015MdIRZ81Xqn7mvzVBz1I9hpuYrT0lPu6DRvWQpAt2xxMvPCzEWwoFtH7CacZCjY7aeXbHanq6r68SHVkidkC0c1yZu~3Wk5BUri54Vh9sHr9Zcs6OmrtaaJv9XYRqeY9rDOwYykc47MrO6-cTaeW-Fp3UMaw5P243qPd3FZHYMYiKkaQtR791CgAmJ79ihzs8X0sKQrRKOH2jZ1Yy48qAIcyc5oyoKaN7owEPb-EbvS5h~vKXijK8jyb~dwzRZ0~uN3v3yREyBvrFL4~csnawkVL03mFlmPcRVnru96cVBm195j79OUrbYI64BmoC~4gkgSCR35zpQ__&Key-Pair-Id=K14LZCZ9QUI4JL");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
17
src/url.zig
17
src/url.zig
|
@ -23,7 +23,7 @@ pub fn fetch(allocator: std.mem.Allocator, url: []const u8) ![]u8 {
|
||||||
|
|
||||||
//dbg_print("Response status: {d}\n", .{req.response.status});
|
//dbg_print("Response status: {d}\n", .{req.response.status});
|
||||||
|
|
||||||
const body = try req.reader().readAllAlloc(allocator, 1024 * 64);
|
const body = try req.reader().readAllAlloc(allocator, 1024 * 1024 * 64);
|
||||||
|
|
||||||
if (req.response.status == .ok) {
|
if (req.response.status == .ok) {
|
||||||
return body;
|
return body;
|
||||||
|
@ -33,3 +33,18 @@ pub fn fetch(allocator: std.mem.Allocator, url: []const u8) ![]u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn download(allocator: std.mem.Allocator, url: []const u8) !void {
|
||||||
|
const data = try fetch(allocator, url);
|
||||||
|
defer allocator.free(data);
|
||||||
|
|
||||||
|
//dbg_print("Success", .{});
|
||||||
|
|
||||||
|
const file = try std.fs.cwd().createFile(
|
||||||
|
"test.flac",
|
||||||
|
.{ .read = true },
|
||||||
|
);
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
try file.writeAll(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue