icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
6.92k stars 556 forks source link

Download fails when iCloud photo has a filename attribute with strange (empty?) value #935

Closed MicaelJacobsson closed 2 months ago

MicaelJacobsson commented 3 months ago

Overview

I have photos with a seemingly empty value as filename. I think it came from uploading photos to iCloud causing duplicates. When downloading my entire library each such photo cause an uncaught exception and terminates the download

Steps to Reproduce

Try to download an iCloud photo where the filename shown in the photo Details is empty

Expected Behavior

The filename of the downloaded file should be set to truncated fingerprint by the code below

# Some photos don't have a filename.
        # In that case, just use the truncated fingerprint (hash),
        # plus the correct extension.
        filename = re.sub('[^0-9a-zA-Z]', '_', self.id)[0:12]

Actual Behavior

There is an exception thrown from this piece of code just above:

            _filename = self._service.filename_cleaner(**base64.b64decode(
                fields['filenameEnc']['value']
            )**.decode('utf-8'))

Context

I added a try: except on line 613 in icloud_photos_downloader\src\pyicloud_ipd\services\photos.py around that entire first if-clause, and rebuilt. With that build I could download the entire library, and the file-names of the strange photos were set from the truncated hash.

AndreyNikiforov commented 3 months ago

Can you try to confirm what attributes are in the response from icloud, please? Is there really no "filenameEnc" and no "filename" attributes or they have some unsupported values? icloud allows uploading assets with duplicate filenames, so I do not expect it to be the cause.

AndreyNikiforov commented 2 months ago

@MicaelJacobsson v1.23.2 will dump content on which decoding is choking. Should be sufficient to use --dry-run for reproducing your issue. Please try and see what it brings.

AndreyNikiforov commented 2 months ago

I assume your issue is related to new plain text filename encoding introduced by Apple. Support for that encoding has been added in v1.23.4. You can test if new version fixes your issue with:

docker run --rm -it icloudpd/icloudpd:1.23.4 icloudpd -u your@email.address -d . --dry-run