Skip to content

Opds-pse v1.2 [LastRead]#13357

Merged
Frenzie merged 11 commits into
koreader:masterfrom
shirishsaxena:master
Mar 5, 2025
Merged

Opds-pse v1.2 [LastRead]#13357
Frenzie merged 11 commits into
koreader:masterfrom
shirishsaxena:master

Conversation

@showyee

@showyee showyee commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

Still pretty new to Lua & KOReader, so might’ve missed something. Open to any suggestions...

Changes

  • Added OPDS-PSE v1.2 [lastRead] support in the download dialog whenever pse:lastRead is present.
    • Since the Page Stream option now has three buttons, I added a sub-dialog—clicking "Page Stream" now opens another dialog with all three options.
    • Clicking "Resume From Page N" directs the ImageViewer to open that page image.
  • Fix for serverFileName issues: If the endpoint doesn’t return proper headers on a HEAD request, the filename was set as empty, causing an error saying "Is a directory". Now, it falls back to the original/default filename, and if the filename is modified, it correctly retains that change. Relates to how to export a ebook through opds calibre with actual filename #13007

Screenshots

Page Stream Button & Dialog

Page Stream Button
Page Stream Dialog

Raw File name enabled (existing)
When.no.fileName.from.server.existing.mp4
Raw File name enabled (this change) | last one returns filename in header
This.change.with.all.scenarios.covered.mp4

This change is Reviewable

showyee added 6 commits March 3, 2025 14:41
Opds-pse v1.2 [LastRead], serverFileName fallback & ImageViewer (Fit to Width button)
@poire-z

poire-z commented Mar 3, 2025

Copy link
Copy Markdown
Contributor
  • ImageViewer: Added a "Fit to Width" button. While "Scale to Fit" works fine, I wanted an option that fits the image to width for better readability and scrollability. The "Original Size" option wasn’t cutting it.

