From 62173e30f11df0a646bcde82b7656f0f772bf26c Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:55:29 +0530 Subject: [PATCH] Nat Geo add options for hi-res images --- recipes/natgeo.recipe | 15 +++++++++++++-- recipes/natgeomag.recipe | 12 ++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/recipes/natgeo.recipe b/recipes/natgeo.recipe index 4e02b194a7..bb403978e3 100644 --- a/recipes/natgeo.recipe +++ b/recipes/natgeo.recipe @@ -163,6 +163,14 @@ class NatGeo(BasicNewsRecipe): resolve_internal_links = True ignore_duplicate_articles = {'url'} + recipe_specific_options = { + 'res': { + 'short': 'For hi-res images, select a resolution from the\nfollowing options: 800, 1000, 1200 or 1500', + 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use 400 or 300.', + 'default': '600' + } + } + extra_css = ''' blockquote { color:#404040; } .byline, i { font-style:italic; color:#202020; } @@ -223,8 +231,11 @@ class NatGeo(BasicNewsRecipe): for h2 in soup.findAll('h2'): h2.name = 'h4' for img in soup.findAll('img', src=True): - # for high res images use '?w=2000&h=2000' - img['src'] = img['src'] + '?w=600&h=600' + res = '?w=600' + w = self.recipe_specific_options.get('res') + if w and isinstance(w, str): + res = '?w=' + w + img['src'] = img['src'] + res return soup def populate_article_metadata(self, article, soup, first): diff --git a/recipes/natgeomag.recipe b/recipes/natgeomag.recipe index 70724ab4e5..bf5661bb75 100644 --- a/recipes/natgeomag.recipe +++ b/recipes/natgeomag.recipe @@ -176,6 +176,11 @@ class NatGeo(BasicNewsRecipe): 'date': { 'short': 'The date of the edition to download (Month-YYYY format)', 'long': 'For example, March-2023' + }, + 'res': { + 'short': 'For hi-res images, select a resolution from the\nfollowing options: 800, 1000, 1200 or 1500', + 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use 400 or 300.', + 'default': '600' } } @@ -231,8 +236,11 @@ class NatGeo(BasicNewsRecipe): for h2 in soup.findAll('h2'): h2.name = 'h4' for img in soup.findAll('img', src=True): - # for high res images use '?w=2000&h=2000' - img['src'] = img['src'] + '?w=600&h=600' + res = '?w=600' + w = self.recipe_specific_options.get('res') + if w and isinstance(w, str): + res = '?w=' + w + img['src'] = img['src'] + res return soup def populate_article_metadata(self, article, soup, first):