How to use the icloudpd.string_helpers.truncate_middle function in icloudpd

To help you get started, we’ve selected a few icloudpd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / tests / test_string_helpers.py View on Github external
def test_truncate_middle(self):
        assert truncate_middle("test_filename.jpg", 50) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 17) == "test_filename.jpg"
        assert truncate_middle("test_filename.jpg", 16) == "test_f...me.jpg"
        assert truncate_middle("test_filename.jpg", 10) == "tes...jpg"
        assert truncate_middle("test_filename.jpg", 5) == "t...g"
        assert truncate_middle("test_filename.jpg", 4) == "...g"
        assert truncate_middle("test_filename.jpg", 3) == "..."
        assert truncate_middle("test_filename.jpg", 2) == ".."
        assert truncate_middle("test_filename.jpg", 1) == "."
        assert truncate_middle("test_filename.jpg", 0) == ""
        with self.assertRaises(ValueError):
            truncate_middle("test_filename.jpg", -1)
github ndbroadbent / icloud_photos_downloader / icloudpd / base.py View on Github external
file_exists = os.path.isfile(download_path)
            if not file_exists and download_size == "original":
                # Deprecation - We used to download files like IMG_1234-original.jpg,
                # so we need to check for these.
                # Now we match the behavior of iCloud for Windows: IMG_1234.jpg
                original_download_path = ("-%s." % size).join(
                    download_path.rsplit(".", 1)
                )
                file_exists = os.path.isfile(original_download_path)

            if file_exists:
                if until_found is not None:
                    consecutive_files_found += 1
                logger.set_tqdm_description(
                    "%s already exists." % truncate_middle(download_path, 96)
                )
            else:
                if until_found is not None:
                    consecutive_files_found = 0

                if only_print_filenames:
                    print(download_path)
                else:
                    truncated_path = truncate_middle(download_path, 96)
                    logger.set_tqdm_description(
                        "Downloading %s" %
                        truncated_path)

                    download_result = download.download_media(
                        icloud, photo, download_path, download_size
                    )
github ndbroadbent / icloud_photos_downloader / icloudpd / base.py View on Github external
version = photo.versions[lp_size]
                    filename = version["filename"]
                    if live_photo_size != "original":
                        # Add size to filename if not original
                        filename = filename.replace(
                            ".MOV", "-%s.MOV" %
                            live_photo_size)
                    lp_download_path = os.path.join(download_dir, filename)

                    if only_print_filenames:
                        print(lp_download_path)
                    else:
                        if os.path.isfile(lp_download_path):
                            logger.set_tqdm_description(
                                "%s already exists."
                                % truncate_middle(lp_download_path, 96)
                            )
                            break

                        truncated_path = truncate_middle(lp_download_path, 96)
                        logger.set_tqdm_description(
                            "Downloading %s" % truncated_path)
                        download.download_media(
                            icloud, photo, lp_download_path, lp_size
                        )

            break

        if until_found is not None and consecutive_files_found >= until_found:
            logger.tqdm_write(
                "Found %d consecutive previously downloaded photos. Exiting"
                % until_found
github ndbroadbent / icloud_photos_downloader / icloudpd / base.py View on Github external
file_exists = os.path.isfile(original_download_path)

            if file_exists:
                if until_found is not None:
                    consecutive_files_found += 1
                logger.set_tqdm_description(
                    "%s already exists." % truncate_middle(download_path, 96)
                )
            else:
                if until_found is not None:
                    consecutive_files_found = 0

                if only_print_filenames:
                    print(download_path)
                else:
                    truncated_path = truncate_middle(download_path, 96)
                    logger.set_tqdm_description(
                        "Downloading %s" %
                        truncated_path)

                    download_result = download.download_media(
                        icloud, photo, download_path, download_size
                    )

                    if download_result and set_exif_datetime:
                        if photo.filename.lower().endswith((".jpg", ".jpeg")):
                            if not exif_datetime.get_photo_exif(download_path):
                                # %Y:%m:%d looks wrong but it's the correct format
                                date_str = created_date.strftime(
                                    "%Y:%m:%d %H:%M:%S")
                                logger.debug(
                                    "Setting EXIF timestamp for %s: %s",