From a9fd1b6876666616dd607dbd9960a48774dd749e Mon Sep 17 00:00:00 2001 From: Rui NARCISO Date: Mon, 3 Jun 2024 15:41:41 +0200 Subject: [PATCH] added an option "no-album-sorting" to remove the prefixes added to the photos inside an album so that the names are identical to the original photos names --- pyproject.toml | 2 ++ src/gphotos_sync/GoogleAlbumsSync.py | 7 ++++++- src/gphotos_sync/Settings.py | 1 + src/gphotos_sync/__main__.py | 6 ++++++ tests/test_units/test_units.py | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 978c71a1..46843b05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,6 +120,8 @@ commands = [tool.ruff] src = ["src", "tests"] line-length = 88 + +[tool.ruff.lint] select = [ "C4", # flake8-comprehensions - https://beta.ruff.rs/docs/rules/#flake8-comprehensions-c4 "E", # pycodestyle errors - https://beta.ruff.rs/docs/rules/#error-e diff --git a/src/gphotos_sync/GoogleAlbumsSync.py b/src/gphotos_sync/GoogleAlbumsSync.py index ef6e6edc..847802cf 100644 --- a/src/gphotos_sync/GoogleAlbumsSync.py +++ b/src/gphotos_sync/GoogleAlbumsSync.py @@ -66,6 +66,7 @@ def __init__( self._ntfs_override = settings.ntfs_override self.month_format = settings.month_format self.path_format = settings.path_format + self._no_album_sorting = settings.no_album_sorting @classmethod def make_search_parameters( @@ -309,7 +310,11 @@ def create_album_content_links(self): link_folder: Path = self.album_folder_name(album_name, start_date, end_date) - link_filename = "{:04d}_{}".format(album_item, file_name) + if self._no_album_sorting: + link_filename = "{}".format(file_name) + else: + link_filename = "{:04d}_{}".format(album_item, file_name) + link_filename = link_filename[: get_check().max_filename] link_file = link_folder / link_filename # incredibly, pathlib.Path.relative_to cannot handle diff --git a/src/gphotos_sync/Settings.py b/src/gphotos_sync/Settings.py index aee40d6a..4a5238f4 100644 --- a/src/gphotos_sync/Settings.py +++ b/src/gphotos_sync/Settings.py @@ -26,6 +26,7 @@ class Settings: album_index: bool omit_album_date: bool album_invert: bool + no_album_sorting: bool album: str album_regex: str shared_albums: bool diff --git a/src/gphotos_sync/__main__.py b/src/gphotos_sync/__main__.py index 3d5ffe34..f25cc729 100644 --- a/src/gphotos_sync/__main__.py +++ b/src/gphotos_sync/__main__.py @@ -147,6 +147,11 @@ def __init__(self): help="Make the album date the same as its earliest " "photo. The default is its last photo", ) + parser.add_argument( + "--no-album-sorting", + action="store_true", + help="Remove prefix in photo filename inside the album folders", + ) parser.add_argument( "--start-date", help="Set the earliest date of files to sync" "format YYYY-MM-DD", @@ -380,6 +385,7 @@ def setup(self, args: Namespace, db_path: Path): path_format=args.path_format, image_timeout=args.image_timeout, video_timeout=args.video_timeout, + no_album_sorting=args.no_album_sorting, ) self.google_photos_client = RestClient( diff --git a/tests/test_units/test_units.py b/tests/test_units/test_units.py index a3819382..dc530d8a 100644 --- a/tests/test_units/test_units.py +++ b/tests/test_units/test_units.py @@ -185,4 +185,4 @@ def test_fs_overrides(self): ) s.gp.fs_checks(s.root, s.parsed_args) self.assertTrue(get_check().is_linux) - self.assertEqual(get_check().max_filename, 255) + self.assertTrue(get_check().max_filename >= 242)