diff --git a/plugins/newsdownloader.koplugin/main.lua b/plugins/newsdownloader.koplugin/main.lua
index e8a981a9c..3bc1ffaf7 100644
--- a/plugins/newsdownloader.koplugin/main.lua
+++ b/plugins/newsdownloader.koplugin/main.lua
@@ -43,7 +43,7 @@ local FEED_TYPE_ATOM = "atom"
-- If a title looks like
blabla it'll just be feed.title.
-- If a title looks like blabla then we get a table
-- where [1] is the title string and the attributes are also available.
-local function getFeedTitle(possible_title)
+function NewsDownloader.getFeedTitle(possible_title)
if type(possible_title) == "string" then
return util.htmlEntitiesToUtf8(possible_title)
elseif possible_title[1] and type(possible_title[1]) == "string" then
@@ -69,7 +69,7 @@ end
-- Some feeds that can be used for unit test.
-- http://fransdejonge.com/feed/ for multiple links.
-- https://github.com/koreader/koreader/commits/master.atom for single link with attributes.
-local function getFeedLink(possible_link)
+function NewsDownloader.getFeedLink(possible_link)
local E = {}
if type(possible_link) == "string" then
return possible_link
@@ -605,12 +605,20 @@ function NewsDownloader:processFeed(feed_type, feeds, cookies, limit, download_f
total_items = (limit == 0)
and #feeds.rss.channel.item
or limit
+ if feed_item[1] == nil and feed_item.title then
+ -- Normalize data for single-item feeds.
+ feed_item = {feed_item}
+ end
else
- feed_title = getFeedTitle(feeds.feed.title)
+ feed_title = self.getFeedTitle(feeds.feed.title)
feed_item = feeds.feed.entry
total_items = (limit == 0)
and #feeds.feed.entry
or limit
+ if feed_item[1] == nil and feed_item.title then
+ -- Normalize data for single-item feeds.
+ feed_item = {feed_item}
+ end
end
-- Get the path to the output directory.
local feed_output_dir = ("%s%s/"):format(
@@ -686,7 +694,7 @@ local function parseDate(dateTime)
end
local function getTitleWithDate(feed)
- local title = util.getSafeFilename(getFeedTitle(feed.title))
+ local title = util.getSafeFilename(NewsDownloader.getFeedTitle(feed.title))
if feed.updated then
title = parseDate(feed.updated) .. title
elseif feed.pubDate then
@@ -709,7 +717,7 @@ function NewsDownloader:downloadFeed(feed, cookies, feed_output_dir, include_ima
else
logger.dbg("NewsDownloader: News file will be stored to :", news_file_path)
local article_message = T(_("%1\n%2"), message, title_with_date)
- local link = getFeedLink(feed.link)
+ local link = self.getFeedLink(feed.link)
local html = DownloadBackend:loadPage(link, cookies)
DownloadBackend:createEpub(news_file_path, html, link, include_images, article_message, enable_filter, filter_element)
end
@@ -729,7 +737,7 @@ function NewsDownloader:createFromDescription(feed, title, content, feed_output_
local byline = getByline(feed)
local footer = _("If this is only a summary, the full article can be downloaded by going to the News Downloader settings and changing 'Download full article' to 'true'.")
- local base_url = getFeedLink(feed.link)
+ local base_url = self.getFeedLink(feed.link)
if base_url then
if not base_url:match("/$") then
base_url = base_url .. "/"
@@ -761,7 +769,7 @@ function NewsDownloader:createFromDescription(feed, title, content, feed_output_