From d1791e72e2e1442033cad2ad7ef1dd183562ddec Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 20 Aug 2024 20:42:26 -0300 Subject: Initial import --- export-koreader-note | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 export-koreader-note (limited to 'export-koreader-note') diff --git a/export-koreader-note b/export-koreader-note new file mode 100755 index 0000000..ae2e0ef --- /dev/null +++ b/export-koreader-note @@ -0,0 +1,46 @@ +#!/usr/bin/env lua +-- +-- Convert koreader metadata to markdown. +-- + +-- Sort by page number +function compare(a, b) + return a.page < b.page +end + +-- Check if a file exists +-- Thanks https://stackoverflow.com/questions/4990990/check-if-a-file-exists-with-lua#4991602 +function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end +end + +-- Get filename +file = arg[1] + +-- Usage +if file == nil then + print('usage: ' .. arg[0] .. ' ') + os.exit(1) +else + if not file_exists(file) then + print('file not found: ' .. file) + os.exit(1) + end +end + +-- Load metadata +content = assert(loadfile(file)) +data = content() +bookmarks = data.bookmarks + +-- Sort +table.sort(bookmarks, compare) + +-- Iterate over bookmarks +for key, item in ipairs(bookmarks) do + print('Page ' .. item.page .. ':') + print('') + print('> ' .. item.notes) + print('') +end -- cgit v1.2.3