jya-dev / supernote-tool

Unofficial python tool for Supernote
Apache License 2.0
237 stars 26 forks source link

feature: Combine multiple notes into one? #11

Open codemac opened 2 years ago

codemac commented 2 years ago

This tool has been a life saver for my own personal workflow. Thank you for creating this!

Because you have a parser, I was curious if there would be a way to merely append two .note files into one. I realize this is different than parsing, in fact the opposite of generating.

Any thoughts on what this would take?

jya-dev commented 2 years ago

Technically it is possible, but not simple. The note file consists of multiple blocks and the blocks are referred from other blocks by byte offset value. When combining multiple note files, we need to adjust offset values and merge metadata carefully to ensure consistency because the position of the blocks change.

Your suggestion looks interesting. It may take some time, but I'll consider file combining method.

enomis123 commented 2 years ago

Merging ( and splitting) notes would be SO cool and helpful for my workflow.

jya-dev commented 2 years ago

I have started implementing the merging feature and now it works with some restrictions. You can try it with the latest commit (f687b4f41e6b4d0dda066dea51c9eafef5ca48f1).

Important Notices: This is an experimental feature, so output file may be corrupted. Backup your input files before trying the feature to prevent data loss.

Usage:

$ supernote-tool merge input1.note input2.note output.note

This command generates output.note which combines the pages of input1.note and input2.note. The cover image of output.note uses the one of input1.note.

Restrictions:

enomis123 commented 2 years ago

Nice - thank you very much !!! My first tests came out perfectly fine: I merged two files ( 70 mb, 40mb) totalling in 180 pages and it worked great. I have not checked if titles are keywords are fine. What is next on your list ? ( I have some ideas but I don't want to stress you :) )

jya-dev commented 2 years ago

Hi, thank you for testing. Titles and Keywords has been also supported.

I plan to add bellows:

  1. a binary format integrity check before outputting note binary file
  2. mutual conversion between Notebook object and binary format
  3. APIs to edit Notebook object easily (insert/remove pages, etc.)
  4. refactoring the merge feature code with new APIs
enomis123 commented 2 years ago

Very cool ( especially item 3). How about merging more than 2 notebooks ( eg merging all files in a specific directory ) ?

jya-dev commented 2 years ago

OK, I add the feature that merging more than 2 notebooks to my plan list. Basically It is not difficult because we should be able to achieve the feature by repeating the merge function.

codemac commented 2 years ago

Thank you so much for this feature! Trying it out now.

Really makes my workflow so much better where I write notes into new files, and then add them into .note files when I've processed them.

jya-dev commented 2 years ago

Now I committed the feature that merging more than 2 notebooks (d9c6839678d703090990c7de1cccccb955ed7e96). 'merge' sub-command accepts any number of input file name arguments.

Examples:

$ supernote-tool merge input1.note input2.note input3.note output.note

You can easily specify many input files in a directory using shell's wildcards.

$ ls mynote/
20220306_164410.note  20220306_164428.note  20220306_164458.note  20220306_164504.note
$ supernote-tool merge mynote/*.note merged-mynote.note
mateo0023 commented 4 months ago

It seems you forgot to add the newer .note versions in the supported files. Expected signature is noteSN_FILE_VER_20210010 whereas the latest file version is 20230015