Git Product home page Git Product logo

jikan.net's Introduction

Discord Server build status build status License: MIT GitHub issues open

jikan.net

Jikan.net is a .NET wrapper for Jikan RESTful API for parsing data from MyAnimeList. Main objective of the wrapper is to simplify utilization of Jikan API, as strongly typed languages are not-so-easy to use with elastic json (sure we can go use dynamics in .NET, but let's think about performance).

Main attributes

  • Written in to work with .Net Standard 2.0, compatible with .Net Framework (4.6.1 or newer), .Net Core (2.0 or newer) and .net (6.0 or newer).
  • Fully asynchromous request fetching (can be forced to synchromous if needed).
  • Light on dependencies
    • No dependencies if you are using .Net Core 3.x or net 6.0+
    • Single dependancy for .Net Framework and .Net Core 2.x (System.Text.Json).
  • Usable with Dependency Injection.

List of features

  • Anime
    • Basic information
    • Characters
    • Staff
    • Episode
    • News
    • Videos/PV/Episodes
    • Pictures
    • Statistics
    • Forum Topics
    • More Info
    • Reviews
    • Recommendations
    • User Updates
    • Related entries
    • Themes
    • External links
    • Full information
  • Manga
    • Basic information
    • Characters
    • News
    • Pictures
    • Stats
    • Forum Topics
    • More Info
    • Reviews
    • Recommendations
    • User Updates
    • Related entries
    • External links
    • Full information
  • People
    • Basic information
    • Related anime
    • Related manga
    • Voice acting roles
    • Pictures
    • Full information
  • Characters
    • Basic information
    • Related anime
    • Related manga
    • Voice actors
    • Pictures
    • Full information
  • Search
    • Anime
    • Manga
    • People
    • Characters
    • Users
    • Clubs
  • Seasonal Anime
    • Current
    • Upcoming
    • Archival
  • Anime Scheduling (for current season)
  • Top
    • Anime
    • Manga
    • People
    • Characters
    • Reviews
  • Genre
    • Anime genres
    • Manga genres
  • Producer
    • Basic information
    • External links
    • Full data
  • Magazine
  • User
    • Profile
    • Friends
    • History
    • Statistics
    • Favorites
    • About
    • Reviews
    • Recommendations
    • Clubs
    • Anime list (will become obsolete soon)
    • Manga list (will become obsolete soon)
    • Full data
  • Clubs
    • Profile
    • Member list
    • Staff
    • Relations

Installation

Package manager

PM> Install-Package JikanDotNet

.NET CLI

>dotnet add package JikanDotNet

Then restore dependencies:

>dotnet restore

Changelog

17.11.2023 - Version 2.7.0

  • Add support for .net 8

Read More

Documentation & Usage example

See project wiki.

jikan.net's People

Contributors

aetherstrata avatar chofito avatar dady8889 avatar ensignpayton avatar ervie avatar majora2007 avatar moiph avatar n0d4n avatar thomasaunvik avatar vynxc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jikan.net's Issues

Error Handling for Get Methods

Is there any possible error handling for things like GetAnime? for example the id 500 does not exist on MAL and I use Jikan.net for a discord bot I am currently coding but am having trouble trying to do some error handling when something, like I mentioned above, happens. This could be very niche but would be cool if there's some built-in error handling or if you could give me some tips on how to handle situations like that.

OS

Is this windows 10 package Manager?
Or do i need to install a piece if software first. E.G Node.js?

The server responded with error 400: BadRequest

For the past couple of days, I've been getting this issue where it'll give me an error 400: BadRequest I have not tried the other methods besides GetAnime. I'm not sure if this is just something on my end. or something is up with the API at the moment.

GetScheduleAsync exception

Hi Ervie, I think I found some sort of bug from GetScheduleAsync method, this was what I found.

{System.InvalidOperationException: The JSON property name for 'JikanDotNet.DbPaginatedJikanResponse`1[System.Collections.Generic.ICollection`1[JikanDotNet.Anime]].Pagination' collides with another property.
  at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameConflict (System.Text.Json.JsonClassInfo jsonClassInfo, System.Text.Json.JsonPropertyInfo jsonPropertyInfo) [0x0001b] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.JsonClassInfo..ctor (System.Type type, System.Text.Json.JsonSerializerOptions options) [0x00133] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.JsonSerializerOptions.GetOrAddClass (System.Type classType) [0x00017] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.ReadStackFrame.Initialize (System.Type type, System.Text.Json.JsonSerializerOptions options) [0x00000] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.JsonSerializer.ReadCore (System.Type returnType, System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader) [0x00008] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.JsonSerializer.Deserialize (System.String json, System.Type returnType, System.Text.Json.JsonSerializerOptions options) [0x0009d] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at System.Text.Json.JsonSerializer.Deserialize[TValue] (System.String json, System.Text.Json.JsonSerializerOptions options) [0x00000] in <815ff95f4d6a463fa6a3be490e0514aa>:0 
  at JikanDotNet.Jikan.ExecuteGetRequestAsync[T] (System.Collections.Generic.ICollection`1[T] routeSections) [0x0012a] in <210aaa08ca6e48cc9535ceee605c1cbc>:0 

Review Model not valid (v4)

Looking at https://api.jikan.moe/v4/anime/1/reviews, you can see the json below. However, the model currently has properties that are no longer there, like votes, ReviewScores, and missing important fields like Score and IsSpoiler.

However I noticed multiple tests testing against Votes, despite the payload not having it. Thoughts? I need to be able to get the score of the review, however current version is always having Overall as 0.

Note: I have already coded up the model and can raise a PR if needed.

{
            "mal_id": 7406,
            "url": "https://myanimelist.net/reviews.php?id=7406",
            "type": "anime",
            "reactions": {
                "overall": 2156,
                "nice": 2136,
                "love_it": 9,
                "funny": 1,
                "confusing": 1,
                "informative": 5,
                "well_written": 4,
                "creative": 0
            },
            "date": "2008-08-24T05:46:00+00:00",
            "review": "...",
            "score": 10,
            "tags": [
                "Recommended"
            ],
            "is_spoiler": false,
            "is_preliminary": false,
            "episodes_watched": null,
            "user": {
                "url": "https://myanimelist.net/profile/TheLlama",
                "username": "TheLlama",
                "images": {
                    "jpg": {
                        "image_url": "https://cdn.myanimelist.net/s/common/userimages/35fb5f95-6a86-498b-93a5-fcff7f402bc2_42x62_i?s=31842eb777c5fc3e5a4324250440ae95"
                    },
                    "webp": {
                        "image_url": "https://cdn.myanimelist.net/s/common/userimages/35fb5f95-6a86-498b-93a5-fcff7f402bc2_42x62_i?s=31842eb777c5fc3e5a4324250440ae95"
                    }
                }
            }
        },

[Proposal] Add new constructor to Jikan class

Add new constructor to Jikan class which accepts custom, user-provided HttpClient.

Reasoning

With this feature user will be able to provide custom HttpClient with preconfigured HttpMessageHandler, make HttpClient resilient with Polly for example etc.

Currently it is possible to achieve the same thing via reflection or with implementing IJikan interface and making such constructor, however both ways are looking tricky to me.

Proposed API

/// <summary>
/// Constructor.
/// </summary>
/// <param name="httpClient">Http client to call REST request and receive REST response</param>
/// <param name="suppressException">Should exception be thrown in case of failed request. If true, failed request return null.</param>
public Jikan(HttpClient httpClient, bool suppressException = false)
{
_suppressException = suppressException;
_httpClient = httpClient
}

Optionally check httpClient instance for being null.

I can make a PR for this.

Response deserialization failing silently

The JSON deserializer can silently fail and return a response wih null data because the model fields are not required. This is especially problematic until the mantainers fix jikan-me/jikan-rest#351. Marking them with required is enough to trigger a JsonException according to .NET Docs.

You can try getting data from {endpoint}/anime/2. It will sometimes return the same error message but with a 200 status code

The problem is that this feature is only available on C# 11 / .NET 7 so this project must either drop support for .NET 6 and lower and start targeting .NET 7 or add the feature manually.

I tested PolySharp and it seems to work but if you don´t want to add it as dependency, adding this and this to the project should be fine.

After making Data required:

Serialization failed.
Inner exception message: JSON deserialization for type 'JikanDotNet.BaseJikanResponse`1[JikanDotNet.Anime]' was missing required properties, including the following: data

Jikan API v3.2 Update

Hi, I just released Jikan v3.2. It has some new additions and changes, thought I'd let wrapper devs know directly.

New Features

  • Anime/Manga Reviews, Recommendations, User Updates
  • Club Information, Members
  • Season Later

Specification

Reviews

Anime

GET /v3/anime/{id}/reviews/{page}

Manga

GET /v3/anime/{id}/reviews/{page}

Remarks: Only 20 items are shown per page for reviews

Recommendations

Anime

GET /v3/anime/{id}/recommendations

Manga

GET /v3/anime/{id}/recommendations

User Updates

Anime

GET /v3/anime/{id}/userupdates/{page}

Manga

GET /v3/anime/{id}/userupdates/{page}

Season Later

GET /v3/season/later

Club Information

GET /v3/club/{id}

Club Members

GET /v3/club/{id}/members

Changes

  • All data from user related endpoints /v3/user/* are now cached for 5 minutes only
  • (Anime/Manga) Bug fixed for related property. It's an object but returns an array when it was empty. This is fixed now.
  • Error messages are now different and readable.

Documentation: https://jikan.docs.apiary.io

Chapters in MangaSearchEntry can be null

Sample request: https://api.jikan.moe/v3/search/manga?q=naruto

...
"results":[{"mal_id":95210,"url":"https:\/\/myanimelist.net\/manga\/95210\/Boruto__Naruto_Next_Generations","title":"Boruto: Naruto Next Generations","image_url":"https:\/\/cdn.myanimelist.net\/images\/manga\/3\/181968.jpg","type":"Manga","volumes":null,"chapters":null,"publishing":true,
...
JikanDotNet.Exceptions.JikanRequestException: Serialization failed.
Inner exception message: Error converting value {null} to type 'System.Int32'. Path 'results[0].chapters', line 1, position 404.
 ---> Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.Int32'. Path 'results[0].chapters', line 1, position 404.
 ---> System.InvalidCastException: Null object cannot be converted to a value type.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   --- End of inner exception stack trace ---

Interface for Anime item and Manga item

Is there a way to for you to add an Interface for the Anime item and Manga item so I can treat them as the same item to help with accessing internal propertys.

So instead of doing something like this;
public long ID { get { if (AnimeItem!= null) return AnimeItem.MalId; else return MangaItem.MalId; } }

I can reference the ID though a interface (or a series of interfaces) , like this

public interface MalItemInteracter
    {
        long MalId { get; }
        string Title { get; }
        string Studios { get; }
        string Type { get; }
        string Author { get; }
        string Genres { get; }
        float? Score { get; }
    }

MalItemInteracter MII = (AnimeItem or MangaItem) as MalItemInteracter();
public long ID { get { MalItemInteracter.MalId; } }

the current way to use titles is marked as deprecated

With the current APIv4 you have the JSON elements for the titles separately available.

  • title
  • title_english
  • title_japanese
  • title_synonyms

Those are marked as Deprecated according to the documentation here

The new way combines all of the titles under a single element titles, example:

"titles": [
      {
        "type": "Default",
        "title": "One Piece"
      },
      {
        "type": "Synonym",
        "title": "OP"
      },
      {
        "type": "Japanese",
        "title": "ONE PIECE"
      },
      {
        "type": "English",
        "title": "One Piece"
      }
    ],

Nowhere to check request_cached or request_cache_expiry

Jikan REST API has a Rate Limit of 30 requests per minute, and 2 requests per second.
This becomes a problem when you are going over-limit. With request_cached you can check if your request is cached so you dont have to add to your "rate limit" count. It is a way to not get errors when trying to do a request.

If you do IJikan#GetPerson, i have no idea if it has been cached or not.

GetSeason returning JikanValidationException for year bigger than current year

Hi Ervie, I've noticed GetSeason stopped working as expected, I'm not sure when this happened but the last version of jikan GetSeason returns JikanValidationException when selected year is bigger than current year.

Steps to reproduce:

  • Pass any year > current year to GetSeason

Expected:

  • GetSeason returned data for future seasons if it exists

Actual behavior:

  • GetSeason gives JikanValidationException at JikanDotNet.Helpers.Guard.IsValid[T] (System.Func`2[T,TResult] isValidFunc, T arg, System.String argumentName, System.String message) [0x00020] in :0
    at JikanDotNet.Jikan.GetSeason (System.Int32 year, JikanDotNet.Seasons season) [0x0001d] in

Injectable HttpClient for the HttpClientFactory pattern

It is currently not possible to inject my own HttpClient using IoC.

Also then instead of the Endpoint property in the client config, using the HttpClientFactory pattern one could do this as well:

services.AddHttpClient<IJikan, Jikan>(client => {
  client.Timeout = TimeSpan.FromSeconds(10);
  client.BaseAddress = new Uri(/* your endpoint */)
});

See this page for even more benefits: https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests

SearchAnime results in bad request

_jikan.SearchAnime("one piece", 0) results in the following exception message:

"GET request failed. Status code: BadRequest Inner message: System.Net.Http.StreamContent"

GetAnimeCharactersStaff(MalId) always returns null

It started behaving like this since yesterday.
I'm sure the provided ID is valid (as being an anime) and there's also characters & staff listed at the MAL page. This same ID used to work a few days ago.
Tried with 2 different machines.

SearchAnime method loading duplicates of first page

I was trying to list Animes using the fourth overload for SearchAnime, it loads fine for the first page, but it does not seems working after this. Maybe MAL changed the endpoint?

Steps to reproduce:

  • Use the fourth overload, SearchAnime(string query, int page, AnimeSearchConfig config)
  • From my experience, it doesnt matter if the query was empty or not
  • You can use any config type, I was using AnimeSearchSortable.Title or GenreSearch.Action
  • Request the first page, notice it loads as expected, after this try loading other pages, it will return the same 50 first page items

Anime Character About is empty

Hi Ervie, after update 1.5.0 the property About from Character is empty.

Steps to reproduce:

Use GetCharacter(CharacterMALid) on Jikan version 1.4.2 to get any character which has a description (About property)

Expected behavior: character which has description on MAL will have text on About property
Actual behavior: text exist inside About property

Use GetCharacter(CharacterMALid) on Jikan version 1.5.0 to get any character which has a description (About property)

Expected behavior: character which has description on MAL will have text on About property
Actual behavior: About property is empty

Ratelimiting support

It would be appreciated to have an interval between requests as a optional parameter. It would be good to support custom ratelimits for self-hosted APIs as well.
As of now the ratelimits for the main instance jikan.moe are:

Daily Limit: Unlimited
30 requests / minute
2 requests / second

Bulk requests must be 1 request / 4 seconds.

GetSeason needs params - current season?

My app broke cuz someone decided to move the API version up.. how do i get current season? it sued to be just GetSeason, your documentation shows that it still works but in 2.4.0 it does not accept it without params

Retrieving next page from GetUpcomingSeasonAsync

Is there any way to retrieve next page from GetUpcomingSeasonAsync method? Now it returns 25 records from first page with pagination data but with no option to set the number of page or am I missing something? Thank you

Exception while trying to get user's manga/anime list

Repro

.NET6, JikanDotNet v2.1.0

using JikanDotNet;

var jikan = new Jikan();
try
{
	_ = await jikan.GetUserMangaListAsync("N0D4N");
	//_ = await jikan.GetUserAnimeListAsync("N0D4N");
}
catch (Exception ex)
{
	Console.WriteLine(ex);
}

Exception

JikanDotNet.Exceptions.JikanRequestException: Serialization failed.
Inner exception message: The JSON value could not be converted to System.String. Path: $.data[0].reading_status | LineNumber: 0 | BytePositionInLine: 28.
 ---> System.Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.data[0].reading_status | LineNumber: 0 | BytePositionInLine: 28.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string.
   at System.Text.Json.Utf8JsonReader.GetString()
   at System.Text.Json.Serialization.Converters.StringConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at JikanDotNet.Jikan.ExecuteGetRequestAsync[T](ICollection`1 routeSections)
   --- End of inner exception stack trace ---
   at JikanDotNet.Jikan.ExecuteGetRequestAsync[T](ICollection`1 routeSections)
   at JikanDotNet.Jikan.GetUserMangaListAsync(String username)
   at Program.<Main>$(String[] args)

Jikan response for https://api.jikan.moe/v4/users/N0D4N/mangalist

{
  "data": [
    {
      "reading_status": 1,
      "score": 0,
      // everything else

Notes

Seems like System.Text.Json doesn't convert json number value to string automatically, which is ReadingStatus/WatchingStatus of MangaListEntry/AnimeListEntry. Unfortunately JsonSerializerOptions doesn't have option to allow getting string from json's number, one way to fix it would be to write custom JsonConverter that will allow it, another is to change properties type from string to int/enum

AnimeSearchConfig excluded genres don't behave as expected

Hi Ervie, I was trying to implement AnimeSearchConfig filters and noticed the end point of excluded genres is not behaving as expected. I've Tried to fill 5 genres for exclusion(and marked the boolean property "GenreIncluded" as false), the returning collection was empty. I've checked as well MAL website, there it works removing the searched animes which has any genres specified for exclusion.

Steps to reproduce:

Expected:

  • create a AnimeSearchConfig object with sort by score and descending
  • fill genres with "hentai", "yaoi", "yuri", "ecchi", "harem"
  • set the GenreIncluded property as false
  • collection return without animes of the specified genres

Actual behavior:

  • create a AnimeSearchConfig object with sort by score and descending
  • fill genres with "hentai", "yaoi", "yuri", "ecchi", "harem"
  • set the GenreIncluded property as false
  • collection return empty

[Proposal] Make argument check on enums to make sure they are valid before making HTTP request

Reasoning

Currently jikan.net doesn't make any checks on any enums passed as parameters to methods of Jikan class, so its possible to pass int casted to enum to method which will result in making HTTP request and failing on parsing response from Jikan server.

Proposal

Add method IsValidEnum or IsDefinedEnum to Guard class which will check if passed parameter is defined enum. Add checks for validity of enums passed in methods.

Drawbacks

Execution time of method with added checks will increase, and i'm not sure if its worth it for safechecking for such edge cases.

Note

I can make PR for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.