Repair broken bookmarks to referenced files in Apple Photos

Overview

Repair Apple Photos Bookmarks

Work in progress to repair file location bookmarks in Apple Photos.

Background

Starting in macOS 10.15/Catalina, photos imported into the Apple Photos app and not copied into the library (e.g. referenced photos) are tied to a specific volume on a specific computer. If you move the photos to a different volume or computer, even with the same name, Photos will be unable to open the original files and will produce a "Missing file" dialog. This is caused because of macOS Sandbox security features and the fact that Photos now stores locations to photos using security-scoped file system bookmarks instead by path. This script will repair your photos library by updating the bookmarks.

This is a work in progress and it's a bit of hack. It requires a few manual steps to get it working (the script will prompt you).

How to use

pip install -r requirements.txt python3 repair_photos_bookmarks.py follow the prompts

Additional Information

For more information, see this discussion

Issues
  • Current implementation doesn't update ZINTERNALRESOURCE.ZFILESYSTEMVOLUME info

    Current implementation doesn't update ZINTERNALRESOURCE.ZFILESYSTEMVOLUME info

    Although the current implementation appears to work -- as in Photos is able to locate the photos after repairing bookmarks -- it does not update the volume info in ZINTERNALRESOURCES.ZFILESYSTEMVOLUME. ZINTERNALRESOURCES.ZFILESYSTEMBOOKMARK points to the now updated bookmark, which appears to be correct, but if the volume changed, the volume info in the ZFILESYSTEMVOLUME table pointed at by ZINTERNALRESOURCES.ZFILESYSTEMVOLUME will be incorrect.

    Should the script also add a new volume (if necessary) to ZFILESYSTEMVOLUME and update the pointer in ZINTERNALRESOURCES? Nothing appears to be broken but it does leave an inconsistency in the database.

    opened by RhetTbull 0
  • Allow remapping of old path to new path when updating bookmarks

    Allow remapping of old path to new path when updating bookmarks

    The current implementation uses CFURLCreateByResolvingBookmarkData which fails if the target file isn't present. This means Photos bookmarks cannot be migrated to a different path (unless copies of the target photos were present in both the old location and the new location). If the bookmark resolution is replaced with mac_alias calls, the URL could be extracted even if the target isn't present and then changed, according to some mapping, to the new location.

    Would still need a way to map old location to new location.

    The following python code shows how to extract the bookmark URL.

    """Extract file path from a CFURL bookmark without calling Objective C"""
    import os
    
    from mac_alias import Bookmark, kBookmarkPath
    
    
    def get_bookmark_path(bookmark_data: bytes) -> str:
        """Get the path from a CFURL file bookmark
        This works without calling CFURLCreateByResolvingBookmarkData
        which fails if the target file does not exist
        """
        try:
            bookmark = Bookmark.from_bytes(bookmark_data)
        except Exception as e:
            raise ValueError(f"Invalid bookmark: {e}")
        path_components = bookmark.get(kBookmarkPath, None)
        if not path_components:
            return None
        return "/" + os.path.join(*path_components)
    
    
    if __name__ == "__main__":
        import sys
    
        bookmark_file = sys.argv[1]
        with open(bookmark_file, "rb") as f:
            bookmark_data = f.read()
        bookmark_path = get_bookmark_path(bookmark_data)
        print(f"{bookmark_path=}")
    
    opened by RhetTbull 2
Owner
Rhet Turnbull
I tinker with various things. Here are a few of my projects.
Rhet Turnbull
Gallery written in Python to manage your photos

GalleryMan Gallery written in Python to manage your photos Installation

Asian Cat 16 Nov 9, 2021
Fix datetime EXIF data in photos downloaded from Google Takeout

fix-google-takeout Warning Use at your own risk. Backup your photos. Overview Google takeout for photos

Mayank Mandava 13 Aug 21, 2021
A tool to maintain an archive/mirror of your Google Photos library for backup purposes.

Google Photos Archiver Updated Instructions 8/9/2021 Version 2.0.6 Instructions: Download the script (exe or python script listed below) Follow the in

Nick Dawson 63 Nov 26, 2021
Convert photos to paintings with python

Convert-photos-to-paintings Before the changes After the changes Before the changes After the changes This code is written in the Python programming l

Amir Hussein Sharifnezhad 3 Nov 7, 2021
Program designed to mass edit and watermark all photos in a directory

Photographer-All-In-One This is a program designed for photographers to mass edit or watermark photos (.jpg || .png) You can run this program from any

Brad Martin 2 Nov 23, 2021
Find target hash collisions for Apple's NeuralHash perceptual hash function.💣

neural-hash-collider Find target hash collisions for Apple's NeuralHash perceptual hash function. For example, starting from a picture of this cat, we

Anish Athalye 592 Nov 25, 2021
Simple AI app that is guessing color of apple in picture

Apple Color Determinant Application that is guessing color of apple from image Install Pillow, sklearn and numpy, using command for your package manag

Gleb Nikitin 1 Oct 25, 2021
Viewer for NFO files

NFO Viewer NFO Viewer is a simple viewer for NFO files, which are "ASCII" art in the CP437 codepage. The advantages of using NFO Viewer instead of a t

Osmo Salomaa 99 Nov 15, 2021
An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C. Overview Her

Sy Brand 224 Oct 18, 2021
Paper backup of files using QR codes

Generate paper backups for Linux. Currently command-linux Linux only. Takes any file, and outputs a "paper backup": a printable black-and-white pdf fu

Zachary Vance 16 Oct 21, 2021
Easy to use Python module to extract Exif metadata from digital image files.

Easy to use Python module to extract Exif metadata from digital image files.

ianaré sévi 637 Nov 30, 2021
HTML2Image is a lightweight Python package that acts as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

null 95 Nov 18, 2021
Small wrapper around 3dmol.js and html2canvas for creating self-contained HTML files that display a 3D molecular representation.

Description Small wrapper around 3dmol.js and html2canvas for creating self-contained HTML files that display a 3D molecular representation. Double cl

David Meijer 1 Dec 1, 2021
Apple Store Stock Notifier monitors the availability of selected Apple devices in selected Apple stores, and sends you a notification when devices are available!

Apple Store Stock Notifier This software will immediately send you a notification via Telegram when one of your coveted Apple Devices is available in

Floris-Jan Willemsen 15 Nov 19, 2021
Broken Link Finder is a Burp Extension to detect broken links for a passive scanning domains and links.

Broken Link Finder Broken Link Finder is a Burp Extension to detect broken links for a passive scanning domains and links. Inspired by InitRoot's link

Red Section 10 Sep 11, 2021
This is an app that allows users to upload photos and display and store the photos in a file until the user deletes them.

Qt Photo App This is an app that allows users to upload photos and display and store the photos in a file until the user deletes them. Setup python3 -

Kathy Yang 2 Oct 17, 2021
Automatically move or copy files based on metadata associated with the files. For example, file your photos based on EXIF metadata or use MP3 tags to file your music files.

Automatically move or copy files based on metadata associated with the files. For example, file your photos based on EXIF metadata or use MP3 tags to file your music files.

Rhet Turnbull 2 Nov 25, 2021
Download Apple Music Cover Artwork in the best Quality by providing an Apple Music Link. It downloads the jpg, png and webp version since they often differ from another.

amogus.py - Version 0.0.5 amogus - Apple Music Hi-Res Artwork Fetcher this is my first real python tool so sorry if its bad amogus is a Python script

reaper 13 Dec 2, 2021
pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative markdown file as input

pystitcher pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative input in the form of a mark

Nemo 37 Aug 23, 2021
Better firefox bookmarks script for rofi

rofi-bookmarks Small python script to open firefox bookmarks with rofi. Features Icons! Only show bookmarks in a specified bookmark folder Show entire

null 19 Oct 12, 2021
🗃 Open source self-hosted web archiving. Takes URLs/browser history/bookmarks/Pocket/Pinboard/etc., saves HTML, JS, PDFs, media, and more...

ArchiveBox Open-source self-hosted web archiving. ▶️ Quickstart | Demo | Github | Documentation | Info & Motivation | Community | Roadmap "Your own pe

ArchiveBox 12.3k Nov 24, 2021
Allows you to easily share bookmarks from Raindrop.io in Telegram chats.

Allows you to easily share bookmarks from Raindrop.io in Telegram chats. As well as save links/photos/longreads from Telegram right into Raindrop.io. Join us, we have a nice 'reader mode' :)

Oleh 18 Oct 13, 2021
A Fast Broken Link Hijacker Tool written in Python

Broken Link Hijacker BrokenLinkHijacker(BLH) is a Fast Broken Link Hijacker Tool written in Python.

Mayank Pandey 56 Nov 23, 2021
Data Recovery from your broken Android phone

Broken Phone Recovery a guide how to backup data from your locked android phone if you broke your screen (and more) you can skip some steps depending

v1nc 18 Nov 13, 2021
[ICML 2021] Break-It-Fix-It: Learning to Repair Programs from Unlabeled Data

Break-It-Fix-It: Learning to Repair Programs from Unlabeled Data This repo provides the source code & data of our paper: Break-It-Fix-It: Unsupervised

Michihiro Yasunaga 44 Nov 13, 2021
Super Mario Kart November 1991 Prototype Repair by MrL314

Super Mario Kart November 1991 Prototype Repair by MrL314

MrL314 42 Nov 2, 2021
Python module to work with Magneto Database directly without using broken Magento 2 core

Python module to work with Magneto Database directly without using broken Magento 2 core

Egor Shitikov 3 Dec 1, 2021
Tiny command-line utility for mapping broken keys to other positions.

brokenkey Tiny command-line utility for mapping broken keys to other positions. Installation Clone this repository using git: git clone https://github

null 0 Oct 4, 2021