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
This commit is contained in:
mitteneer 2025-04-21 12:23:20 -04:00
parent 445ca45fa9
commit 87a2fe2d34
4 changed files with 41 additions and 15 deletions

View file

@ -1,11 +1,34 @@
const Scrobble = @import("types").LastFMScrobble;
const Rules = @import("types").Rules;
const std = @import("std");
const Scrobble = @import("./types.zig").LastFMScrobble;
const Rules = @import("./types.zig").Rules;
pub fn applyRule(scrobble: Scrobble, rules: Rules) !Scrobble {
pub fn applyScrobbleRule(scrobble: Scrobble, rules: Rules) Scrobble {
var match_found: bool = true;
var output_scrobble: Scrobble = scrobble;
for (rules) |rule| {
for (rules.rules) |rule| {
for (rule.conditionals) |cond| {
switch (cond.match_cond) {}
switch (cond.match_cond) {
.is => switch (cond.match_on) {
inline else => |on| match_found = match_found and std.mem.eql(u8, @field(scrobble, @tagName(on)), cond.match_txt),
},
.contains => switch (cond.match_on) {
inline else => |on| match_found = match_found and (std.mem.count(u8, @field(scrobble, @tagName(on)), cond.match_txt) > 0),
},
}
}
if (match_found) {
for (rule.actions) |act| {
switch (act.action) {
.add => {},
.replace => switch (act.action_on) {
inline else => |on| @field(output_scrobble, @tagName(on)) = act.action_txt,
},
}
}
}
}
return output_scrobble;
}
//pub fn applyAlbumRule() !Album {}