Fix null albums
We're so back
This commit is contained in:
parent
4f051170e5
commit
a2aa946b3b
3 changed files with 9 additions and 10 deletions
|
|
@ -25,9 +25,9 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
|
|||
//std.log.debug("{s}", .{scrobble.track});
|
||||
|
||||
// Make hashes
|
||||
const album_hash = std.hash.Fnv1a_64.hash(scrobble.album);
|
||||
const artist_hash = std.hash.Fnv1a_64.hash(scrobble.artist);
|
||||
const song_hash = std.hash.Fnv1a_64.hash(scrobble.track);
|
||||
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)));
|
||||
const song_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.track)));
|
||||
|
||||
// Make IDs
|
||||
// Song: Song hash XOR artist hash XOR album hash
|
||||
|
|
@ -48,7 +48,7 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
|
|||
// then a descriptive string can be provided to
|
||||
// differentiate after the fact, or in a rule.
|
||||
|
||||
var album_id: u64 = 0;
|
||||
var album_id: i32 = 0;
|
||||
const song_id = (song_hash ^ artist_hash ^ album_hash);
|
||||
if (artist_hash == album_hash) {
|
||||
album_id = album_hash;
|
||||
|
|
|
|||
|
|
@ -19,16 +19,15 @@ pub fn post(request: *jetzig.Request) !jetzig.View {
|
|||
var root = try request.data(.object);
|
||||
|
||||
if (try request.file("upload")) |file| {
|
||||
const content = try std.json.parseFromSlice(lastfm, request.allocator, file.content, .{});
|
||||
defer content.deinit();
|
||||
const history = content.value;
|
||||
//std.debug.print("{s}", .{file.content});
|
||||
const content = try std.json.parseFromSliceLeaky(lastfm, request.allocator, file.content, .{ .ignore_unknown_fields = true });
|
||||
|
||||
var scrobbles_view = try root.put("scrobbles", .array);
|
||||
|
||||
var job = try request.job("process_scrobbles");
|
||||
var scrobbles_data = try job.params.put("scrobbles", .array);
|
||||
|
||||
for (history.scrobbles) |scrobble| {
|
||||
for (content.scrobbles) |scrobble| {
|
||||
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| {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub const LastFMScrobble = struct {
|
||||
track: []const u8,
|
||||
artist: []const u8,
|
||||
album: ?[]const u8,
|
||||
album: ?[]const u8 = "",
|
||||
date: i128,
|
||||
};
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ pub const SafeLastFMScrobble = struct {
|
|||
};
|
||||
|
||||
// From lastfmstats.com
|
||||
pub const LastFM = struct { username: []u8, scrobbles: []LastFMScrobble };
|
||||
pub const LastFM = struct { username: []const u8, scrobbles: []LastFMScrobble };
|
||||
|
||||
pub const SpotifyScrobble = struct {
|
||||
ts: []u8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue