Skip to content

Allow NewsDownloader plugin to download EPUB documents#15065

Merged
Frenzie merged 2 commits into
koreader:masterfrom
Witcher01:newsdownloader-epub
Mar 4, 2026
Merged

Allow NewsDownloader plugin to download EPUB documents#15065
Frenzie merged 2 commits into
koreader:masterfrom
Witcher01:newsdownloader-epub

Conversation

@Witcher01

@Witcher01 Witcher01 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Implemented as discussed in #15061.

This is tested with the following:

All articles were downloaded successfully.


This change is Reviewable

local html = DownloadBackend:loadPage(link, cookies, extra_headers)
DownloadBackend:createEpub(news_file_path, html, link, include_images, article_message, enable_filter, filter_element, block_element)
local content_type, content = DownloadBackend:loadPage(link, cookies, extra_headers)
if content_type == "text/html" then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or application/xhtml+xml

then
logger.warn("request interrupted:", status or code)
return false, code
return false, "", code

@Frenzie Frenzie Mar 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd write this a bit differently:

Suggested change
return false, "", code
return false, nil, code

Then where you use it, you can do:

if not content_type then
    return
elseif html or xhtml then
    -- make EPUB
elseif DocumentRegistry:hasProvider(nil, content_type) then
    -- supported mimetype
    local file = io.open(news_file_path, "w")
else
    -- unsupported
end

@Witcher01 Witcher01 force-pushed the newsdownloader-epub branch 2 times, most recently from 46f3042 to b9a2aaa Compare March 4, 2026 13:23
@Witcher01

Copy link
Copy Markdown
Contributor Author

I implemented your suggestions, feel free to have another look.

local util = require("util")
local _ = require("gettext")
local T = FFIUtil.template
local DocumentRegistry = require("document/documentregistry")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 3 please.

Comment on lines 509 to 510
logger.dbg("NewsDownloader: Content-Type of response was:", content_type)
logger.dbg("NewsDownloader: Response was:", response)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to flood lines. ;-)

Suggested change
logger.dbg("NewsDownloader: Content-Type of response was:", content_type)
logger.dbg("NewsDownloader: Response was:", response)
logger.dbg("NewsDownloader: content_type:", content_type), response:", response)

DownloadBackend:createEpub(news_file_path, html, link, include_images, article_message, enable_filter, filter_element, block_element)
local content_type, content = DownloadBackend:loadPage(link, cookies, extra_headers)
if not content_type then
logger.err("No content type, not saving", link)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.err("No content type, not saving", link)
logger.err("NewsDownloader: No content type, not saving", link)

file:write(content)
file:close()
else
logger.err("Unsupported feed Content-Type:", content_type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.err("Unsupported feed Content-Type:", content_type)
logger.err("NewsDownloader: Unsupported feed Content-Type:", content_type)

if headers and headers["content-type"] then
content_type = headers["content-type"]
else
logger.warn("Request didn't return a Content-Type header")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warn("Request didn't return a Content-Type header")
logger.warn("NewsDownloader: Request didn't return a Content-Type header")

if headers == nil then
logger.warn("No HTTP headers:", status or code or "network unreachable")
return false, "Network or remote server unavailable"
return false, nil, "Network or remote server unavailable"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these ever shown to the user or just the logs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the content_type? Just the logs afaics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean the untranslated string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is fine for logs-only, not for user-facing.

To allow for further handling of specific content types returned when
querying a URL for its content make the function "getUrlContent" also
return the value of the "Content-Type" header of the response.

Signed-off-by: Thomas Böhler <witcher@wiredspace.de>
The NewsDownloader plugin downloads HTML and converts it into EPUB
documents. If the feed already serves EPUB itself it saves us the step
of converting the content to EPUB ourselves, so save the EPUB document
without any processing.

Signed-off-by: Thomas Böhler <witcher@wiredspace.de>
@Witcher01 Witcher01 force-pushed the newsdownloader-epub branch from b9a2aaa to 27717ef Compare March 4, 2026 14:39
@Witcher01

Copy link
Copy Markdown
Contributor Author

All suggestions should be implemented :)

@Frenzie Frenzie merged commit a7cb81c into koreader:master Mar 4, 2026
2 checks passed
@Frenzie Frenzie added this to the 2026.02 milestone Mar 4, 2026
@Frenzie Frenzie added the Plugin label Mar 4, 2026
Frenzie added a commit that referenced this pull request Mar 26, 2026
Frenzie added a commit that referenced this pull request Mar 26, 2026
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants