diff --git a/Alias.zig b/Alias.zig deleted file mode 100644 index e69de29..0000000 diff --git a/build.zig b/build.zig index cc733a9..beffc71 100644 --- a/build.zig +++ b/build.zig @@ -29,20 +29,20 @@ pub fn build(b: *std.Build) void { }); // We will also create a module for our other entry point, 'main.zig'. - const exe_mod = b.createModule(.{ - // `root_source_file` is the Zig "entry point" of the module. If a module - // only contains e.g. external object files, you can make this `null`. - // In this case the main source file is merely a path, however, in more - // complicated build scripts, this could be a generated file. - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - }); + //const exe_mod = b.createModule(.{ + // // `root_source_file` is the Zig "entry point" of the module. If a module + // // only contains e.g. external object files, you can make this `null`. + // // In this case the main source file is merely a path, however, in more + // // complicated build scripts, this could be a generated file. + // .root_source_file = b.path("src/main.zig"), + // .target = target, + // .optimize = optimize, + //}); // Modules can depend on one another using the `std.Build.Module.addImport` function. // This is what allows Zig source code to use `@import("foo")` where 'foo' is not a // file path. In this case, we set up `exe_mod` to import `lib_mod`. - exe_mod.addImport("muzigbrainz_lib", lib_mod); + //exe_mod.addImport("muzigbrainz_lib", lib_mod); // Now, we will create a static library based on the module we created above. // This creates a `std.Build.Step.Compile`, which is the build step responsible @@ -60,41 +60,41 @@ pub fn build(b: *std.Build) void { // This creates another `std.Build.Step.Compile`, but this one builds an executable // rather than a static library. - const exe = b.addExecutable(.{ - .name = "muzigbrainz", - .root_module = exe_mod, - }); + //const exe = b.addExecutable(.{ + // .name = "muzigbrainz", + // .root_module = exe_mod, + //}); const zig_time_dep = b.dependency("zeit", .{}); - exe.root_module.addImport("zeit", zig_time_dep.module("zeit")); + lib.root_module.addImport("zeit", zig_time_dep.module("zeit")); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). - b.installArtifact(exe); + //b.installArtifact(exe); // This *creates* a Run step in the build graph, to be executed when another // step is evaluated that depends on it. The next line below will establish // such a dependency. - const run_cmd = b.addRunArtifact(exe); + //const run_cmd = b.addRunArtifact(exe); // By making the run step depend on the install step, it will be run from the // installation directory rather than directly from within the cache directory. // This is not necessary, however, if the application depends on other installed // files, this ensures they will be present and in the expected location. - run_cmd.step.dependOn(b.getInstallStep()); + //run_cmd.step.dependOn(b.getInstallStep()); // This allows the user to pass arguments to the application in the build // command itself, like this: `zig build run -- arg1 arg2 etc` - if (b.args) |args| { - run_cmd.addArgs(args); - } + //if (b.args) |args| { + // run_cmd.addArgs(args); + //} // This creates a build step. It will be visible in the `zig build --help` menu, // and can be selected like this: `zig build run` // This will evaluate the `run` step rather than the default, which is "install". - const run_step = b.step("run", "Run the app"); - run_step.dependOn(&run_cmd.step); + //const run_step = b.step("run", "Run the app"); + //run_step.dependOn(&run_cmd.step); // Creates a step for unit testing. This only builds the test executable // but does not run it. @@ -102,18 +102,20 @@ pub fn build(b: *std.Build) void { .root_module = lib_mod, }); + lib_unit_tests.root_module.addImport("zeit", zig_time_dep.module("zeit")); + const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); - const exe_unit_tests = b.addTest(.{ - .root_module = exe_mod, - }); + //const exe_unit_tests = b.addTest(.{ + // .root_module = exe_mod, + //}); - const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + //const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); // Similar to creating the run step earlier, this exposes a `test` step to // the `zig build --help` menu, providing a way for the user to request // running the unit tests. const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_lib_unit_tests.step); - test_step.dependOn(&run_exe_unit_tests.step); + //test_step.dependOn(&run_exe_unit_tests.step); } diff --git a/src/Entities.zig b/src/Entities.zig index 05d47ca..05654c0 100644 --- a/src/Entities.zig +++ b/src/Entities.zig @@ -2,6 +2,7 @@ //! Fields based on JSON response fields const Alias = @import("Alias.zig").Alias; +const zeit = @import("zeit"); pub const Artist = struct { id: []const u8, @@ -17,6 +18,7 @@ pub const ArtistCredit = struct { name: []const u8, artist: Artist, }; + pub const Recording = struct { id: []const u8, score: u8, @@ -25,7 +27,8 @@ pub const Recording = struct { video: ?bool, @"artist-credit": []ArtistCredit, //artist_credit: []ArtistCredit, - @"first-release-date": ?[]const u8 = null, + //@"first-release-date": ?[]const u8 = null, + @"first-release-date": ?union(enum) { slice: []const u8, dt: zeit.Date } = null, //first_release_date: []const u8, releases: []Release, isrcs: ?[][]const u8 = null, diff --git a/src/QueryResults.zig b/src/QueryResults.zig index b6dc9e4..f38e6e1 100644 --- a/src/QueryResults.zig +++ b/src/QueryResults.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const zeit = @import("zeit"); const Entities = @import("Entities.zig"); const Artist = Entities.Artist; @@ -6,6 +7,7 @@ const Recording = Entities.Recording; pub const Result = struct { created: ?[]const u8 = null, + //created: ?zeit.Instant.Source.iso8601 = null, count: ?u32 = null, offset: ?u32 = null, artists: ?[]Artist = null, @@ -71,4 +73,19 @@ pub const Result = struct { } return null; } + + pub fn getSpecifiedRID(self: *const Result, tn: []const u8, rgn: []const u8, an: []const u8) ?[]const u8 { + _ = tn; + _ = rgn; + _ = an; + if (self.count) |count| { + switch (count) { + 0 => return null, + 1 => return self.recording.?[0].id, + else => { + return null; // Sort by date + }, + } + } + } }; diff --git a/src/root.zig b/src/root.zig index 3e36a9b..59c093f 100644 --- a/src/root.zig +++ b/src/root.zig @@ -112,7 +112,7 @@ test "rgid_via_recording" { test "rgid_via_recording_multiple_artists_2" { const test_alloc = std.testing.allocator; const track: []const u8 = "Hesitating%20Beauty"; - const album: []const u8 = "Mermaid%Avenue"; + const album: []const u8 = "Mermaid%20Avenue"; const artist: []const u8 = "Wilco"; const wilco_id: []const u8 = "9e53f84d-ef44-4c16-9677-5fd4d78cbd7d"; @@ -130,4 +130,29 @@ test "rgid_via_recording_multiple_artists_2" { try testing.expect(std.mem.eql(u8, result.getSpecifiedARID("Wilco", "Hesitating Beauty").?, wilco_id)); } + + //try testing.expect(false); } + +//test "rid" { +// const test_alloc = std.testing.allocator; +// const track: []const u8 = "Battery"; +// const album: []const u8 = "Master%20of%20Puppets"; +// const artist: []const u8 = "Metallica"; +// +// const battery_id: []const u8 = "3bfda26a-49fa-4bc4-a4d6-8bbfa0767ab7"; +// +// var mb_result = std.ArrayList(u8).init(test_alloc); +// defer mb_result.deinit(); +// +// const search_result = try mbSearch(test_alloc, &mb_result, track, album, artist); +// +// if (search_result) |sr| { +// const json = try std.json.parseFromSlice(QR.Result, test_alloc, sr, .{ .ignore_unknown_fields = true }); +// defer json.deinit(); +// +// const result: QR.Result = json.value; +// +// try testing.expect(std.mem.eql(u8, result.getSpecifiedARID("Wilco", "Hesitating Beauty").?, battery_id)); +// } +//}