Clean
This commit is contained in:
parent
0631ded115
commit
be8c1191b0
2 changed files with 10 additions and 28 deletions
|
|
@ -18,41 +18,30 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
|
||||||
//_ = env;
|
//_ = env;
|
||||||
if (params.getT(.array, "scrobbles")) |scrobbles| {
|
if (params.getT(.array, "scrobbles")) |scrobbles| {
|
||||||
for (scrobbles.items()) |item| {
|
for (scrobbles.items()) |item| {
|
||||||
//var buffer: [256**4]u8 = undefined;
|
var track_artists_al = std.ArrayList([]const u8).init(allocator);
|
||||||
//var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
var album_artists_al = std.ArrayList([]const u8).init(allocator);
|
||||||
//const alloc = fba.allocator();
|
|
||||||
|
|
||||||
var alssu8 = std.ArrayList([]const u8).init(allocator);
|
|
||||||
defer alssu8.deinit();
|
|
||||||
|
|
||||||
for (item.getT(.array, "artists_track").?.items()) |artist| {
|
for (item.getT(.array, "artists_track").?.items()) |artist| {
|
||||||
try alssu8.append(try artist.coerce([]const u8));
|
try track_artists_al.append(try artist.coerce([]const u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
const track_artists = try alssu8.toOwnedSlice();
|
|
||||||
|
|
||||||
for (item.getT(.array, "artists_album").?.items()) |artist| {
|
for (item.getT(.array, "artists_album").?.items()) |artist| {
|
||||||
try alssu8.append(try artist.coerce([]const u8));
|
try album_artists_al.append(try artist.coerce([]const u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
const album_artists = try alssu8.toOwnedSlice();
|
|
||||||
|
|
||||||
const scrobble: Data.Scrobble = .{
|
const scrobble: Data.Scrobble = .{
|
||||||
.track = item.getT(.string, "track").?,
|
.track = item.getT(.string, "track").?,
|
||||||
.artists_track = track_artists,
|
.artists_track = track_artists_al.items,
|
||||||
.album = item.getT(.string, "album") orelse "",
|
.album = item.getT(.string, "album") orelse "",
|
||||||
.artists_album = album_artists,
|
.artists_album = album_artists_al.items,
|
||||||
.date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))),
|
.date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))),
|
||||||
};
|
};
|
||||||
|
|
||||||
var id_prehash = std.ArrayList(u8).init(allocator);
|
var id_prehash = std.ArrayList(u8).init(allocator);
|
||||||
defer id_prehash.deinit();
|
|
||||||
|
|
||||||
var alartist = std.ArrayList(struct { name: []const u8, id: i32 }).init(allocator);
|
var alartist = std.ArrayList(struct { name: []const u8, id: i32 }).init(allocator);
|
||||||
defer alartist.deinit();
|
|
||||||
|
|
||||||
for (scrobble.artists_track) |artist| {
|
for (scrobble.artists_track) |artist| {
|
||||||
//try id_prehash.appendSlice(artist);
|
|
||||||
try alartist.append(.{ .name = artist, .id = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(artist))) });
|
try alartist.append(.{ .name = artist, .id = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(artist))) });
|
||||||
}
|
}
|
||||||
//const artist_id = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(id_prehash.items)));
|
//const artist_id = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(id_prehash.items)));
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,6 @@ pub fn applyScrobbleRule(allocator: std.mem.Allocator, scrobble: Data.ImportedSc
|
||||||
.date = scrobble.date,
|
.date = scrobble.date,
|
||||||
};
|
};
|
||||||
|
|
||||||
//var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
||||||
//const gpalloc = gpa.allocator();
|
|
||||||
|
|
||||||
//var arena = std.heap.ArenaAllocator.init(gpalloc);
|
|
||||||
//defer arena.deinit();
|
|
||||||
//const allocator = arena.allocator();
|
|
||||||
|
|
||||||
for (rules.rules) |rule| {
|
for (rules.rules) |rule| {
|
||||||
var match_found: bool = switch (rule.cond_req) {
|
var match_found: bool = switch (rule.cond_req) {
|
||||||
.any => false,
|
.any => false,
|
||||||
|
|
@ -57,9 +50,11 @@ pub fn applyScrobbleRule(allocator: std.mem.Allocator, scrobble: Data.ImportedSc
|
||||||
// I have decided an error won't happen :)
|
// I have decided an error won't happen :)
|
||||||
al.appendSlice(@field(output_scrobble, @tagName(on))) catch unreachable;
|
al.appendSlice(@field(output_scrobble, @tagName(on))) catch unreachable;
|
||||||
al.append(act.action_txt) catch unreachable;
|
al.append(act.action_txt) catch unreachable;
|
||||||
const artists = al.toOwnedSlice() catch unreachable;
|
@field(output_scrobble, @tagName(on)) = al.items;
|
||||||
@field(output_scrobble, @tagName(on)) = artists;
|
|
||||||
},
|
},
|
||||||
|
//else => {
|
||||||
|
// std.log.debug("Adding artists doesn't work yet", .{});
|
||||||
|
//},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.replace => switch (act.action_on) {
|
.replace => switch (act.action_on) {
|
||||||
|
|
@ -73,5 +68,3 @@ pub fn applyScrobbleRule(allocator: std.mem.Allocator, scrobble: Data.ImportedSc
|
||||||
|
|
||||||
return output_scrobble;
|
return output_scrobble;
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn applyAlbumRule() !Album {}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue