Refactor
I'm not sure if this is a "good" use of an Arena Allocator, but I'm not getting any leaks, so maybe it's fine...
This commit is contained in:
parent
319c5aeae8
commit
4779e105d1
2 changed files with 217 additions and 255 deletions
|
|
@ -7,18 +7,14 @@ const Recording = Entities.Recording;
|
||||||
const Release = Entities.Release;
|
const Release = Entities.Release;
|
||||||
|
|
||||||
pub const Result = struct {
|
pub const Result = struct {
|
||||||
created: ?[]const u8 = null,
|
created: []const u8,
|
||||||
count: ?u32 = null,
|
count: u32,
|
||||||
offset: ?u32 = null,
|
offset: u32,
|
||||||
artists: ?[]Artist = null,
|
recordings: []Recording,
|
||||||
recordings: ?[]Recording = null,
|
|
||||||
@"error": ?[]const u8 = null,
|
|
||||||
help: ?[]const u8 = null,
|
|
||||||
|
|
||||||
pub fn getIDs(self: *const Result, smd: searchMetadata, pbo: parseByOptions) ?searchIDs {
|
pub fn getIDs(self: *const Result, smd: searchMetadata, pbo: parseByOptions) ?searchIDs {
|
||||||
if (self.count) |count| {
|
if (self.count == 0) return null;
|
||||||
if (count == 0) return null;
|
const sorted_recordings = self.recordings;
|
||||||
const sorted_recordings = self.recordings.?;
|
|
||||||
std.mem.sort(Recording, sorted_recordings, {}, Recording.lessThan);
|
std.mem.sort(Recording, sorted_recordings, {}, Recording.lessThan);
|
||||||
for (sorted_recordings) |rc| {
|
for (sorted_recordings) |rc| {
|
||||||
switch (pbo.parse) {
|
switch (pbo.parse) {
|
||||||
|
|
@ -29,18 +25,20 @@ pub const Result = struct {
|
||||||
if (std.mem.eql(u8, rc.title, smd.tn)) {
|
if (std.mem.eql(u8, rc.title, smd.tn)) {
|
||||||
break :song_song rc.id;
|
break :song_song rc.id;
|
||||||
//break :rc_loop;
|
//break :rc_loop;
|
||||||
}
|
} else break :song_song "";
|
||||||
},
|
},
|
||||||
.album => song_album: {
|
.album => song_album: {
|
||||||
if (rc.releases) |rls| {
|
if (rc.releases) |rls| {
|
||||||
for (rls) |rl| {
|
for (rls) |rl| {
|
||||||
if (std.mem.eql(u8, rl.title, smd.rgn)) {
|
if (std.mem.eql(u8, rl.title, smd.rn)) {
|
||||||
break :song_album rc.id;
|
break :song_album rc.id;
|
||||||
//break :rc_loop;
|
//break :rc_loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break :song_album "";
|
||||||
} else {
|
} else {
|
||||||
std.log.err("Could not find any releases", .{});
|
std.log.err("Could not find any releases", .{});
|
||||||
|
break :song_album "";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.artist => song_artist: {
|
.artist => song_artist: {
|
||||||
|
|
@ -51,8 +49,10 @@ pub const Result = struct {
|
||||||
//break :rc_loop;
|
//break :rc_loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break :song_artist "";
|
||||||
} else {
|
} else {
|
||||||
std.log.err("Could not find any artists", .{});
|
std.log.err("Could not find any artists", .{});
|
||||||
|
break :song_artist "";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.all => unreachable, // I'll do this later
|
.all => unreachable, // I'll do this later
|
||||||
|
|
@ -68,7 +68,7 @@ pub const Result = struct {
|
||||||
for (sorted_releases) |rl| {
|
for (sorted_releases) |rl| {
|
||||||
switch (pbo.specifyBy) {
|
switch (pbo.specifyBy) {
|
||||||
.song, .album => {
|
.song, .album => {
|
||||||
if (std.mem.eql(u8, rl.title, smd.rgn)) break :blk rl.id;
|
if (std.mem.eql(u8, rl.title, smd.rn)) break :blk rl.id;
|
||||||
},
|
},
|
||||||
.artist => {
|
.artist => {
|
||||||
if (rl.@"artist-credit") |acs| {
|
if (rl.@"artist-credit") |acs| {
|
||||||
|
|
@ -120,7 +120,6 @@ pub const Result = struct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -140,39 +139,27 @@ pub const searchMetadata = struct {
|
||||||
an: []const u8,
|
an: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maybe just use a HashMap...
|
//pub fn percentEncode(alloc: std.mem.Allocator, smd: searchMetadata) !searchMetadata {
|
||||||
pub const searchMetadataEncoded = struct {
|
// var output: searchMetadata = undefined;
|
||||||
tn: []const u8,
|
// inline for (std.meta.fields(searchMetadata)) |k| {
|
||||||
rn: []const u8,
|
// var encoded = std.ArrayList(u8).init(alloc);
|
||||||
an: []const u8,
|
// errdefer encoded.deinit();
|
||||||
|
// for (@field(smd, k.name)) |v| {
|
||||||
//pub fn deinit(self: *searchMetadata) void {
|
// if ((v >= 'A' and v <= 'Z') or (v >= 'a' and v <= 'z') or (v >= '0' and v <= '9') or v == '-' or v == '_' or v == '.' or v == '~') {
|
||||||
// self.alloc.free(self.tn.enc);
|
// try encoded.append(v);
|
||||||
// self.alloc.free(self.rn.enc);
|
// } else if (v == ' ') {
|
||||||
// self.alloc.free(self.an.enc);
|
// try encoded.append('+');
|
||||||
|
// } else {
|
||||||
|
// const hex = try std.fmt.allocPrint(alloc, "%{x}", .{v});
|
||||||
|
// defer alloc.free(hex);
|
||||||
|
// try encoded.appendSlice(hex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// @field(output, k.name) = try encoded.toOwnedSlice();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return output;
|
||||||
//}
|
//}
|
||||||
};
|
|
||||||
pub fn percentEncode(alloc: std.mem.Allocator, smd: searchMetadata) !searchMetadataEncoded {
|
|
||||||
var output: searchMetadataEncoded = undefined;
|
|
||||||
inline for (std.meta.fields(searchMetadata)) |k| {
|
|
||||||
var encoded = std.ArrayList(u8).init(alloc);
|
|
||||||
errdefer encoded.deinit();
|
|
||||||
for (@field(smd, k.name)) |v| {
|
|
||||||
if ((v >= 'A' and v <= 'Z') or (v >= 'a' and v <= 'z') or (v >= '0' and v <= '9') or v == '-' or v == '_' or v == '.' or v == '~') {
|
|
||||||
try encoded.append(v);
|
|
||||||
} else if (v == ' ') {
|
|
||||||
try encoded.append('+');
|
|
||||||
} else {
|
|
||||||
const hex = try std.fmt.allocPrint(alloc, "%{x}", .{v});
|
|
||||||
defer alloc.free(hex);
|
|
||||||
try encoded.appendSlice(hex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@field(output, k.name) = try encoded.toOwnedSlice();
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const searchIDs = union {
|
pub const searchIDs = union {
|
||||||
id: []const u8,
|
id: []const u8,
|
||||||
|
|
@ -183,26 +170,28 @@ pub const searchIDs = union {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
test "pe_jethro_tull" {
|
//test "pe_jethro_tull" {
|
||||||
const test_alloc = std.testing.allocator;
|
// const test_alloc = std.testing.allocator;
|
||||||
var jt = searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "Aqualung" }, .rn = .{ .dec = "Aqualung" }, .an = .{ .dec = "Jethro Tull" } };
|
// const jt = searchMetadata{ .tn = "Aqualung ", .rn = "Aqualung", .an = "Jethro Tull" };
|
||||||
try jt.percentEncode();
|
// const jt_enc = try percentEncode(test_alloc, jt);
|
||||||
defer jt.deinit();
|
// defer test_alloc.free(jt_enc);
|
||||||
try testing.expect(std.mem.eql(u8, jt.an.enc, "Jethro+Tull"));
|
// //defer jt.deinit();
|
||||||
}
|
// try testing.expect(std.mem.eql(u8, jt_enc.an, "Jethro+Tull"));
|
||||||
|
//}
|
||||||
test "pe_aphex_twin" {
|
//
|
||||||
const test_alloc = std.testing.allocator;
|
//test "pe_aphex_twin" {
|
||||||
var at = searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "#3" }, .rn = .{ .dec = "Selected Ambient Works Volume II" }, .an = .{ .dec = "Aphex Twin" } };
|
// const test_alloc = std.testing.allocator;
|
||||||
try at.percentEncode();
|
// var at = searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "#3" }, .rn = .{ .dec = "Selected Ambient Works Volume II" }, .an = .{ .dec = "Aphex Twin" } };
|
||||||
defer at.deinit();
|
// try at.percentEncode();
|
||||||
try testing.expect(std.mem.eql(u8, at.tn.enc, "%233"));
|
// defer at.deinit();
|
||||||
}
|
// try testing.expect(std.mem.eql(u8, at.tn.enc, "%233"));
|
||||||
|
//}
|
||||||
test "pe_bon_iver" {
|
//
|
||||||
const test_alloc = std.testing.allocator;
|
//test "pe_bon_iver" {
|
||||||
var bi = searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "21 M♢♢N WATER" }, .rn = .{ .dec = "22, a Million" }, .an = .{ .dec = "Bon Iver" } };
|
// const test_alloc = std.testing.allocator;
|
||||||
try bi.percentEncode();
|
// var bi = searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "21 M♢♢N WATER" }, .rn = .{ .dec = "22, a Million" }, .an = .{ .dec = "Bon Iver" } };
|
||||||
defer bi.deinit();
|
// try bi.percentEncode();
|
||||||
try testing.expect(std.mem.eql(u8, bi.tn.enc, "21+M%e2%99%a2%e2%99%a2N+WATER"));
|
// defer bi.deinit();
|
||||||
}
|
// try testing.expect(std.mem.eql(u8, bi.tn.enc, "21+M%e2%99%a2%e2%99%a2N+WATER"));
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
|
|
||||||
137
src/root.zig
137
src/root.zig
|
|
@ -1,6 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
//const zeit = @import("zeit");
|
|
||||||
const Entities = @import("Entities.zig");
|
const Entities = @import("Entities.zig");
|
||||||
const Alias = @import("Alias.zig");
|
const Alias = @import("Alias.zig");
|
||||||
const MBQ = @import("MusicBrainzQuery.zig");
|
const MBQ = @import("MusicBrainzQuery.zig");
|
||||||
|
|
@ -8,18 +7,31 @@ const Client = std.http.Client;
|
||||||
|
|
||||||
pub const user_agent: []const u8 = "ZuletztMBClient/0.0.1 (swebbguy@gmail.com)";
|
pub const user_agent: []const u8 = "ZuletztMBClient/0.0.1 (swebbguy@gmail.com)";
|
||||||
|
|
||||||
pub fn mbSearch(alloc: std.mem.Allocator, smd: MBQ.searchMetadata) !?MBQ.Result {
|
pub fn mbSearch(alloc: std.mem.Allocator, smd: MBQ.searchMetadata) !MBQ.Result {
|
||||||
const encoded = try MBQ.percentEncode(alloc, smd);
|
var encoded: MBQ.searchMetadata = undefined;
|
||||||
|
inline for (std.meta.fields(MBQ.searchMetadata)) |k| {
|
||||||
|
var code = std.ArrayList(u8).init(alloc);
|
||||||
|
errdefer code.deinit();
|
||||||
|
for (@field(smd, k.name)) |v| {
|
||||||
|
if ((v >= 'A' and v <= 'Z') or (v >= 'a' and v <= 'z') or (v >= '0' and v <= '9') or v == '-' or v == '_' or v == '.' or v == '~') {
|
||||||
|
try code.append(v);
|
||||||
|
} else if (v == ' ') {
|
||||||
|
try code.append('+');
|
||||||
|
} else {
|
||||||
|
const hex = try std.fmt.allocPrint(alloc, "%{x}", .{v});
|
||||||
|
defer alloc.free(hex);
|
||||||
|
try code.appendSlice(hex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@field(encoded, k.name) = try code.toOwnedSlice();
|
||||||
|
}
|
||||||
|
|
||||||
// Might consider making just one of these and passing it around
|
// Might consider making just one of these and passing it around
|
||||||
var client = Client{ .allocator = alloc };
|
var client = Client{ .allocator = alloc };
|
||||||
defer client.deinit();
|
|
||||||
|
|
||||||
const query: []const u8 = try std.fmt.allocPrint(alloc, "https://musicbrainz.org/ws/2/recording/?query=\"{s}\"%20AND%20artist:\"{s}\"%20AND%20release:\"{s}\"&fmt=json", .{ encoded.tn, encoded.an, encoded.rn });
|
const query: []const u8 = try std.fmt.allocPrint(alloc, "https://musicbrainz.org/ws/2/recording/?query=\"{s}\"%20AND%20artist:\"{s}\"%20AND%20release:\"{s}\"&fmt=json", .{ encoded.tn, encoded.an, encoded.rn });
|
||||||
defer alloc.free(query);
|
|
||||||
|
|
||||||
var ar = std.ArrayList(u8).init(alloc);
|
var ar = std.ArrayList(u8).init(alloc);
|
||||||
errdefer ar.deinit();
|
|
||||||
|
|
||||||
const response: Client.FetchResult = try client.fetch(.{ .response_storage = .{ .dynamic = &ar }, .location = .{ .url = query }, .method = .GET, .headers = .{ .user_agent = .{ .override = user_agent } } });
|
const response: Client.FetchResult = try client.fetch(.{ .response_storage = .{ .dynamic = &ar }, .location = .{ .url = query }, .method = .GET, .headers = .{ .user_agent = .{ .override = user_agent } } });
|
||||||
|
|
||||||
|
|
@ -27,7 +39,6 @@ pub fn mbSearch(alloc: std.mem.Allocator, smd: MBQ.searchMetadata) !?MBQ.Result
|
||||||
0...299 => std.log.debug("Success", .{}),
|
0...299 => std.log.debug("Success", .{}),
|
||||||
300...399 => {
|
300...399 => {
|
||||||
std.log.err("Redirected", .{});
|
std.log.err("Redirected", .{});
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
400...511 => {
|
400...511 => {
|
||||||
std.log.err("Get rekt {s}", .{ar.items});
|
std.log.err("Get rekt {s}", .{ar.items});
|
||||||
|
|
@ -35,26 +46,26 @@ pub fn mbSearch(alloc: std.mem.Allocator, smd: MBQ.searchMetadata) !?MBQ.Result
|
||||||
},
|
},
|
||||||
512 => {
|
512 => {
|
||||||
std.log.err("Need to login", .{});
|
std.log.err("Need to login", .{});
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, alloc, ar.items, .{ .ignore_unknown_fields = true });
|
const json = try std.json.parseFromSliceLeaky(MBQ.Result, alloc, ar.items, .{ .ignore_unknown_fields = true });
|
||||||
errdefer json.deinit();
|
|
||||||
|
|
||||||
return json.value;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
test "arid_via_recording" {
|
test "arid_via_recording" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .tn = "Veni veni Emmanuel", .an = "iamthemorning", .rn = "Counting the Ghosts" };
|
const metadata = MBQ.searchMetadata{ .tn = "Veni veni Emmanuel", .an = "iamthemorning", .rn = "Counting the Ghosts" };
|
||||||
const iatm_id: []const u8 = "5854a6de-af8f-4b99-8710-cb47d6436a19";
|
const iatm_id: []const u8 = "5854a6de-af8f-4b99-8710-cb47d6436a19";
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, metadata);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
if (search_result) |rs| {
|
|
||||||
const id = rs.getIDs(metadata, .{ .parse = .artist, .specifyBy = .song });
|
const id = search_result.getIDs(metadata, .{ .parse = .artist, .specifyBy = .song });
|
||||||
|
|
||||||
std.Thread.sleep(1000000000);
|
std.Thread.sleep(1000000000);
|
||||||
|
|
||||||
|
|
@ -62,25 +73,18 @@ test "arid_via_recording" {
|
||||||
try testing.expect(std.mem.eql(u8, out.id, iatm_id));
|
try testing.expect(std.mem.eql(u8, out.id, iatm_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
test "arid_via_recording_multiple_artists_1" {
|
test "arid_via_recording_multiple_artists_1" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "Roll Me Up And Smoke Me When I Die" }, .an = .{ .dec = "Lyle Lovett" }, .rn = .{ .dec = "Willie Nelson American Outlaw" } };
|
const metadata = MBQ.searchMetadata{ .tn = "Roll Me Up And Smoke Me When I Die", .an = "Lyle Lovett", .rn = "Willie Nelson American Outlaw" };
|
||||||
const ll_id: []const u8 = "7241e3ed-5ad4-4849-94df-6858ea833472";
|
const ll_id: []const u8 = "7241e3ed-5ad4-4849-94df-6858ea833472";
|
||||||
|
|
||||||
var mb_result = std.ArrayList(u8).init(test_alloc);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
defer mb_result.deinit();
|
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, &mb_result, metadata);
|
const id = search_result.getIDs(metadata, .{ .parse = .artist, .specifyBy = .song });
|
||||||
|
|
||||||
if (search_result) |sr| {
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, test_alloc, sr, .{ .ignore_unknown_fields = true });
|
|
||||||
defer json.deinit();
|
|
||||||
|
|
||||||
const result: MBQ.Result = json.value;
|
|
||||||
const id = result.getIDs(metadata, .{ .parse = .artist, .specifyBy = .song });
|
|
||||||
|
|
||||||
std.Thread.sleep(1000000000);
|
std.Thread.sleep(1000000000);
|
||||||
|
|
||||||
|
|
@ -88,25 +92,18 @@ test "arid_via_recording_multiple_artists_1" {
|
||||||
try testing.expect(std.mem.eql(u8, out.id, ll_id));
|
try testing.expect(std.mem.eql(u8, out.id, ll_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
test "rgid_via_recording" {
|
test "rgid_via_recording" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "I Of The Storm" }, .rn = .{ .dec = "Beneath the Skin" }, .an = .{ .dec = "Of Monsters and Men" } };
|
const metadata = MBQ.searchMetadata{ .tn = "I Of The Storm", .rn = "Beneath the Skin", .an = "Of Monsters and Men" };
|
||||||
const bts_id: []const u8 = "4f4f5b98-45ac-4b47-addb-66b501473bd8";
|
const bts_id: []const u8 = "4f4f5b98-45ac-4b47-addb-66b501473bd8";
|
||||||
|
|
||||||
var mb_result = std.ArrayList(u8).init(test_alloc);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
defer mb_result.deinit();
|
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, &mb_result, metadata);
|
const id = search_result.getIDs(metadata, .{ .parse = .album, .specifyBy = .song });
|
||||||
|
|
||||||
if (search_result) |sr| {
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, test_alloc, sr, .{ .ignore_unknown_fields = true });
|
|
||||||
defer json.deinit();
|
|
||||||
|
|
||||||
const result: MBQ.Result = json.value;
|
|
||||||
const id = result.getIDs(metadata, .{ .parse = .album, .specifyBy = .song });
|
|
||||||
|
|
||||||
std.Thread.sleep(1000000000);
|
std.Thread.sleep(1000000000);
|
||||||
|
|
||||||
|
|
@ -114,25 +111,18 @@ test "rgid_via_recording" {
|
||||||
try testing.expect(std.mem.eql(u8, out.id, bts_id));
|
try testing.expect(std.mem.eql(u8, out.id, bts_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
test "rgid_via_recording_multiple_artists_2" {
|
test "rgid_via_recording_multiple_artists_2" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "Hesitating Beauty" }, .rn = .{ .dec = "Mermaid Avenue" }, .an = .{ .dec = "Wilco" } };
|
const metadata = MBQ.searchMetadata{ .tn = "Hesitating Beauty", .rn = "Mermaid Avenue", .an = "Wilco" };
|
||||||
const wilco_id: []const u8 = "9ba73bf8-6c15-4bd2-8da1-e2292538f617";
|
const wilco_id: []const u8 = "9ba73bf8-6c15-4bd2-8da1-e2292538f617";
|
||||||
|
|
||||||
var mb_result = std.ArrayList(u8).init(test_alloc);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
defer mb_result.deinit();
|
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, &mb_result, metadata);
|
const id = search_result.getIDs(metadata, .{ .parse = .album, .specifyBy = .song });
|
||||||
|
|
||||||
if (search_result) |sr| {
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, test_alloc, sr, .{ .ignore_unknown_fields = true });
|
|
||||||
defer json.deinit();
|
|
||||||
|
|
||||||
const result: MBQ.Result = json.value;
|
|
||||||
const id = result.getIDs(metadata, .{ .parse = .album, .specifyBy = .song });
|
|
||||||
|
|
||||||
std.Thread.sleep(1000000000);
|
std.Thread.sleep(1000000000);
|
||||||
if (id) |out| {
|
if (id) |out| {
|
||||||
|
|
@ -140,53 +130,36 @@ test "rgid_via_recording_multiple_artists_2" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//try testing.expect(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "rid_aqualung" {
|
test "rid_aqualung" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "Aqualung" }, .rn = .{ .dec = "Aqualung" }, .an = .{ .dec = "Jethro Tull" } };
|
const metadata = MBQ.searchMetadata{ .tn = "Aqualung", .rn = "Aqualung", .an = "Jethro Tull" };
|
||||||
const aqualung_id: []const u8 = "2621d113-3a9f-41f9-a0f2-b9459f86e8e9";
|
const aqualung_id: []const u8 = "2621d113-3a9f-41f9-a0f2-b9459f86e8e9";
|
||||||
|
|
||||||
var mb_result = std.ArrayList(u8).init(test_alloc);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
defer mb_result.deinit();
|
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, &mb_result, metadata);
|
const id = search_result.getIDs(metadata, .{ .parse = .song, .specifyBy = .song });
|
||||||
|
|
||||||
if (search_result) |sr| {
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, test_alloc, sr, .{ .ignore_unknown_fields = true });
|
|
||||||
defer json.deinit();
|
|
||||||
|
|
||||||
const result: MBQ.Result = json.value;
|
|
||||||
const id = result.getIDs(metadata, .{ .parse = .song, .specifyBy = .song });
|
|
||||||
|
|
||||||
if (id) |out| {
|
if (id) |out| {
|
||||||
try testing.expect(std.mem.eql(u8, out.id, aqualung_id));
|
try testing.expect(std.mem.eql(u8, out.id, aqualung_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
test "rid_battery" {
|
test "rid_battery" {
|
||||||
const test_alloc = std.testing.allocator;
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const test_alloc = arena.allocator();
|
||||||
|
|
||||||
const metadata = MBQ.searchMetadata{ .alloc = test_alloc, .tn = .{ .dec = "Battery" }, .rn = .{ .dec = "Master of Puppets" }, .an = .{ .dec = "Metallica" } };
|
const metadata = MBQ.searchMetadata{ .tn = "Battery", .rn = "Master of Puppets", .an = "Metallica" };
|
||||||
const battery_id: []const u8 = "3bfda26a-49fa-4bc4-a4d6-8bbfa0767ab7";
|
const battery_id: []const u8 = "3bfda26a-49fa-4bc4-a4d6-8bbfa0767ab7";
|
||||||
|
|
||||||
var mb_result = std.ArrayList(u8).init(test_alloc);
|
const search_result = try mbSearch(test_alloc, metadata);
|
||||||
defer mb_result.deinit();
|
|
||||||
|
|
||||||
const search_result = try mbSearch(test_alloc, &mb_result, metadata);
|
const id = search_result.getIDs(metadata, .{ .parse = .song, .specifyBy = .song });
|
||||||
|
|
||||||
if (search_result) |sr| {
|
|
||||||
const json = try std.json.parseFromSlice(MBQ.Result, test_alloc, sr, .{ .ignore_unknown_fields = true });
|
|
||||||
defer json.deinit();
|
|
||||||
|
|
||||||
const result: MBQ.Result = json.value;
|
|
||||||
const id = result.getIDs(metadata, .{ .parse = .song, .specifyBy = .song });
|
|
||||||
|
|
||||||
if (id) |out| {
|
if (id) |out| {
|
||||||
try testing.expect(std.mem.eql(u8, out.id, battery_id));
|
try testing.expect(std.mem.eql(u8, out.id, battery_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue