morss: ability to use first link from desc instead of default link

master
pictuga 2020-05-13 12:29:53 +02:00
parent 038f267ea2
commit 91be2d229e
1 changed files with 9 additions and 2 deletions

View File

@ -130,7 +130,7 @@ def parseOptions(options):
return out return out
def ItemFix(item, feedurl='/'): def ItemFix(item, options, feedurl='/'):
""" Improves feed items (absolute links, resolve feedburner links, etc) """ """ Improves feed items (absolute links, resolve feedburner links, etc) """
# check unwanted uppercase title # check unwanted uppercase title
@ -149,6 +149,13 @@ def ItemFix(item, feedurl='/'):
item.link = match[0] item.link = match[0]
log(item.link) log(item.link)
# at user's election, use first <a>
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 # check relative urls
item.link = urljoin(feedurl, item.link) item.link = urljoin(feedurl, item.link)
@ -375,7 +382,7 @@ def FeedGather(rss, url, options):
if item is None: if item is None:
continue 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 time.time() - start_time > max_time >= 0 or i + 1 > max_item >= 0:
if not options.proxy: if not options.proxy: