Fix for New Yorker stupidly serving photographs in PNG format

This commit is contained in:
Kovid Goyal 2024-02-27 22:45:50 +05:30
parent 09c17cc135
commit f6185b2e55
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -76,10 +76,20 @@ class NewYorker(BasicNewsRecipe):
noscript.name = 'div'
return soup
def preprocess_image(self, img_data, image_url):
from PIL import Image
from calibre import fit_image
from io import BytesIO
img = Image.open(BytesIO(img_data)).convert('RGB')
scaled, nwidth, nheight = fit_image(img.width, img.height, 1024, 1024)
if scaled:
img = img.resize((nwidth, nheight))
buf = BytesIO()
img.save(buf, format='JPEG')
return buf.getvalue()
def parse_index(self):
# Get cover
cover_soup = self.index_to_soup('https://www.newyorker.com/archive')
cover_img = cover_soup.find(
attrs={'class': lambda x: x and 'MagazineSection__cover___' in x})