From e3316ef3d86e6636c39f58d2f23df04767751d4b Mon Sep 17 00:00:00 2001 From: Rongrong Date: Sat, 9 Sep 2023 17:09:46 +0800 Subject: [PATCH] feat(parsing/medium.Image): prefer HD fallback Only images from sinaimg and pixiv may benefit from the patch. Fixes #329 Signed-off-by: Rongrong --- src/parsing/medium.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/parsing/medium.py b/src/parsing/medium.py index 742d63c800..49f5560f72 100644 --- a/src/parsing/medium.py +++ b/src/parsing/medium.py @@ -524,7 +524,7 @@ class Image(Medium): type = IMAGE maxSize = IMAGE_MAX_SIZE typeFallbackTo = File - typeFallbackAllowSelfUrls = True + typeFallbackAllowSelfUrls = False inputMediaExternalType = InputMediaPhotoExternal def __init__(self, urls: Union[str, list[str]]): @@ -532,7 +532,7 @@ def __init__(self, urls: Union[str, list[str]]): new_urls = [] for url in self.urls: sinaimg_match = sinaimg_size_parser(url) - pixiv_match = pixiv_size_parser(url) + pixiv_match = pixiv_size_parser(url) if not sinaimg_match else None if sinaimg_match: parsed_sinaimg = sinaimg_match.groupdict() # is a sinaimg img for size_name in sinaimg_sizes: @@ -550,6 +550,7 @@ def __init__(self, urls: Union[str, list[str]]): if url not in new_urls: new_urls.append(url) self.urls = new_urls + self.type_fallback_urls = new_urls.copy() urls_not_weserv = [url for url in self.urls if not url.startswith(env.IMAGES_WESERV_NL)] self.urls.extend(construct_weserv_url_convert_to_2560_png(urls_not_weserv[i]) for i in range(min(len(urls_not_weserv), 3))) # use for final fallback