Skip to content

Commit

Permalink
feat(parsing/medium.Image): prefer HD fallback
Browse files Browse the repository at this point in the history
Only images from sinaimg and pixiv may benefit from the patch.
Fixes #329

Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 committed Sep 9, 2023
1 parent a37afb2 commit e3316ef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parsing/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,15 @@ 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]]):
super().__init__(urls)
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:
Expand All @@ -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
Expand Down

0 comments on commit e3316ef

Please sign in to comment.