z411 / trackma

Open multi-site list manager for Unix-like systems. (ex-wMAL)
https://z411.github.io/trackma
GNU General Public License v3.0
761 stars 82 forks source link

Got KeyError when fetching small version of posterImage #665

Closed Eiji7 closed 1 year ago

Eiji7 commented 1 year ago

Hi, as in title I got KeyError.

Here is a Traceback:

Traceback (most recent call last):
  File "$HOME/.local/lib/python3.10/site-packages/trackma/ui/qt/workers.py", line 185, in run
    ret = self.function(*self.args, **self.kwargs)
  File "$HOME/.local/lib/python3.10/site-packages/trackma/ui/qt/workers.py", line 161, in _start
    self.engine.start()
  File "$HOME/.local/lib/python3.10/site-packages/trackma/engine.py", line 249, in start
    (self.api_info, self.mediainfo) = self.data_handler.start()
  File "$HOME/.local/lib/python3.10/site-packages/trackma/data.py", line 178, in start
    self.download_data()
  File "$HOME/.local/lib/python3.10/site-packages/trackma/data.py", line 548, in download_data
    self.showlist = self.api.fetch_list()
  File "$HOME/.local/lib/python3.10/site-packages/trackma/lib/libkitsu.py", line 364, in fetch_list
    info = self._parse_info(media)
  File "$HOME/.local/lib/python3.10/site-packages/trackma/lib/libkitsu.py", line 564, in _parse_info
    'image':       attr['posterImage'] and attr['posterImage']['small'],
KeyError: 'small'

I have installed trackma using pip3 (v0.8.5).

I have changed code this way:


    def _parse_info(self, media):
+        print(str(media))

and found the media entry causing error:

{'id': '44834', 'type': 'anime', 'links': {'self': 'https://kitsu.io/api/edge/anime/44834'}, 'attributes': {'slug': 'strike-the-blood-final', 'canonicalTitle': 'Strike the Blood FINAL', 'titles': {'en': 'Strike the Blood V', 'en_jp': 'Strike the Blood FINAL', 'ja_jp': 'ストライク・ザ・ブラッドFINAL'}, 'episodeCount': 4, 'description': 'The fifth season of Strike the Blood.', 'status': 'finished', 'tba': None, 'subtype': 'OVA', 'posterImage': {'original': 'https://kitsu-production-media.s3.us-west-002.backblazeb2.com/anime/44834/poster_image/def4bedfad0f1d8b97ad7d7fe83e8b92.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=002d6013655cdc00000000003%2F20230114%2Fus-west-002%2Fs3%2Faws4_request&X-Amz-Date=20230114T120944Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=b0b38c983a05de4e8375f2b1f0ce46a48042d037cb8fa284a6edd40ae745331c', 'meta': {'dimensions': {}}}, 'startDate': '2022-03-30', 'endDate': '2022-06-29', 'abbreviatedTitles': [], 'averageRating': '75.93', 'popularityRank': 18221, 'ratingRank': 1617, 'ageRating': 'R', 'ageRatingGuide': 'Mild Nudity', 'userCount': 0, 'favoritesCount': 0, 'nsfw': False}}

Then I have used Python Formatter site and here is the result:

{
    "id": "44834",
    "type": "anime",
    "links": {"self": "https://kitsu.io/api/edge/anime/44834"},
    "attributes": {
        "slug": "strike-the-blood-final",
        "canonicalTitle": "Strike the Blood FINAL",
        "titles": {
            "en": "Strike the Blood V",
            "en_jp": "Strike the Blood FINAL",
            "ja_jp": "ストライク・ザ・ブラッドFINAL",
        },
        "episodeCount": 4,
        "description": "The fifth season of Strike the Blood.",
        "status": "finished",
        "tba": None,
        "subtype": "OVA",
        "posterImage": {
            "original": "https://kitsu-production-media.s3.us-west-002.backblazeb2.com/anime/44834/poster_image/def4bedfad0f1d8b97ad7d7fe83e8b92.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=002d6013655cdc00000000003%2F20230114%2Fus-west-002%2Fs3%2Faws4_request&X-Amz-Date=20230114T120944Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=b0b38c983a05de4e8375f2b1f0ce46a48042d037cb8fa284a6edd40ae745331c",
            "meta": {"dimensions": {}},
        },
        "startDate": "2022-03-30",
        "endDate": "2022-06-29",
        "abbreviatedTitles": [],
        "averageRating": "75.93",
        "popularityRank": 18221,
        "ratingRank": 1617,
        "ageRating": "R",
        "ageRatingGuide": "Mild Nudity",
        "userCount": 0,
        "favoritesCount": 0,
        "nsfw": False,
    },
}

Using above data I have found an anime url Strike the Blood FINAL.

Later I tried the search engine on kitsu page: kitsu search screenshot

Finally I tried to open missing image in new tab and got another error:

UnauthorizedAccess Request has expired given timestamp: '20230108T043150Z' and expiration: 900 

Looks like a kitsu issue, but not handling missing data like this does not allow to use Trackma at all, so that's why I have opened this issue. Could you please update the code to take small version or original version of posterImage?

Edit: I have also created an issue on kitsu feedback page.

FichteFoll commented 1 year ago

I fixed the first part in #666, but for the second about the request expiring it appears we'd need to think of something different to get re-usable images. Either re-request a new URL whenever we need one and the previous one has expired or cache the thumbnails aggressively on disk. I'd prefer the former, combined with caching if that's not happening already (didn't check).

Kitsu could help us with this if they made their URLs accessible for longer, but to really make it usable with the current trackma state it would need to persist for as long as we don't re-fetch the list, which is user-configurable and thus not really on them to consider.

FichteFoll commented 1 year ago

I closed the first part in #666 and created a separate ticket for the expiring URLs at #669. Thanks for reporting.