From 87a2fe2d3479ace74d3d11439bd6ad5e9f184e80 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Mon, 21 Apr 2025 12:23:20 -0400 Subject: [PATCH] Complete preliminary find and replace rules Tested by replacing AJR with John Van Derwood. Need to test on albums and artists, as well as matching on one piece of metadata, and replacing another --- src/app/jobs/process_scrobbles.zig | 9 +++++--- src/app/views/rules/index.zmpl | 2 +- src/apply_rule.zig | 33 +++++++++++++++++++++++++----- src/types.zig | 12 +++++------ 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/app/jobs/process_scrobbles.zig b/src/app/jobs/process_scrobbles.zig index bbfc9d4..06d7365 100644 --- a/src/app/jobs/process_scrobbles.zig +++ b/src/app/jobs/process_scrobbles.zig @@ -3,6 +3,9 @@ const jetzig = @import("jetzig"); const jetquery = @import("jetzig").jetquery; const Scrobble = @import("../../types.zig").LastFMScrobble; const lastfm = @import("../../types.zig").LastFM; +//const Rules = @import("../../types.zig").Rules; +const Data = @import("../../types.zig"); +const rules = @import("../../apply_rule.zig"); // The `run` function for a job is invoked every time the job is processed by a queue worker // (or by the Jetzig server if the job is processed in-line). @@ -18,14 +21,14 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig const file = try std.fs.cwd().openFile("rules.json", .{ .mode = .read_only }); const file_content = try file.readToEndAlloc(allocator, 16_000_000); - const rules = try std.json.parseFromSliceLeaky(Rules, allocator, file_content, .{}); + const rule_list = try std.json.parseFromSliceLeaky(Data.Rules, allocator, file_content, .{}); if (params.getT(.array, "scrobbles")) |scrobbles| { for (scrobbles.items()) |item| { //const fixed_date: u32 = @as(u32, item.getT(.integer, "date").?); - const scrobble: Scrobble = .{ .track = item.getT(.string, "track").?, .artist = item.getT(.string, "artist").?, .album = item.getT(.string, "album") orelse "", .date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))) }; + const pre_scrobble: Scrobble = .{ .track = item.getT(.string, "track").?, .artist = item.getT(.string, "artist").?, .album = item.getT(.string, "album") orelse "", .date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))) }; - for (rules) |rule| {} + const scrobble = rules.applyScrobbleRule(pre_scrobble, rule_list); // Make hashes //const album_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.album))); diff --git a/src/app/views/rules/index.zmpl b/src/app/views/rules/index.zmpl index 4d15188..b9a1b17 100644 --- a/src/app/views/rules/index.zmpl +++ b/src/app/views/rules/index.zmpl @@ -21,7 +21,7 @@ If