diff --git a/src/app/jobs/process_scrobbles.zig b/src/app/jobs/process_scrobbles.zig index 70c2976..bbfc9d4 100644 --- a/src/app/jobs/process_scrobbles.zig +++ b/src/app/jobs/process_scrobbles.zig @@ -14,14 +14,19 @@ const lastfm = @import("../../types.zig").LastFM; // - logger: Logger attached to the same stream as the Jetzig server. // - environment: Enum of `{ production, development }`. pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig.jobs.JobEnv) !void { - _ = allocator; //_ = env; + 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, .{}); 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)))) }; + for (rules) |rule| {} + // Make hashes //const album_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.album))); //const artist_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.artist))); diff --git a/src/apply_rule.zig b/src/apply_rule.zig new file mode 100644 index 0000000..871c996 --- /dev/null +++ b/src/apply_rule.zig @@ -0,0 +1,11 @@ +const Scrobble = @import("types").LastFMScrobble; +const Rules = @import("types").Rules; + +pub fn applyRule(scrobble: Scrobble, rules: Rules) !Scrobble { + var output_scrobble: Scrobble = scrobble; + for (rules) |rule| { + for (rule.conditionals) |cond| { + switch (cond.match_cond) {} + } + } +} diff --git a/src/types.zig b/src/types.zig index 55bca1c..00e063c 100644 --- a/src/types.zig +++ b/src/types.zig @@ -1,5 +1,3 @@ -const zeit = @import("zeit"); - pub const LastFMScrobble = struct { track: []const u8, artist: []const u8, @@ -36,3 +34,27 @@ pub const SpotifyScrobble = struct { offline_timestamp: u64, incognito_mode: ?bool, }; + +const Rule = struct { + name: []const u8, + conditionals: []struct { + match_on: MatchOn, + match_cond: enum { is, contains }, + match_txt: []const u8, + }, + actions: []struct { + action: []const u8, + action_on: enum { is, contains }, + action_txt: []const u8, + }, +}; + +const Rules = struct { + rules: []const Rule, +}; + +const MatchOn = enum { + artist, + album, + song, +};