From 4991bac9a452a6f07cefbc844d1bc070adf54800 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Thu, 15 May 2025 15:39:21 -0400 Subject: [PATCH] Add LastFM scrobble type In preparation for importing via LastFM api --- src/app/views/upload.zig | 2 +- src/types.zig | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/app/views/upload.zig b/src/app/views/upload.zig index 5f47cc4..25a9128 100644 --- a/src/app/views/upload.zig +++ b/src/app/views/upload.zig @@ -37,7 +37,7 @@ pub fn post(request: *jetzig.Request) !jetzig.View { switch (source) { 0 => { - const content: Data.LastFM = try std.json.parseFromSliceLeaky(Data.LastFM, request.allocator, file.content, .{}); + const content: Data.LastFMStats = try std.json.parseFromSliceLeaky(Data.LastFMStats, request.allocator, file.content, .{}); const before_limiting_date = if (before_limiter and params.get("b") != null) (try zeit.instant(.{ .source = .{ .iso8601 = params.get("b").?.string.value } })).unixTimestamp() * 1000 else 0; const after_limiting_date = if (after_limiter and params.get("a") != null) (try zeit.instant(.{ .source = .{ .iso8601 = params.get("a").?.string.value } })).unixTimestamp() * 1000 else 9_223_372_036_854_775_807; appends: for (content.scrobbles) |scrobble| { diff --git a/src/types.zig b/src/types.zig index e71018c..e8ac141 100644 --- a/src/types.zig +++ b/src/types.zig @@ -14,7 +14,7 @@ pub const Scrobble = struct { }; // From lastfmstats.com -pub const LastFM = struct { username: []const u8, scrobbles: []ImportedScrobble }; +pub const LastFMStats = struct { username: []const u8, scrobbles: []ImportedScrobble }; // I derived whether or not these values were optional from searching // the respective fields for null in Vim, so there may be some fields @@ -43,6 +43,37 @@ pub const SpotifyScrobble = struct { //incognito_mode: ?bool, }; +pub const LastFMWeb = struct { + track: []struct { + artist: LastFMWebHyperlinkData, + album: LastFMWebHyperlinkData, + name: []const u8, + mbid: []const u8, + image: struct { + size: []const u8, + @"#text": []const u8, + }, + date: struct { + uts: []const u8, + @"#text": []const u8, + }, + }, + @"@attr": LastFMWebAttr, +}; + +pub const LastFMWebAttr = struct { + perPage: u32, + totalPages: u32, + page: u32, + user: []const u8, + total: u32, +}; + +pub const LastFMWebHyperlinkData = struct { + mbid: []const u8, + @"#text": []const u8, +}; + pub const Rule = struct { name: []const u8, cond_req: enum { any, all },