Really not fond of that.
You can't just throw a useless-always-there 4th button among 3 valuables ones - just because you want it - or because you read one book with an aspect ratio taller than your device's screen :)
The current button Original/Scale somehow shows the boolean state (at least it shows the "other" state) - your new button makes this crappy.
Possible solution if this is really really needed:

  • have the current button cycle Original > Scale > Fit width > Fit height > Original (but I'll be botherered having to cycle more to get back to original).
  • or better, now that we have anchored-popup ButtonDialog: show the current state in the button and on tap show these 4 scaling options (with the current one greyed out).
    (Don't implement any of that yet, let us discuss it before.)

Not caring about and not familiar with OPDS stuff: but with streaming, are people really reading books via this ImageViewer (not having all the features of Reader, statistics, pages left...) ? Or is it just for preview ?

Comment thread frontend/ui/widget/imageviewer.lua Outdated
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
@Frenzie

Frenzie commented Mar 3, 2025

Copy link
Copy Markdown
Member

Basically lgtm, just a few nits about capitalization and needless comments. (Please keep in mind I only added a few notes explicitly.)

@showyee

showyee commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author
  • ImageViewer: Added a "Fit to Width" button. While "Scale to Fit" works fine, I wanted an option that fits the image to width for better readability and scrollability. The "Original Size" option wasn’t cutting it.

Really not fond of that. You can't just throw a useless-always-there 4th button among 3 valuables ones - just because you want it - or because you read one book with an aspect ratio taller than your device's screen :) The current button Original/Scale somehow shows the boolean state (at least it shows the "other" state) - your new button makes this crappy. Possible solution if this is really really needed:

  • have the current button cycle Original > Scale > Fit width > Fit height > Original (but I'll be botherered having to cycle more to get back to original).

  • or better, now that we have anchored-popup ButtonDialog: show the current state in the button and on tap show these 4 scaling options (with the current one greyed out).
    (Don't implement any of that yet, let us discuss it before.)

Yeah, fair point. I’ll open an issue/enhancement request so we can discuss it properly before making any changes...

Not caring about and not familiar with OPDS stuff: but with streaming, are people really reading books via this ImageViewer (not having all the features of Reader, statistics, pages left...) ? Or is it just for preview ?

Not sure about others, but I use it a lot for reading ongoing manga. Thought it was a minor change, but yeah, it’s kinda crappy :')

Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
local buttons = {
{
{
text = _("\u{23EE} Beginning"),

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.

@showyee showyee changed the title Opds-pse v1.2 [LastRead], serverFileName fallback & ImageViewer (Fit to Width button) Opds-pse v1.2 [LastRead], serverFileName fallback Mar 3, 2025
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
@poire-z

poire-z commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

Not sure about others, but I use it a lot for reading ongoing manga.

If calling ImageViewer from this specific place, where you'll always be showing a book page for reading - and "fit to width" is always preferable, you maybe could compute and set the right scaling options for fit-to-width directly when you instantiate your ImageViewer ?

@Frenzie

Frenzie commented Mar 3, 2025

Copy link
Copy Markdown
Member

"fit to width" is always preferable

It might not necessarily be on something an Elipsa, but I agree. The use case is a bit different from a normal image, so it needn't take all of the regular image defaults.

@showyee

showyee commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

I've opened an enhancement request for the ImageViewer discussion. Please let me know your suggestions there. I'll probably create a separate PR depending on how the discussion goes.

@showyee showyee requested a review from Frenzie March 3, 2025 18:31
@hius07

hius07 commented Mar 4, 2025

Copy link
Copy Markdown
Member
  • If the endpoint doesn’t return proper headers on a HEAD request, the filename was set as empty

Can you show the problematic headers?
Maybe we should fix parsing it, instead of fallback to filename_orig as you propose?

return header:match('filename="*([^"]+)"*')

Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
@showyee

showyee commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author
  • If the endpoint doesn’t return proper headers on a HEAD request, the filename was set as empty

Can you show the problematic headers? Maybe we should fix parsing it, instead of fallback to filename_orig as you propose?

return header:match('filename="*([^"]+)"*')

The issue wasn’t with how the headers were being matched—they were working fine. The problem was with how the OPDS server was set up. It didn’t support a HEAD request, and the filename was only returned in a GET request.
I know this is a server-side issue that needs to be fixed, but encountering an "is a directory" error when downloading a file wasn’t intuitive from a user experience perspective.
Instead of just falling back, maybe we could show a toast message saying, "No filename found from server; using the original name instead.

That said, I’m okay with skipping this change if there are any objections—I’ve already fixed the server-side issue on my end. :')

@hius07

hius07 commented Mar 5, 2025

Copy link
Copy Markdown
Member

To use a server that doesn't return server-filename, a user should uncheck the checkbox and get generated local names.

@showyee

showyee commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

To use a server that doesn't return server-filename, a user should uncheck the checkbox and get generated local names.

I mean, it does return the filename, but not in the HEAD request—rather, in the GET request, which most browsers and downloaders use by default. But sure, I'll revert this change as well...

@hius07

hius07 commented Mar 5, 2025

Copy link
Copy Markdown
Member

in the GET request

Can we use it? In getServerFileName() or in downloadFile()?

@showyee

showyee commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

in the GET request

Can we use it? In getServerFileName() or in downloadFile()?

I think it should be possible to use it in downloadFile(). It won't work well for getServerFileName(). While we can do a partial GET request with Range, I’m not sure if the all servers support it (it might return 206 without a filename header). Plus, Lua libraries may not handle it well, and we could end up fetching the entire content just to get the header?

For this PR, I’ll revert the changes related to serverfilename and come up with a better approach in another PR—perhaps using HEAD (if supported) or have the filename fetch at downloadFile() method, if that sounds good? But still we would need a fallback name or atleast a toast/InfoMessage saying "failed to fetch filename, please untick raw_file_name from opds feed?"

function OPDSBrowser:downloadFile(local_path, remote_url, caller_callback)

@hius07

hius07 commented Mar 5, 2025

Copy link
Copy Markdown
Member

We shouldn't get the entire content just to have a filename, for sure.
I think, the message that no filename received from the server is enough.

@hius07

hius07 commented Mar 5, 2025

Copy link
Copy Markdown
Member

Thanks, can you show the screenshot of the download dialog, to see these special symbols.

@showyee

showyee commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

Yup... my bad, should've included it before...

screenshots

image
image

@showyee showyee changed the title Opds-pse v1.2 [LastRead], serverFileName fallback Opds-pse v1.2 [LastRead] Mar 5, 2025
@hius07

hius07 commented Mar 5, 2025

Copy link
Copy Markdown
Member

Looks good, and the code as well.

@Frenzie Frenzie added this to the 2025.02 milestone Mar 5, 2025
Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
end,
{
-- @translators "Stream" here refers to being able to read documents from an OPDS server without downloading them completely, on a page by page basis.
text = "\u{23EE} " .. _("Page stream"),

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
text = "\u{23EE} " .. _("Page stream"),
text = "\u{23EE} " .. _("Page stream"), -- Black Left-Pointing Double Triangle with Vertical Bar

Or something along those lines, @poire-z or @hius07 used all caps previously.

Comment thread plugins/opds.koplugin/opdsbrowser.lua Outdated
},
{
-- @translators "Stream" here refers to being able to read documents from an OPDS server without downloading them completely, on a page by page basis.
text = _("Stream from page") .. " \u{23E9}",

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.

Same except that'll be the right arrow I presume.

@Frenzie Frenzie merged commit 70d13be into koreader:master Mar 5, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants