From 91be2d229e5a6a6f1b5147e55bdf00a56ead65e4 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 13 May 2020 12:29:53 +0200 Subject: [PATCH] morss: ability to use first link from desc instead of default link --- morss/morss.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/morss/morss.py b/morss/morss.py index 019badc..ce6ac9e 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -130,7 +130,7 @@ def parseOptions(options): return out -def ItemFix(item, feedurl='/'): +def ItemFix(item, options, feedurl='/'): """ Improves feed items (absolute links, resolve feedburner links, etc) """ # check unwanted uppercase title @@ -149,6 +149,13 @@ def ItemFix(item, feedurl='/'): item.link = match[0] log(item.link) + # at user's election, use first + if options.firstlink and (item.desc or item.content): + match = lxml.html.fromstring(item.desc or item.content).xpath('//a/@href') + if len(match): + item.link = match[0] + log(item.link) + # check relative urls item.link = urljoin(feedurl, item.link) @@ -375,7 +382,7 @@ def FeedGather(rss, url, options): if item is None: continue - item = ItemFix(item, url) + item = ItemFix(item, options, url) if time.time() - start_time > max_time >= 0 or i + 1 > max_item >= 0: if not options.proxy: