Skip to content

Commit

Permalink
Switch to new kitsu.app url for kitsu
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Aug 14, 2024
1 parent aa2cf89 commit fd079a8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/Database.zig
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ test "binary version should be updated" {
\\ "https://anidb.net/anime/8069",
\\ "https://anilist.co/anime/9756",
\\ "https://anisearch.com/anime/6601",
\\ "https://kitsu.io/anime/5853",
\\ "https://kitsu.app/anime/5853",
\\ "https://livechart.me/anime/3246",
\\ "https://myanimelist.net/anime/9756"
\\ ],
Expand Down Expand Up @@ -736,14 +736,14 @@ test "binary version should be updated" {
\\ "https://anisearch.com/anime/13854",
\\ "https://anisearch.com/anime/6993",
\\ "https://anisearch.com/anime/7409",
\\ "https://kitsu.io/anime/11573",
\\ "https://kitsu.io/anime/13871",
\\ "https://kitsu.io/anime/42016",
\\ "https://kitsu.io/anime/48919",
\\ "https://kitsu.io/anime/6218",
\\ "https://kitsu.io/anime/6636",
\\ "https://kitsu.io/anime/6637",
\\ "https://kitsu.io/anime/6638",
\\ "https://kitsu.app/anime/11573",
\\ "https://kitsu.app/anime/13871",
\\ "https://kitsu.app/anime/42016",
\\ "https://kitsu.app/anime/48919",
\\ "https://kitsu.app/anime/6218",
\\ "https://kitsu.app/anime/6636",
\\ "https://kitsu.app/anime/6637",
\\ "https://kitsu.app/anime/6638",
\\ "https://livechart.me/anime/10663",
\\ "https://livechart.me/anime/1947",
\\ "https://livechart.me/anime/3495",
Expand Down
40 changes: 30 additions & 10 deletions src/database/Id.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ id: u32,

pub fn fromUrl(url: []const u8) !Id {
for (std.meta.tags(Site)) |site| {
const site_url = site.url();
if (std.mem.startsWith(u8, url, site_url)) {
const id = try std.fmt.parseUnsigned(u32, url[site_url.len..], 10);
return Id{ .site = site, .id = id };
for (site.urls()) |site_url| {
if (std.mem.startsWith(u8, url, site_url)) {
const id = try std.fmt.parseUnsigned(u32, url[site_url.len..], 10);
return Id{ .site = site, .id = id };
}
}
}

Expand Down Expand Up @@ -35,13 +36,32 @@ pub const Site = enum(u8) {
pub const all = std.meta.tags(Site);

pub fn url(site: Site) []const u8 {
return site.urls()[0];
}

/// The first url in the slice returned is the current url for that site. Anything after are
/// old or alternative urls for the site.
pub fn urls(site: Site) []const []const u8 {
return switch (site) {
.anidb => "https://anidb.net/anime/",
.anilist => "https://anilist.co/anime/",
.anisearch => "https://anisearch.com/anime/",
.kitsu => "https://kitsu.io/anime/",
.livechart => "https://livechart.me/anime/",
.myanimelist => "https://myanimelist.net/anime/",
.anidb => &.{
"https://anidb.net/anime/",
},
.anilist => &.{
"https://anilist.co/anime/",
},
.anisearch => &.{
"https://anisearch.com/anime/",
},
.kitsu => &.{
"https://kitsu.app/anime/",
"https://kitsu.io/anime/",
},
.livechart => &.{
"https://livechart.me/anime/",
},
.myanimelist => &.{
"https://myanimelist.net/anime/",
},
};
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/database/Image.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Image urls in the anime-offline-database all follow a similar pattern. They all start with a base url and then
//! have a path that is unique to the image. To save on memory, we only store the path of the image url and then an
//! enum that represents the base url.
//! Image urls in the anime-offline-database all follow a similar pattern. They all start with a
//! base url and then have a path that is unique to the image. To save on memory, we only store
//! the path of the image url and then an enum that represents the base url.

base: Base,
path: []const u8,
Expand Down Expand Up @@ -38,6 +38,7 @@ pub const Base = enum(u8) {
myanimelist2,
notifymoe1,
notifymoe2,
kitsu3,

pub fn fromUrl(str: []const u8) !Image.Base {
for (std.meta.tags(Image.Base)) |base| {
Expand Down Expand Up @@ -67,6 +68,7 @@ pub const Base = enum(u8) {
.animeplanet1 => "https://cdn.anime-planet.com/images/anime/default/",
.animeplanet2 => "https://cdn.anime-planet.com/anime/primary/",
.anidb => "https://cdn.anidb.net/images/main/",
.kitsu3 => "https://media.kitsu.app/anime/",
};
}
};
Expand Down

0 comments on commit fd079a8

Please sign in to comment.