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 1/2] 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): From 5a28507414916c9f1e30034571fa93f4e4057f86 Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:57:34 +0530 Subject: [PATCH 2/2] ... --- recipes/indian_express.recipe | 1 + recipes/natgeohis.recipe | 15 +++++++++++++-- recipes/outlook_india.recipe | 3 +-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/recipes/indian_express.recipe b/recipes/indian_express.recipe index 9274368581..0cda06c70e 100644 --- a/recipes/indian_express.recipe +++ b/recipes/indian_express.recipe @@ -48,6 +48,7 @@ class IndianExpress(BasicNewsRecipe): def parse_index(self): section_list = [ + ('Daily Briefing', 'https://indianexpress.com/section/live-news/'), ('Front Page', 'https://indianexpress.com/print/front-page/'), ('India', 'https://indianexpress.com/section/india/'), # ('Express Network', 'https://indianexpress.com/print/express-network/'), diff --git a/recipes/natgeohis.recipe b/recipes/natgeohis.recipe index ee5fcec9af..b95967520b 100644 --- a/recipes/natgeohis.recipe +++ b/recipes/natgeohis.recipe @@ -163,6 +163,14 @@ class NatGeo(BasicNewsRecipe): masthead_url = 'https://i.natgeofe.com/n/e76f5368-6797-4794-b7f6-8d757c79ea5c/ng-logo-2fl.png?w=600&h=600' resolve_internal_links = True + 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; } @@ -198,8 +206,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/outlook_india.recipe b/recipes/outlook_india.recipe index b91b6ce4e8..b982befbed 100644 --- a/recipes/outlook_india.recipe +++ b/recipes/outlook_india.recipe @@ -70,8 +70,7 @@ class outlook(BasicNewsRecipe): self.description = self.tag_to_string(summ) tme = soup.find(attrs={'class':'arr__timeago'}) if tme: - self.timefmt = ' [' + self.tag_to_string(tme).strip() + ']' - + self.timefmt = ' [' + self.tag_to_string(tme).split('-')[-1].strip() + ']' ans = []