Allow filtering scrobble uploads by date

Necessary to avoid double scrobbling if uploading from two sources (i.e. my Spotify data [2016-2023] and my last.fm data [2019-present])
This commit is contained in:
mitteneer 2025-02-21 11:54:02 -05:00
parent ab01f2e213
commit 7957345057
6 changed files with 90 additions and 26 deletions

View file

@ -3,6 +3,7 @@ const jetzig = @import("jetzig");
const jetquery = @import("jetzig").jetquery;
const Scrobble = @import("../../types.zig").LastFMScrobble;
const lastfm = @import("../../types.zig").LastFM;
const zeit = @import("zeit");
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
_ = data;
@ -27,7 +28,15 @@ pub fn post(request: *jetzig.Request) !jetzig.View {
var job = try request.job("process_scrobbles");
var scrobbles_data = try job.params.put("scrobbles", .array);
for (content.scrobbles) |scrobble| {
const params = try request.params();
const limiting_date_string: ?[]const u8 = if (params.get("l")) |param| param.string.value else null;
const limiting_date_instant: ?zeit.Instant = if (limiting_date_string) |str| try zeit.instant(.{ .source = .{ .iso8601 = str } }) else null;
// This is seconds from Unix epoch
const limiting_date_epoch = if (limiting_date_instant) |time| time.unixTimestamp() else 9_223_372_036_854_775_807;
appends: for (content.scrobbles) |scrobble| {
// Scrobble.date is in milliseconds from Unix epoch
if (scrobble.date < limiting_date_epoch * 1000) continue :appends;
var value = try scrobbles_data.append(.object);
// This is so unnecessary, probably useful once I start doing Spotify integration though
inline for (std.meta.fields(Scrobble)) |f| {