-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Custom metadata #10861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom metadata #10861
Conversation
TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just some early comments, have to run, will review more later today.)
frontend/docsettings.lua
Outdated
@@ -16,6 +16,7 @@ local DocSettings = LuaSettings:extend{} | |||
|
|||
local HISTORY_DIR = DataStorage:getHistoryDir() | |||
local DOCSETTINGS_DIR = DataStorage:getDocSettingsDir() | |||
local custom_metadata_filename = "/custom_metadata.lua" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads odd, as meaning that the file with be in the root folder /custom_metadata.lua
.
I guess you want to avoid an additional concatenation .. "/" .. custom_metadata_filename
, but still...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid an additional concatenation
Yes, that's the only purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still "reads" odd :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
frontend/docsettings.lua
Outdated
function DocSettings:removeSidecarDir(doc_path, sidecar_dir) | ||
if sidecar_dir == self:getSidecarDir(doc_path, "doc") then | ||
function DocSettings.removeSidecarDir(doc_path, sidecar_dir) | ||
if sidecar_dir == DocSettings:getSidecarDir(doc_path, "doc") then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There and below (and maybe elsewhere).
DocSettings:getSidecarDir
with a :
reads odd (and feels like a typo, and have me wondering what will happen if the DocSettings module table is used as the object self
.)
It should be either DocSettings.getSidecarDir()
with a .
when it's a pure function, and no self
object is needed.
Or self:getSidecarDir()
with a :
(as it was), if it looks better as a method and having an object self
, even if self
is not used.
I see that there, defining a function DocSettings.removeSidecarDir()
, you need to use the method DocSettings:getSidecarDir()
(probably because it's often used as a method), so it's indeed complicated.
Dunno how to make that clearer. Should if be made as a method DocSettings:removeSidecarDir()
because it uses other methods ?
Not sure what's the best/cleaner. @Frenzie @NiLuJe ?
(Or may be it's just me on an early morning seeing evil where there is not :/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started here and would like to continue transforming methods that do not require self
, to functions.
It is a code optimization, and is clearer to read.
In DocSettings only flush
, purge
and getCoverFile
require self
.
EDIT: and new flushCustomMetadata
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to use the method
DocSettings:getSidecarDir()
(probably because it's often used as a method)
Yes, I tried to avoid massive refactoring not related to custom metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and is clearer to read.
Disagree, for pretty much the reasons @poire-z pointed out.
I'd be fine with it if the whole module was pure, but this isn't the case here.
The only way I would see that viable is to fork those off to a dedicated LuaSettingsUtil module, but, again, I very strongly would suggest not bothering with that, especially if it involves a lot of code churn in existing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my mind using self the way it was is clearer too (in fact I'm not sure I didn't write it in the first place 😅).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
original_props = original_props or {} | ||
|
||
local props = {} | ||
for _i, prop_key in ipairs(BookInfo.props) do | ||
for _, prop_key in ipairs(BookInfo.props) do | ||
props[prop_key] = custom_props[prop_key] or original_props[prop_key] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still feeling setting display_title
should be the job of this customizeProps()
?
If it really is the place where we "extend" the plain book metadata (with pages, display_title and custom metadata), may be the its name should be changed to extendProps()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
-- but custom metadata exists, it has a copy of original doc_props | ||
if not book_props then | ||
local custom_metadata_file = DocSettings:getCustomMetadataFile(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I have not yet met the custom_metadata code while reading) but should custom_metadata really contain a copy of the orignal book_props, even if not modified ?
I would think it should contain only key/value of modified props.
edit: ok, seems you save both original doc_props and custom ones (see my other comment below).
-- Description may (often in EPUB, but not always) or may not (rarely | ||
-- in PDF) be HTML. | ||
description = util.htmlToPlainTextIfHtml(description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Was a bit sad that you removed my wildlife observation notes. But it is duplicated elsewhere, so not yet lost :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that, but there is another one:
-- Description may (often in EPUB, but not always) or may not (rarely in PDF) be HTML |
function BookInfo:showCustomEditDialog(file, book_props, metadata_updated_caller_callback, prop_key) | ||
local input_dialog | ||
input_dialog = InputDialog:new{ | ||
title = _("Edit book property: ") .. self.prop_text[prop_key]:sub(1, -2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_("Title:"),
when translated in French (haven't checked) may be _("Titre :")
with a space or thin-space before the :
.
I guess no issue if there's a trailing space in the text of the title you make for that widget, but dunno about other languages and how they would translate these (and if we should include the :
in the translatable strings or not (and have the code append it, but then French won't get that space).
@Frenzie : thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to me like it should be Edit book property: %1
instead of trying to figure out how to concatenate things, but iff template isn't appropriate for some reason the space should be concatenated without bothering the translator with it, as in Edit book property:
(colon at the end, no space at the end).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment was more about your %1
, from https://github.com/koreader/koreader/pull/10861/files#diff-10106ca66f5be0b0a2554fc344220689d85fa930768116d5650e655c558f465bR32
the list of the keys of the Book info KVPage, which includes their :
, and is reused there to make the title "Edit this property", without the there uneeded :
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, there's a good chance that's being too clever yeah, although your French example is probably unproblematic (a tiny bit of extra space). But if Chinese uses some utf8 full width colon for example does it still work out...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (replace ":" to "").
if original_prop and prop_key == "description" then | ||
original_prop = util.htmlToPlainTextIfHtml(original_prop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if editing Description, and it was HTML, we'll start editing the TEXT version of it?
I guess that's ok and the most sane, to avoid getting bad/unbalanced HTML in the custom Description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, currently BookInfo:showCustomEditDialog()
takes unstripped html description.
Should be fixed.
I see that we do not use original HTML'ed description anywhere.
Maybe clean it at the source, in Document:getProps()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we do not use original HTML'ed description anywhere.
Maybe clean it at the source, inDocument:getProps()
?
My preference in general is to save the orignal stuff as it is, original :)
If we later fix/tweak the cleaning code, it will apply immediately, without the need to refresh book metadata.
And maybe one day we'll want to display it as HTML (I think there was an issue about it - the resulting text being bad, that we solved another way).
But then I don't know how this plays with "custom description" :/ I guess the custom description should be plain text - dunno if where the htmlToPlainText stuff happens is too late to know about that.
original_prop = self.custom_doc_settings:readSetting("doc_props")[prop_key] | ||
custom_prop = self.custom_doc_settings:readSetting("custom_props")[prop_key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are both the original doc_props and the customized (only those modified?) in the custom_metadata.lua
?
Can you paste some sample of this custom_metadata.lua content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- we can read Lua syntax here!
return {
["custom_props"] = {
["authors"] = "Dariusz Terefenko",
["series"] = "Jazz",
["series_index"] = 3,
},
["doc_props"] = {
["authors"] = "Terefenko, Dariusz;",
["language"] = "En",
["pages"] = 824,
["title"] = "Jazz Theory",
},
}
Yes, might looks better. |
@@ -270,7 +269,7 @@ function BookInfo.getDocProps(file, book_props, no_open_document, no_customize) | |||
end | |||
end | |||
|
|||
return no_customize and (book_props or {}) or BookInfo.customizeProps(book_props, file) | |||
return no_customize and (book_props or {}) or BookInfo.extendProps(book_props, file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess no_customize
could be renamed to not_extended
or plain
or raw
or something else like that.
Good :) |
Eventually, it never existed. |
Some issue with this and the Reading statistics. |
Allows me to fix an old pet-peeve of mine re: the terrible variable names used in there ;o).
I thought the stats were based on some kind of md5 and/or file location, but I guess that's the sync? |
Looks like it is the 3 items |
Yes, agreed on not using the path. Using the title and authors seems a bit redundant given the md5. |
Indeed :) |
Allows me to fix an old pet-peeve of mine re: the terrible variable names used in there ;o).
Looks like that in customization, I can't "empty" a field (to remove trash, ie. from keywords, if we later have "browse by metadata/keyword"). |
I thought about that when coded the input dialog. |
It also cannot be "" because there are some checks that replace it with "N/A". |
Long-press on a property in the Book information window to customize it.
custom_props
and originaldoc_props
are saved tocustom_metadata.lua
in sdr folder.Maybe it's better to reorder the items, to put non-prop "Pages" to the end, closer to other numbers.
This change is