From 8452d04a33352ef10ae1c12b86e7a450139d395c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 20 Jun 2024 23:11:07 +0200 Subject: [PATCH] [fanbox] handle KeyError for no longer existing plans (#5759) return the plan of the next higher tier instead --- gallery_dl/extractor/fanbox.py | 7 ++++++- test/results/fanbox.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/fanbox.py b/gallery_dl/extractor/fanbox.py index 2223403e..3d51792f 100644 --- a/gallery_dl/extractor/fanbox.py +++ b/gallery_dl/extractor/fanbox.py @@ -113,7 +113,12 @@ class FanboxExtractor(Extractor): post["user"] = self._get_user_data(post["creatorId"]) if self._meta_plan: plans = self._get_plan_data(post["creatorId"]) - post["plan"] = plans[post["feeRequired"]] + fee = post["feeRequired"] + try: + post["plan"] = plans[fee] + except KeyError: + post["plan"] = plans[fee] = min( + p for p in plans.values() if p["fee"] >= fee) return content_body, post diff --git a/test/results/fanbox.py b/test/results/fanbox.py index d5910927..3031a759 100644 --- a/test/results/fanbox.py +++ b/test/results/fanbox.py @@ -123,6 +123,22 @@ __tests__ = ( }, }, +{ + "#url" : "https://saki9184.fanbox.cc/posts/7754760", + "#comment" : "missing plan for exact 'feeRequired' value (#5759)", + "#category": ("", "fanbox", "post"), + "#class" : fanbox.FanboxPostExtractor, + "#options" : {"metadata": "plan"}, + + "feeRequired": 300, + "plan" : { + "creatorId": "saki9184", + "fee" : 350, + "id" : "414274", + "title" : "涼宮ハルヒの憂鬱", + }, +}, + { "#url" : "https://mochirong.fanbox.cc/posts/3746116", "#comment" : "imageMap file order (#2718)",