From 566b934ca157f57368f02e46162885fb41b3f070 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 22 Mar 2024 21:28:54 -0400 Subject: [PATCH] properly figure out correct thumbnail url for fanza --- dlibrary/dlibrary.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index b95df94..3e9d641 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -229,7 +229,16 @@ async def fetch_async(args): authors = db_row.pop('authors') tags = db_row.pop('tags') if FANZA_ID_REGEX.fullmatch(work_id): - thumbnail_url = f'https://doujin-assets.dmm.co.jp/digital/comic/{work_id}/{work_id}pl.jpg' + candidate_urls = [ + f'https://doujin-assets.dmm.co.jp/digital/{work_type}/{work_id}/{work_id}pl.jpg' + for work_type in ['comic', 'cg'] + ] + thumbnail_url = None + for url in candidate_urls: + h = requests.head(url, allow_redirects=False) + if h.status_code == 200: + thumbnail_url = url + break elif FAKKU_ID_REGEX.fullmatch(work_id): thumbnail_url = None else: