Last active
February 17, 2022 05:51
-
-
Save djui/8bec1e3174d29f7ebb42 to your computer and use it in GitHub Desktop.
Simple iBooks book index export script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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