Skip to content

Commit

Permalink
Revert "fix(parsing): WEBP unnecessarily converted to PNG"
Browse files Browse the repository at this point in the history
It turns out that Telegram cannot convert WEBP properly. In particular,
color space conversion seems broken.
Fixes #372

This reverts commit 3bafebf.
  • Loading branch information
Rongronggg9 committed Nov 20, 2023
1 parent 9e43aff commit 9dbb1cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/parsing/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@

# Note:
# One message can have 10 media at most, but there are some exceptions.
# 1. A GIF (Animation) and WEBP (sent as a file) must occupy a SINGLE message.
# 1a. A WEBP sent as a file will be shown just like a sticker.
# 1b. Since some time in 2022, Telegram DC will convert any WEBP sent as an image to a JPG. Before that, same as (1a).
# 1. A GIF (Animation) and webp (although as a file) must occupy a SINGLE message.
# 2. Videos and Images can be mixed in a media group, but any other type of media cannot be in the same message.
# 3. Images uploaded as MessageMediaPhoto will be considered as an image. While MessageMediaDocument not, it's a file.
# 4. Any other type of media except Image must be uploaded as MessageMediaDocument.
Expand Down Expand Up @@ -348,14 +346,14 @@ def flushed_log():
self.valid = False
self.drop_silently = True
return False
# force convert SVG to PNG
# force convert WEBP/SVG to PNG
if (
self.content_type
and any(keyword in self.content_type for keyword in ('svg', 'application'))
and any(keyword in self.content_type for keyword in ('webp', 'svg', 'application'))
):
# immediately fall back to 'wsrv.nl'
self.urls = [url for url in self.urls if url.startswith(env.IMAGES_WESERV_NL)]
invalid_reasons.append('force convert SVG to PNG')
invalid_reasons.append('force convert WEBP/SVG to PNG')
continue
# always invalid
if self.width + self.height > 10000:
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/post_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ async def parse_html(self):
medium.valid = False
elif not enclosure.type:
medium = File(enclosure.url)
elif 'svg' in enclosure.type:
elif any(keyword in enclosure.type for keyword in ('webp', 'svg')):
medium = Image(enclosure.url)
medium.url = construct_weserv_url_convert_to_2560_png(enclosure.url)
elif enclosure.type.startswith('image/gif'):
Expand Down

0 comments on commit 9dbb1cb

Please sign in to comment.