Skip to content

Fix wallabag's "Prefer original non-HTML document" setting#13333

Merged
Frenzie merged 3 commits into
koreader:masterfrom
harmtemolder:master
Mar 10, 2025
Merged

Fix wallabag's "Prefer original non-HTML document" setting#13333
Frenzie merged 3 commits into
koreader:masterfrom
harmtemolder:master

Conversation

@harmtemolder

@harmtemolder harmtemolder commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

Fixes #13279: the wallabag plugin now correctly ignores URLs ending in .html when no mimetype is known and downloads the .epub instead. Also fixes duplicate file extensions for files where no mimetype is known and the title is based on the URL (e.g. .txt files). Also felt the comments explaining the behavior could be improved upon.

Setting it to draft, because I made a minor tweak today, and I'm still testing that.


This change is Reviewable

@Frenzie Frenzie left a comment

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.

lgtm, let me know when you're done testing.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
if mimetype == "text/html" then
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because", article.url, "is HTML")
elseif mimetype == nil then -- base ourselves on the file extension
if util.getFileNameSuffix(article.url):lower() == "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.

.htm is or used to be common as well, if this is sufficiently much of a concern.

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.

Oh, right, forgot about that one

@harmtemolder harmtemolder marked this pull request as ready for review March 10, 2025 06:30
@harmtemolder

Copy link
Copy Markdown
Contributor Author

@Frenzie I'm done testing. Could you take a look?

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- A function represents `null` in our JSON.decode, because `nil` would just disappear.
-- We can simplify that to not a string.
local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
-- The mimetype is actually an HTTP Content-Type, so we remove everything from the `;` onward

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.

The original comment is better. It explains the why, while this just repeats the code below.

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- We can simplify that to not a string.
local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
-- The mimetype is actually an HTTP Content-Type, so we remove everything from the `;` onward
-- Wallabag returns `null` if no mimetype is known, which is JSON.decoded to a function,

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.

The old comment here is also mich clearer. "which is JSON decoded to a function"? Why, what does that even mean? The original comment is clear.

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- All webpages are HTML. Ignore them since we want the Wallabag EPUB instead!
if self.download_original_document then
if mimetype ~= "text/html" and DocumentRegistry:hasProvider(nil, mimetype) then
-- Download any filetype that we have a provider for, other than HTML, from the original URL

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.

This too seems to be rewritten to paraphrase rather than explain the code.

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
logger.dbg("Wallabag:downloadArticle: ignoring EPUB in favor of original", article.url)
file_ext = "." .. util.getFileNameSuffix(article.url)
item_url = article.url
-- Fix duplicate extensions (e.g. `.txt.txt`)

@Frenzie Frenzie Mar 10, 2025

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.

What does this mean? When or why might this happen?

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.

Done.

@Frenzie Frenzie added this to the 2025.02 milestone Mar 10, 2025
@Frenzie Frenzie added the Plugin label Mar 10, 2025
@Frenzie

Frenzie commented Mar 10, 2025

Copy link
Copy Markdown
Member

I'm not sure if it matters much here, but having a provider doesn't necessarily mean a format is very well supported. EPUB conversion by Wallabag could theoretically be preferable in some cases.

@harmtemolder harmtemolder left a comment

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.

Interesting thought. It shouldn't be too hard to add more exceptions in the future. Maybe leave it for now, but add it if someone encounters such a case and files an issue?

Reviewable status: 0 of 1 files reviewed, 5 unresolved discussions (waiting on @Frenzie)

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- A function represents `null` in our JSON.decode, because `nil` would just disappear.
-- We can simplify that to not a string.
local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
-- The mimetype is actually an HTTP Content-Type, so we remove everything from the `;` onward

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- We can simplify that to not a string.
local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
-- The mimetype is actually an HTTP Content-Type, so we remove everything from the `;` onward
-- Wallabag returns `null` if no mimetype is known, which is JSON.decoded to a function,

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
-- All webpages are HTML. Ignore them since we want the Wallabag EPUB instead!
if self.download_original_document then
if mimetype ~= "text/html" and DocumentRegistry:hasProvider(nil, mimetype) then
-- Download any filetype that we have a provider for, other than HTML, from the original URL

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.

Done.

Comment thread plugins/wallabag.koplugin/main.lua Outdated
logger.dbg("Wallabag:downloadArticle: ignoring EPUB in favor of original", article.url)
file_ext = "." .. util.getFileNameSuffix(article.url)
item_url = article.url
-- Fix duplicate extensions (e.g. `.txt.txt`)

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.

Done.

@Frenzie

Frenzie commented Mar 10, 2025

Copy link
Copy Markdown
Member

Interesting thought. It shouldn't be too hard to add more exceptions in the future. Maybe leave it for now, but add it if someone encounters such a case and files an issue?

I assume Wallabag doesn't convert Mobi or some such anyway, but if it did there's a chance it'd do a better job.

@Frenzie Frenzie merged commit cf1fb70 into koreader:master Mar 10, 2025
@Frenzie

Frenzie commented Mar 10, 2025

Copy link
Copy Markdown
Member

Anyway, thanks for testing!

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.

wallabag plugin: "Prefer original non-HTML document" downloads some HTML files

2 participants