Combine Alias.zig with Entities.zig
This commit is contained in:
parent
8028e5e42b
commit
c13c2b2817
4 changed files with 96 additions and 110 deletions
|
|
@ -1,14 +0,0 @@
|
|||
pub const Alias = struct {
|
||||
@"sort-name": []const u8,
|
||||
//sort_name: []const u8,
|
||||
@"type-id": ?[]const u8 = null,
|
||||
//type_id: []const u8,
|
||||
name: []const u8,
|
||||
locale: ?[]const u8 = null,
|
||||
type: ?[]const u8 = null,
|
||||
primary: ?bool = null,
|
||||
@"begin-date": ?[]const u8 = null,
|
||||
//begin_date: []const u8,
|
||||
@"end-date": ?[]const u8 = null,
|
||||
//end_date: []const u8,
|
||||
};
|
||||
|
|
@ -1,10 +1,20 @@
|
|||
//! Types of MusicBrainz Entities described here: https://musicbrainz.org/doc/MusicBrainz_Entity
|
||||
//! Fields based on JSON response fields
|
||||
|
||||
const Alias = @import("Alias.zig").Alias;
|
||||
//const zeit = @import("zeit");
|
||||
const std = @import("std");
|
||||
|
||||
pub const Alias = struct {
|
||||
@"sort-name": []const u8,
|
||||
@"type-id": ?[]const u8 = null,
|
||||
name: []const u8,
|
||||
locale: ?[]const u8 = null,
|
||||
type: ?[]const u8 = null,
|
||||
primary: ?bool = null,
|
||||
@"begin-date": ?[]const u8 = null,
|
||||
@"end-date": ?[]const u8 = null,
|
||||
};
|
||||
|
||||
pub const Artist = struct {
|
||||
id: []const u8,
|
||||
name: []const u8,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
//! Types of MusicBrainz Entities described here: https://musicbrainz.org/doc/MusicBrainz_Entity
|
||||
//! Fields based on JSON response fields
|
||||
|
||||
const Alias = @import("Alias.zig").Alias;
|
||||
const std = @import("std");
|
||||
|
||||
pub const Artist = struct {
|
||||
|
|
@ -46,6 +44,7 @@ pub const Recording = struct {
|
|||
} else return false; // a provides no information
|
||||
}
|
||||
};
|
||||
|
||||
pub const Release = struct {
|
||||
id: []const u8,
|
||||
title: []const u8,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub const Result = struct {
|
|||
// album "1"), it will instead give you the information from the album the song originally appeared on
|
||||
// (in this case, the album "Help!").
|
||||
|
||||
pub fn getOriginalIDs(self: *const Result, smd: searchMetadata, pbo: parseOption) ?[]const u8 {
|
||||
pub fn getID(self: *const Result, smd: searchMetadata, pbo: parseOption) ?[]const u8 {
|
||||
if (self.count == 0) return null;
|
||||
switch (pbo) {
|
||||
.song => |method| {
|
||||
|
|
@ -86,107 +86,98 @@ pub const Result = struct {
|
|||
}
|
||||
return self.recordings[0].@"artist-credit"[0].artist.id;
|
||||
},
|
||||
.all => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getIDs(self: *const Result, smd: searchMetadata, pbo: parseByOptions) ?searchIDs {
|
||||
if (self.count == 0) return null;
|
||||
const sorted_recordings = self.recordings;
|
||||
std.mem.sort(Recording, sorted_recordings, {}, Recording.lessThan);
|
||||
for (sorted_recordings) |rc| {
|
||||
switch (pbo.parse) {
|
||||
.song => {
|
||||
const output = searchIDs{
|
||||
.id = switch (pbo.specifyBy) {
|
||||
.song => song_song: {
|
||||
if (std.mem.eql(u8, rc.title, smd.tn)) {
|
||||
break :song_song rc.id;
|
||||
//break :rc_loop;
|
||||
} else break :song_song "";
|
||||
},
|
||||
.album => song_album: {
|
||||
for (rc.releases) |rl| {
|
||||
if (std.mem.eql(u8, rl.title, smd.rn)) {
|
||||
break :song_album rc.id;
|
||||
//break :rc_loop;
|
||||
}
|
||||
}
|
||||
break :song_album "";
|
||||
},
|
||||
.artist => song_artist: {
|
||||
for (rc.@"artist-credit") |ac| {
|
||||
if (std.mem.eql(u8, ac.name, smd.an)) {
|
||||
break :song_artist rc.id;
|
||||
//break :rc_loop;
|
||||
}
|
||||
}
|
||||
break :song_artist "";
|
||||
},
|
||||
.all => unreachable, // I'll do this later
|
||||
},
|
||||
};
|
||||
return output;
|
||||
},
|
||||
.album => {
|
||||
const output = searchIDs{ .id = blk: {
|
||||
const sorted_releases = rc.releases;
|
||||
std.mem.sort(Release, sorted_releases, {}, Release.lessThan);
|
||||
for (sorted_releases) |rl| {
|
||||
switch (pbo.specifyBy) {
|
||||
.song, .album => {
|
||||
if (std.mem.eql(u8, rl.title, smd.rn)) break :blk rl.id;
|
||||
},
|
||||
.artist => {
|
||||
for (rl.@"artist-credit") |ac| {
|
||||
if (std.mem.eql(u8, ac.name, smd.an)) break :blk rl.id;
|
||||
}
|
||||
},
|
||||
.all => unreachable,
|
||||
}
|
||||
}
|
||||
break :blk "";
|
||||
} };
|
||||
return output;
|
||||
},
|
||||
.artist => {
|
||||
const output = searchIDs{ .id = switch (pbo.specifyBy) {
|
||||
.song, .artist => blk: {
|
||||
for (rc.@"artist-credit") |ac| {
|
||||
if (std.mem.eql(u8, ac.name, smd.an)) break :blk ac.artist.id;
|
||||
}
|
||||
break :blk "";
|
||||
},
|
||||
.album => blk: {
|
||||
for (rc.releases) |rl| {
|
||||
for (rl.@"artist-credit") |ac| {
|
||||
if (std.mem.eql(u8, ac.name, smd.an)) break :blk ac.artist.id;
|
||||
}
|
||||
}
|
||||
break :blk "";
|
||||
},
|
||||
.all => unreachable,
|
||||
} };
|
||||
return output;
|
||||
},
|
||||
.all => {
|
||||
var output = searchIDs{ .ids = undefined };
|
||||
if (self.getIDs(smd, .{ .parse = .song })) |ids| output.ids.song_id = ids.id;
|
||||
if (self.getIDs(smd, .{ .parse = .album })) |ids| output.ids.album_id = ids.id;
|
||||
if (self.getIDs(smd, .{ .parse = .artist })) |ids| output.ids.artist_id = ids.id;
|
||||
return output;
|
||||
},
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//pub fn getIDs(self: *const Result, smd: searchMetadata, pbo: parseByOptions) ?searchIDs {
|
||||
// if (self.count == 0) return null;
|
||||
// const sorted_recordings = self.recordings;
|
||||
// std.mem.sort(Recording, sorted_recordings, {}, Recording.lessThan);
|
||||
// for (sorted_recordings) |rc| {
|
||||
// switch (pbo.parse) {
|
||||
// .song => {
|
||||
// const output = searchIDs{
|
||||
// .id = switch (pbo.specifyBy) {
|
||||
// .song => song_song: {
|
||||
// if (std.mem.eql(u8, rc.title, smd.tn)) {
|
||||
// break :song_song rc.id;
|
||||
// //break :rc_loop;
|
||||
// } else break :song_song "";
|
||||
// },
|
||||
// .album => song_album: {
|
||||
// for (rc.releases) |rl| {
|
||||
// if (std.mem.eql(u8, rl.title, smd.rn)) {
|
||||
// break :song_album rc.id;
|
||||
// //break :rc_loop;
|
||||
// }
|
||||
// }
|
||||
// break :song_album "";
|
||||
// },
|
||||
// .artist => song_artist: {
|
||||
// for (rc.@"artist-credit") |ac| {
|
||||
// if (std.mem.eql(u8, ac.name, smd.an)) {
|
||||
// break :song_artist rc.id;
|
||||
// //break :rc_loop;
|
||||
// }
|
||||
// }
|
||||
// break :song_artist "";
|
||||
// },
|
||||
// .all => unreachable, // I'll do this later
|
||||
// },
|
||||
// };
|
||||
// return output;
|
||||
// },
|
||||
// .album => {
|
||||
// const output = searchIDs{ .id = blk: {
|
||||
// const sorted_releases = rc.releases;
|
||||
// std.mem.sort(Release, sorted_releases, {}, Release.lessThan);
|
||||
// for (sorted_releases) |rl| {
|
||||
// switch (pbo.specifyBy) {
|
||||
// .song, .album => {
|
||||
// if (std.mem.eql(u8, rl.title, smd.rn)) break :blk rl.id;
|
||||
// },
|
||||
// .artist => {
|
||||
// for (rl.@"artist-credit") |ac| {
|
||||
// if (std.mem.eql(u8, ac.name, smd.an)) break :blk rl.id;
|
||||
// }
|
||||
// },
|
||||
// .all => unreachable,
|
||||
// }
|
||||
// }
|
||||
// break :blk "";
|
||||
// } };
|
||||
// return output;
|
||||
// },
|
||||
// .artist => {
|
||||
// const output = searchIDs{ .id = switch (pbo.specifyBy) {
|
||||
// .song, .artist => blk: {
|
||||
// for (rc.@"artist-credit") |ac| {
|
||||
// if (std.mem.eql(u8, ac.name, smd.an)) break :blk ac.artist.id;
|
||||
// }
|
||||
// break :blk "";
|
||||
// },
|
||||
// .album => blk: {
|
||||
// for (rc.releases) |rl| {
|
||||
// for (rl.@"artist-credit") |ac| {
|
||||
// if (std.mem.eql(u8, ac.name, smd.an)) break :blk ac.artist.id;
|
||||
// }
|
||||
// }
|
||||
// break :blk "";
|
||||
// },
|
||||
// .all => unreachable,
|
||||
// } };
|
||||
// return output;
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
};
|
||||
|
||||
pub const parseOption = union(enum) {
|
||||
song: enum { canon, orig },
|
||||
album: enum { canon, orig },
|
||||
artist,
|
||||
all,
|
||||
};
|
||||
|
||||
pub const parseByOptions = struct { parse: parseOption = .song, specifyBy: parseOption = .song };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue