Git Product home page Git Product logo

nhentaisharp's Introduction

Build status NuGet codecov Unit tests CodeFactor

NHentaiSharp

NHentaiSharp is a C# library to use NHentai.net API.

How to download it?

You can download it from NuGet with the following command line:

Install-Package NHentaiSharp

Example: Getting a random doujinshi

string[] tags = new[] { // Tags for the upcoming searches
  "loli", // We add the tag loli
  NHentaiSharp.Core.SearchClient.GetExcludeTag("rape"), // We exclude the tag rape
  NHentaiSharp.Core.SearchClient.GetCategoryTag("kantai collection", NHentaiSharp.Search.TagType.Parody)
  // We search doujinshi of the anime/game Kantai Collection
};

Random r = new Random();
// We do a search with the tags
var result = await NHentaiSharp.Core.SearchClient.SearchWithTagsAsync(tags);
int page = r.Next(0, result.numPages) + 1; // Page count begin at 1
// We do a new search at a random page
result = await NHentaiSharp.Core.SearchClient.SearchWithTagsAsync(tags, page);
var doujinshi = result.elements[r.Next(0, result.elements.Length)]; // We get a random doujinshi

Console.WriteLine("Random doujinshi: " + doujinshi.prettyTitle + Environment.NewLine +
  "URL: " + doujinshi.url);

For more information about using this library, please check the wiki.

nhentaisharp's People

Contributors

xwilarg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

andy840119

nhentaisharp's Issues

Failed in SearchClient.SearchAsync(8911)

This error occurred on November 20, 2021.

> SearchClient.SearchAsync(8911).Result;;
System.AggregateException: One or more errors occurred. (Invalid format '0')
 ---> System.ArgumentException: Invalid format '0'
   at NHentaiSharp.Search.Page..ctor(Object json, String urlBase, String urlPreview)
   at CallSite.Target(Closure , CallSite , Type , Object , String , String )
   at NHentaiSharp.Search.GalleryElement..ctor(Object json)
   at CallSite.Target(Closure , CallSite , Type , Object )
   at NHentaiSharp.Search.SearchResult..ctor(Object json)
   at NHentaiSharp.Core.SearchClient.SearchAsync(Int32 page)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at <StartupCode$FSI_0007>.$FSI_0007.main@()

Failed randomly in SearchWithTagsAsync

When I searching with "loli" tag or "touhou" tag, it will failed randomly with exception Your search didn't return any result, that probably mean one of the argument you provided is invalid.

  • Tag "loli"
    • Page 1 OK
    • Page 2 Failed
    • Page 3 Failed
    • Page 4 OK
    • Page 5 OK
  • Tag "touhou"
    • Page 1 Failed
    • Page 2 OK
    • Page 3 OK
    • Page 4 OK
    • Page 5 OK

2021/11/25 12:28 (UTC)

Logs:

> SearchClient.SearchWithTagsAsync([|"loli"|], 1).Result;;
val it: NHentaiSharp.Search.SearchResult =
  NHentaiSharp.Search.SearchResult
    {elements = [|NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement|];
     numPages = 3245;
     numPerPage = 25;}

> SearchClient.SearchWithTagsAsync([|"loli"|], 2).Result;;
System.AggregateException: One or more errors occurred. (Your search didn't return any result, that probably mean one of the argument you provided is invalid)
 ---> NHentaiSharp.Exception.InvalidArgumentException: Your search didn't return any result, that probably mean one of the argument you provided is invalid
   at NHentaiSharp.Search.SearchResult..ctor(Object json)
   at NHentaiSharp.Core.SearchClient.SearchWithTagsAsync(String[] tags, Int32 page, PopularitySort sortOption)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at <StartupCode$FSI_0034>.$FSI_0034.main@()
已因出错而停止
> SearchClient.SearchWithTagsAsync([|"loli"|], 3).Result;;
System.AggregateException: One or more errors occurred. (Your search didn't return any result, that probably mean one of the argument you provided is invalid)
 ---> NHentaiSharp.Exception.InvalidArgumentException: Your search didn't return any result, that probably mean one of the argument you provided is invalid
   at NHentaiSharp.Search.SearchResult..ctor(Object json)
   at NHentaiSharp.Core.SearchClient.SearchWithTagsAsync(String[] tags, Int32 page, PopularitySort sortOption)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at <StartupCode$FSI_0035>.$FSI_0035.main@()
已因出错而停止
> SearchClient.SearchWithTagsAsync([|"loli"|], 4).Result;;
val it: NHentaiSharp.Search.SearchResult =
  NHentaiSharp.Search.SearchResult
    {elements = [|NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement;
                  NHentaiSharp.Search.GalleryElement|];
     numPages = 3245;
     numPerPage = 25;}

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.