sdaqo / anipy-cli

Little tool in python to watch and download anime from the terminal (the better way to watch anime). Also applicable as an API
https://sdaqo.github.io/anipy-cli
GNU General Public License v3.0
265 stars 38 forks source link

[anipy-api] get_info() fails on dubbed anime, where the non dubbed version has an identifier that is not a direct prefix of the dubbed anime identifier #201

Open quenzt opened 3 weeks ago

quenzt commented 3 weeks ago

Describe the bug When provider.get_search with the gogo-provider one of the returned values is an identifier that uniquely identifies an anime. For dubbed anime the -dub or -japanese-dub suffix is removed from the anime. When calling get_info() on an anime where the non dubbed version of the anime has an identifier that is not the dubbed version's identifier minus -dub or -japanese-dub , it fails with a 404 error.

For example, these are the links to the dubbed and subbed version of the same anime: https://gogoanime3.co/category/tate-no-yuusha-no-nariagari-2nd-season https://gogoanime3.co/category/tate-no-yuusha-no-nariagari-season-2-dub When using the provider.get_search the dubbed version gets the identifier tate-no-yuusha-no-nariagari-season-2

If you now execute get_info() on the dubbed version you get a 404 error, because it tries to fetch https://gogoanime3.co/category/tate-no-yuusha-no-nariagari-season-2 and that page does not exist.

To Reproduce take a look at this mini-script

from anipy_api.provider import list_providers, get_provider 
from anipy_api.anime import Anime
from anipy_api.provider import LanguageTypeEnum

provider = get_provider("gogoanime")
search = provider.get_search("Tate no Yuusha no Nariagari Season 2")

for result in search:
    anime = Anime(provider, result.name, result.identifier, result.languages)
    anime.get_info()

Running it causes the following error

(anipy) quenzt@quenzt-ESPRIMO-P956:~/newdl$ /home/quenzt/newdl/anipy/bin/python /home/quenzt/newdl/debug_404.py
Traceback (most recent call last):
  File "/home/quenzt/newdl/debug_404.py", line 11, in <module>
    anime.get_info()
  File "/home/quenzt/newdl/anipy/lib/python3.12/site-packages/anipy_api/anime.py", line 92, in get_info
    return self.provider.get_info(self.identifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quenzt/newdl/anipy/lib/python3.12/site-packages/anipy_api/provider/providers/gogo_provider.py", line 189, in get_info
    res = self._request_page(req)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quenzt/newdl/anipy/lib/python3.12/site-packages/anipy_api/provider/base.py", line 156, in _request_page
    return request_page(self.session, req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quenzt/newdl/anipy/lib/python3.12/site-packages/anipy_api/provider/utils.py", line 26, in request_page
    res.raise_for_status()
  File "/home/quenzt/newdl/anipy/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Page not found for url: https://gogoanime3.co/category/tate-no-yuusha-no-nariagari-season-2

Expected behavior It should not 404 error out. Instead, it should fetch the info from either the dubbed or non dubbed version.

Info

Name: anipy-cli
Version: 3.2.1
Summary: Watch and Download anime from the comfort of your Terminal
Home-page: https://sdaqo.github.io/anipy-cli
Author: sdaqo
Author-email: sdaqo.dev@protonmail.com
License: GPL-3.0
Location: /home/quenzt/newdl/anipy/lib/python3.12/site-packages
Requires: anipy-api, appdirs, inquirerpy, pypresence, pyyaml, yaspin
Required-by: 

Platform

sdaqo commented 3 weeks ago

Gogoanime is a little bit of a pita when it comes to that, as you can see in the example links you provided, one has "2nd season" and the other "season-2". In the meanwhile, please use yuugen, you will get the same videos, because they crawl gogo. They also do a better job at organizing their anime so stuff like this does not happen.