bingryan / obsidian-ibook-plugin

export mac ibook annotations/hightlights to obsidian vault
MIT License
69 stars 2 forks source link

Some additional fields #53

Closed jun6lee closed 11 months ago

jun6lee commented 1 year ago

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


3) 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 commented 1 year ago

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 commented 1 year ago

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

jun6lee commented 1 year ago

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 commented 12 months ago

@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 commented 12 months ago

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

jun6lee commented 12 months ago

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

bingryan commented 12 months ago

@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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

@jun6lee update this plugin and try again. :)

last_opened: {{dateFormat library.ZLASTOPENDATE "YYYY/MM/DDTHH:mm:ss" }}
jun6lee commented 11 months ago

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" }}