abhinavk99/jikanpy

unexpected ClientException on manga search endpoint with genre IDs 44-45

Closed this issue · 1 comments

the number of anime genres doesnt equal the number of manga genres, so trying to do a search for the manga thriller genre (45) results in an empty response

Anime Genres = 1-43
Manga Genres = 1-45

>>> j.search("manga", "Hako to Zero", parameters={'type': 'novel', 'genre': 1})["results"][0]
{'mal_id': 55215, 'url': 'https://myanimelist.net/manga/55215/Utsuro_no_Hako_to_Zero_no_Maria', 'image_url': 'https://cdn.myanimelist.net/images/manga/2/175662.jpg?s=b9b22bf0e733997a1325b6461032eeac', 'title': 'Utsuro no Hako to Zero no Maria', 'publishing': False, 'synopsis': 'Kazuki Hoshino values his everyday life above all else. He spends the days carefree with his friends at school, until the uneventful bliss suddenly comes to a halt with the transfer of the aloof beaut...', 'type': 'Novel', 'chapters': 40, 'volumes': 7, 'score': 8.9, 'start_date': '2009-01-10T00:00:00+00:00', 'end_date': '2015-06-10T00:00:00+00:00', 'members': 67838}
>>> j.search("manga", "Hako to Zero", parameters={'type': 'novel', 'genre': 45})
{'request_hash': 'request:search:822526d692447538103d8049df898f648d350872', 'request_cached': True, 'request_cache_expiry': 41368, 'results': [], 'last_page': 1}

Corresponding MAL urls:

/v3/search/manga?q=Hako%20to%20Zero&type=novel&genre=1&
/v3/search/manga?q=Hako%20to%20Zero&type=novel&genre=45&

You can see the manga genre constants defined in the jikan here.

Place where this is defined in jikanpy

Thriller genre on MAL: https://myanimelist.net/manga/genre/45/Thriller

This could be fixed by changing the genre range depending on search_type, or having different key names for anime/manga genres (e.g. {'anime_genre': 43}, {'manga_genre': 45}), the former seems more reasonable.

Closed this earlier as I thought there was no error, but the error was actually being caused by something else.

This if check

elif isinstance(values, tuple) and value not in values:

will always fail for the genre key, since isinstance(values, tuple), where values is range(1,44) will always be False.

hence searching for manga genre 44-45 raises no error, when it typically should.

I modified the parameters file like:

--- a/jikanpy/parameters.py
+++ b/jikanpy/parameters.py
@@ -68,7 +68,7 @@ SEARCH_PARAMS: Dict[str, Union[str, Tuple[Union[int, str], ...], Iterable[int]]]
         'r',
         'rx'
     ),
-    'genre': range(1, 44),
+    'genre': tuple(range(1, 44)),
     'score': '',
     'start_date': '',
     'end_date': '',

and that causes the expected error:

>>> len(j.search("manga", "", parameters={'type': 'novel', 'genre': 43})["results"])
type novel
('tv', 'ova', 'movie', 'special', 'ona', 'music', 'manga', 'novel', 'oneshot', 'doujin', 'manhwa', 'manhua')
False
genre 43
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43)
False
9
>>> len(j.search("manga", "", parameters={'type': 'novel', 'genre': 45})["results"])
type novel
('tv', 'ova', 'movie', 'special', 'ona', 'music', 'manga', 'novel', 'oneshot', 'doujin', 'manhwa', 'manhua')
False
genre 45
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sean/bin/jikanpy/jikanpy/jikan.py", line 24, in search
    url: str = self._get_search_url(search_type, query, page, parameters)
  File "/Users/sean/bin/jikanpy/jikanpy/abstractjikan.py", line 87, in _get_search_url
    raise ClientException('The value is not valid')
jikanpy.exceptions.ClientException: The value is not valid

The corresponding searches on jikan would be:

http://api.jikan.moe/v3/search/manga?q=&type=novel&genre=43
http://api.jikan.moe/v3/search/manga?q=&type=novel&genre=45

As I said above:

This could be fixed by changing the genre range depending on search_type, or having different key names for anime/manga genres (e.g. {'anime_genre': 43}, {'manga_genre': 45}), the former seems more reasonable.