mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Exporter: XMNote support exporting read time and mark book source (#14144)
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local BD = require("ui/bidi")
|
||||
local DataStorage = require("datastorage")
|
||||
local DocSettings = require("docsettings")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local SQ3 = require("lua-ljsqlite3/init")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local datetime = require("datetime")
|
||||
local ffiUtil = require("ffi/util")
|
||||
local logger = require("logger")
|
||||
local util = require("ffi/util")
|
||||
local T = util.template
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
local T = ffiUtil.template
|
||||
|
||||
local db_location = DataStorage:getSettingsDir() .. "/statistics.sqlite3"
|
||||
|
||||
-- xmnote exporter
|
||||
local XMNoteExporter = require("base"):new {
|
||||
@@ -71,14 +77,78 @@ function XMNoteExporter:getMenuTable()
|
||||
}
|
||||
end
|
||||
|
||||
function XMNoteExporter:getBookReadingDurationsByDay(title, md5)
|
||||
if util.fileExists(db_location) then
|
||||
local conn = SQ3.open(db_location)
|
||||
local sql_query_book_id = [[SELECT id FROM book WHERE title = "%s" and md5 = "%s" LIMIT 1]]
|
||||
local sql_query_durations = [[
|
||||
SELECT date(start_time, 'unixepoch', 'localtime') AS date,
|
||||
max(page) AS last_page,
|
||||
sum(duration) AS total_duration,
|
||||
min(start_time) AS first_start_time
|
||||
FROM page_stat
|
||||
WHERE id_book = %d
|
||||
GROUP BY Date(start_time, 'unixepoch', 'localtime')
|
||||
ORDER BY date DESC;
|
||||
]]
|
||||
|
||||
local result_book_id = conn:exec(string.format(sql_query_book_id, title, md5))
|
||||
if not (result_book_id and result_book_id[1] and result_book_id[1][1]) then
|
||||
return {}
|
||||
end
|
||||
local book_id = tonumber(result_book_id[1][1])
|
||||
|
||||
local result_durations = conn:exec(string.format(sql_query_durations, book_id))
|
||||
conn:close()
|
||||
|
||||
if not result_durations then
|
||||
return {}
|
||||
end
|
||||
|
||||
local durations = {}
|
||||
for i = 1, #result_durations.date do
|
||||
local entry = {
|
||||
date = tonumber(result_durations[4][i]) * 1000,
|
||||
durationSeconds = tonumber(result_durations[3][i]),
|
||||
position = tonumber(result_durations[2][i]),
|
||||
}
|
||||
table.insert(durations, entry)
|
||||
end
|
||||
return durations
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
function XMNoteExporter:createRequestBody(booknotes)
|
||||
local doc_settings = DocSettings:open(booknotes.file)
|
||||
local summary = doc_settings:readSetting("summary") or {}
|
||||
local md5 = doc_settings:readSetting("partial_md5_checksum")
|
||||
|
||||
local reading_status_map = {
|
||||
reading = 2,
|
||||
complete = 3,
|
||||
abandoned = 5,
|
||||
}
|
||||
|
||||
local reading_status_changed_date
|
||||
if summary.modified and summary.modified ~= "" then
|
||||
reading_status_changed_date = datetime.stringToSeconds(summary.modified)
|
||||
else
|
||||
reading_status_changed_date = 0
|
||||
end
|
||||
|
||||
local book = {
|
||||
title = booknotes.title or "",
|
||||
author = booknotes.author or "",
|
||||
type = 1,
|
||||
locationUnit = 1,
|
||||
readingStatus = reading_status_map[summary.status] or reading_status_map.reading,
|
||||
readingStatusChangedDate = reading_status_changed_date,
|
||||
source = "KOReader"
|
||||
}
|
||||
local entries = {}
|
||||
|
||||
for _, chapter in ipairs(booknotes) do
|
||||
for _, clipping in ipairs(chapter) do
|
||||
local entry = {
|
||||
@@ -95,6 +165,7 @@ function XMNoteExporter:createRequestBody(booknotes)
|
||||
end
|
||||
end
|
||||
book.entries = entries
|
||||
book.fuzzyReadingDurations = self:getBookReadingDurationsByDay(book.title, md5)
|
||||
return book
|
||||
end
|
||||
|
||||
@@ -112,7 +183,6 @@ function XMNoteExporter:createHighlights(booknotes)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function XMNoteExporter:isReadyToExport()
|
||||
if self.settings.ip then return true end
|
||||
return false
|
||||
@@ -129,4 +199,3 @@ function XMNoteExporter:export(t)
|
||||
end
|
||||
|
||||
return XMNoteExporter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user