Skip to content
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

Some additional fields #53

Closed
jun6lee opened this issue Jul 14, 2023 · 11 comments
Closed

Some additional fields #53

jun6lee opened this issue Jul 14, 2023 · 11 comments

Comments

@jun6lee
Copy link

jun6lee commented Jul 14, 2023

Very cool plugin, adding some notes on improving, if it's possible.

Is there a way of getting these details in too?

  1. & 2) - Under the book title and language, I'd like to see these two things:
    last_highlight: {{latest instance of ZANNOTATIONMODIFICATIONDATE}}
    highlight_count: {{number of records per book}}

If you could have a look


  1. Add on each highlight:
    Highlighted: {{ZANNOTATIONMODIFICATIONDATE}}

You are pulling this, but it will needs some logic to convert it to readable data.
Looking into it, will report back.

My Template:

---
book: {{library.ZSORTTITLE}}
author: {{library.ZAUTHOR}}
language: {{library.ZLANGUAGE}}
last_opened: {{library.ZLASTOPENDATE}}
last_highlight: {{latest instance of ZANNOTATIONMODIFICATIONDATE}} -- WANT
highlight_count: {{number of records per book}} -- WANT
tags:
- highlights/iBooks
---
# 📔 {{library.ZSORTTITLE}}
---
{{#if library.ZBOOKDESCRIPTION}}

# 🧾 Description
---
	{{{library.ZBOOKDESCRIPTION}}}
{{/if}}

# 🔍 Highlights
---

{{#group annotation by="ZFUTUREPROOFING5"}}
#### 📚{{value}}
---

{{#each items}}
{{#if ZANNOTATIONSELECTEDTEXT}}
{{#is ZANNOTATIONSTYLE 5}}
- 🎯 <mark style="background: #C4B3D9;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 4}}
- 🎯 <mark style="background: #E6A5AB;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 3}}
- 🎯 <mark style="background: #EDD570;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 2}}
- 🎯 <mark style="background: #A8BADE;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 1}}
- 🎯 <mark style="background: #B0D17F;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 0}}
- 🎯 <mark style="background: #FFD9B3;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{/if}}
{{#if ZANNOTATIONNOTE}}
        - ✍️ {{ZANNOTATIONNOTE}}
{{/if}}
<sub>Last Highlighted: {{ZANNOTATIONMODIFICATIONDATE}}</sub>
---
{{/each}}
{{/group}}
Source::  [Apple Books Link](ibooks://assetid/{{library.ZASSETID}})
@jun6lee
Copy link
Author

jun6lee commented Jul 14, 2023

const APPLE_EPOCH_START = new Date("2001-01-01").getTime();
--- been able to dig out that Apple does a weird thing with EPOCH timestamps, so start with this

and feed the ZANNOTATIONMODIFICATIONDATE or ZANNOTATIONCREATIONDATE something like this:

      modifiedAt: convertAppleTime(r.modifiedAt),
      createdAt: convertAppleTime(r.createdAt),

where we covert as follows:

function convertAppleTime(appleTime) {
  return new Date(APPLE_EPOCH_START + appleTime * 1000).getTime();
}

@bingryan
Copy link
Owner

@jun6lee sure, you can DIY you template, please visit: https://github.com/bingryan/obsidian-ibook-plugin#for-user-defined-templates

@jun6lee
Copy link
Author

jun6lee commented Jul 15, 2023

I'm not familiar enough with TypeScript, but what I'm after are two additional fields:

I have done No.3 in my template. -- but the convertAppleTime logic I don't know the syntax to achieve in ts.


last_highlight: -- which I would like to be the latest instance of ZANNOTATIONMODIFICATIONDATE
[0] of sorted array, I guess

and

highlight_count: which would be an integer of how many highlights are imported
it'd need a count of how many times the {{#if ZANNOTATIONSELECTEDTEXT}} gets a result.

@bingryan
Copy link
Owner

@jun6lee metadata

---
book: {{library.ZSORTTITLE}}
author: {{library.ZAUTHOR}}
language: {{library.ZLANGUAGE}}
last_opened: {{date ZLASTOPENDATE "YYYY/MM/DDTHH:mm:ss" }}
last_highlight: {{date ZANNOTATIONMODIFICATIONDATE "YYYY/MM/DDTHH:mm:ss "}}
tags:
- highlights/iBooks
---


# 📔 Book: {{library.ZSORTTITLE}}

**Author**:: {{library.ZAUTHOR}}

**LANGUAGE**:: {{library.ZLANGUAGE}}

**Book Link**:: [Apple Books Link](ibooks://assetid/{{library.ZASSETID}})

{{#if library.ZBOOKDESCRIPTION}}
---
# 🧾 Description
	{{{library.ZBOOKDESCRIPTION}}}
{{/if}}

---
# 🔍 How I Discovered IT

{{#group annotation by="ZFUTUREPROOFING5"}}
- 📚{{value}}
	{{#each items}}
	{{#if ZANNOTATIONSELECTEDTEXT}}
	{{#is ZANNOTATIONSTYLE 5}}
	- 🎯 <mark style="background: #C4B3D9;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{#is ZANNOTATIONSTYLE 4}}
	- 🎯 <mark style="background: #E6A5AB;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{#is ZANNOTATIONSTYLE 3}}
	- 🎯 <mark style="background: #EDD570;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{#is ZANNOTATIONSTYLE 2}}
	- 🎯 <mark style="background: #A8BADE;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{#is ZANNOTATIONSTYLE 1}}
	- 🎯 <mark style="background: #B0D17F;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{#is ZANNOTATIONSTYLE 0}}
	- 🎯 <mark style="background: #E65747;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
	{{/is}}
	{{/if}}
		{{#if ZANNOTATIONNOTE}}
		- ✍️{{ZANNOTATIONNOTE}}
		{{/if}}
	{{/each}}
{{/group}}

@jun6lee
Copy link
Author

jun6lee commented Jul 24, 2023

Oh, didn't know it's that simple.. works! Super!!!

@jun6lee jun6lee closed this as completed Jul 24, 2023
@jun6lee
Copy link
Author

jun6lee commented Jul 24, 2023

Actually, it fixed formatting, but the dates are wrong.

Last Highlighted: {{date annotation.ZANNOTATIONCREATIONDATE "YYYY/MM/DD HH:mm:ss "}}
always seems to reflect the time imported into obsidian rather than the time it was highlighted/modified

@jun6lee jun6lee reopened this Jul 24, 2023
@bingryan
Copy link
Owner

@jun6lee

I found that the time field in ibook is similar:

ZLASTOPENDATE: 703830839.572769
ZPURCHASEDATE: 695628940.302915
ZANNOTATIONCREATIONDATE: 610881340.480055
ZANNOTATIONMODIFICATIONDATE: 610881340.480137

703830839.572769 I do not understand what format is used to store time

@jun6lee
Copy link
Author

jun6lee commented Jul 28, 2023

It is Apple's Cocoas variation on EPOCH which starts from:
1 January 2001

Standard Epoch time starts from:
1 January 1970 00:00:00 UTC

For this reason need to add on 978307200 seconds somehow.
Refer: https://www.epochconverter.com/coredata

@bingryan
Copy link
Owner

It is Apple's Cocoas variation on EPOCH which starts from: 1 January 2001

Standard Epoch time starts from: 1 January 1970 00:00:00 UTC

For this reason need to add on 978307200 seconds somehow. Refer: https://www.epochconverter.com/coredata

@jun6lee nice job, very very very very useful information 🫡

@bingryan
Copy link
Owner

@jun6lee update this plugin and try again. :)

last_opened: {{dateFormat library.ZLASTOPENDATE "YYYY/MM/DDTHH:mm:ss" }}

@jun6lee
Copy link
Author

jun6lee commented Aug 4, 2023

Super. Does the trick.

{{dateFormat ZANNOTATIONMODIFICATIONDATE "YYYY/MM/DD HH:mm:ss" }}

also works...

Something out of your hands, but an Apple quirk I noticed was that if I highlight on my iPhone or iPad, the modification date will only update to when the update gets uploaded to iCloud and then re-downloaded on macOS.

Will have to live with that. Using below instead:

Highlighted: {{dateFormat ZANNOTATIONCREATIONDATE "YYYY/MM/DD HH:mm:ss" }}

@jun6lee jun6lee closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants