Skip to content

Instantly share code, notes, and snippets.

@djui
Last active February 17, 2022 05:51
Show Gist options
  • Select an option

  • Save djui/8bec1e3174d29f7ebb42 to your computer and use it in GitHub Desktop.

Select an option

Save djui/8bec1e3174d29f7ebb42 to your computer and use it in GitHub Desktop.
Simple iBooks book index export script
#!/usr/bin/env python3
import os
import plistlib
import sys
from datetime import datetime
def main(args):
books_path = '~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/Books.plist'
plist = plistlib.readPlist(os.path.expanduser(books_path))
for book in plist['Books']:
title = book.get('itemName')
author = book.get('artistName')
if not author and not title:
title, _ = book.get('BKDisplayName').split('.epub')
try:
mtime = os.path.getmtime(book.get('path'))
except:
epoche = 978307200 # 12:00am Jan 1, 2001 GMT
mtime = epoche + book.get('BKInsertionDate')
mtime = datetime.fromtimestamp(mtime)
print(mtime.strftime('%Y-%m-%d'), title, '-', author or '')
if __name__ == '__main__':
try:
sys.exit(main(sys.argv[1:]))
except KeyboardInterrupt:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment