ndbeals / keep-exporter

A command line utility to export Google Keep notes to markdown.
https://pypi.org/project/keep-exporter/
BSD 3-Clause "New" or "Revised" License
96 stars 1 forks source link

Download images and reference them in the Markdown output #6

Closed mbafford closed 3 years ago

mbafford commented 3 years ago

See this commit for a first rough pass at this: https://github.com/mbafford/keep-exporter/commit/43447684fd7265866bfe5bd6cd5e386594cccd3d

The images API is undocumented, but I was able to piece together how to get the image URL from looking at the image URL in Google Keep and the gkeepapi code. This commit works for all of my notes as far as I can tell, but I'm sure it fails on some other edge case.

The URL generated by the API is simply:

https://keep.google.com/u/0/media/v2/{note.server_id}/{image.server_id}

when Google Keep references the image, it also adds these parameters:

?accept=image/gif,image/jpeg,image/jpg,image/png,image/webp,audio/aac&sz=4032

There's interesting metadata available in:

note.images[0].blob, e.g.:

'kind':'notes#blob'
'type':'IMAGE'
'mimetype':'image/jpeg'
'width':3024
'height':4032
'byte_size':3162748
'extracted_text':'味全\nwei-chuart\nが\n薺菜態 蝦 .\nChinese Spinach[...]'
'extraction_status':'VSS_SUCCEEDED'

No original image filename that I can find.

TODO

mbafford commented 3 years ago

I've tested an verified that you can use exactly the same code to download drawings, at least static representations of them - e.g., change the for loop to:

for image in note.images + note.drawings:

This will download a PNG version of the image (named jpg by this code, but most programs don't really care).

My guess is there's a vector or more complicated format available as well, since you can click on the drawing in Keep and continue editing it. I only have one drawing in my keep library that I created for testing.

ndbeals commented 3 years ago

Merged in #5. Also commented on the pull request but I'll put it here too. Your work has been merged, I finished your todo,

I'm still undecided about whether (and where) to save the OCR text, suggestions are welcome.