Allow NewsDownloader plugin to download EPUB documents#15065
Merged
Conversation
Frenzie
reviewed
Mar 3, 2026
| 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 |
Frenzie
reviewed
Mar 3, 2026
| then | ||
| logger.warn("request interrupted:", status or code) | ||
| return false, code | ||
| return false, "", code |
Member
There was a problem hiding this comment.
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
end46f3042 to
b9a2aaa
Compare
Contributor
Author
|
I implemented your suggestions, feel free to have another look. |
Frenzie
reviewed
Mar 4, 2026
| local util = require("util") | ||
| local _ = require("gettext") | ||
| local T = FFIUtil.template | ||
| local DocumentRegistry = require("document/documentregistry") |
Frenzie
reviewed
Mar 4, 2026
Comment on lines
509
to
510
| logger.dbg("NewsDownloader: Content-Type of response was:", content_type) | ||
| logger.dbg("NewsDownloader: Response was:", response) |
Member
There was a problem hiding this comment.
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) |
Frenzie
reviewed
Mar 4, 2026
| 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) |
Member
There was a problem hiding this comment.
Suggested change
| logger.err("No content type, not saving", link) | |
| logger.err("NewsDownloader: No content type, not saving", link) |
Frenzie
reviewed
Mar 4, 2026
| file:write(content) | ||
| file:close() | ||
| else | ||
| logger.err("Unsupported feed Content-Type:", content_type) |
Member
There was a problem hiding this comment.
Suggested change
| logger.err("Unsupported feed Content-Type:", content_type) | |
| logger.err("NewsDownloader: Unsupported feed Content-Type:", content_type) |
Frenzie
reviewed
Mar 4, 2026
| if headers and headers["content-type"] then | ||
| content_type = headers["content-type"] | ||
| else | ||
| logger.warn("Request didn't return a Content-Type header") |
Member
There was a problem hiding this comment.
Suggested change
| logger.warn("Request didn't return a Content-Type header") | |
| logger.warn("NewsDownloader: Request didn't return a Content-Type header") |
Frenzie
reviewed
Mar 4, 2026
| 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" |
Member
There was a problem hiding this comment.
Are these ever shown to the user or just the logs?
Contributor
Author
There was a problem hiding this comment.
Do you mean the content_type? Just the logs afaics
Member
There was a problem hiding this comment.
No, I mean the untranslated string.
Member
There was a problem hiding this comment.
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>
b9a2aaa to
27717ef
Compare
Contributor
Author
|
All suggestions should be implemented :) |
3 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented as discussed in #15061.
This is tested with the following:
All articles were downloaded successfully.
This change is