Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #329 from BriceSchaffner/feature-configurable-path
Browse files Browse the repository at this point in the history
Added configurable album path formatting
  • Loading branch information
gilesknap authored Apr 23, 2022
2 parents 5102d72 + d406f50 commit 9f84f91
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
14 changes: 9 additions & 5 deletions gphotos/GoogleAlbumsSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(
self._omit_album_date = settings.omit_album_date
self._use_hardlinks = settings.use_hardlinks
self._ntfs_override = settings.ntfs_override
self.month_format = settings.month_format
self.path_format = settings.path_format

@classmethod
def make_search_parameters(cls, album_id: str, page_token: str = None) -> Dict:
Expand Down Expand Up @@ -197,7 +199,7 @@ def index_albums_type(
self.album_regex, album.orig_name, re.I
):
log.debug(
"Skipping Album: %s, photos: %d "
"Skipping Album: %s, photos: %d "
"(does not match --album-regex)",
album.filename,
album.size,
Expand Down Expand Up @@ -244,12 +246,14 @@ def album_folder_name(
else:
d = end_date
year = Utils.safe_str_time(d, "%Y")
month = Utils.safe_str_time(d, "%m%d")
month = Utils.safe_str_time(d, self.month_format or "%m%d")

if self._use_flat_path:
rel_path = "{0}-{1} {2}".format(year, month, album_name)
fmt = self.path_format or "{0}-{1} {2}"
rel_path = fmt.format(year, month, album_name)
else:
rel_path = Path(year) / "{0} {1}".format(month, album_name)
fmt = self.path_format or "{0} {1}"
rel_path = Path(year) / fmt.format(month, album_name)

link_folder: Path = self._links_root / rel_path
return link_folder
Expand Down Expand Up @@ -301,7 +305,7 @@ 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)
link_filename = link_filename[:get_check().max_filename]
link_filename = link_filename[: get_check().max_filename]
link_file = link_folder / link_filename
# incredibly, pathlib.Path.relative_to cannot handle
# '../' in a relative path !!! reverting to os.path
Expand Down
28 changes: 25 additions & 3 deletions gphotos/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def __init__(self):
album_group.add_argument(
"--album-regex",
action="store",
metavar='REGEX',
metavar="REGEX",
help="""only synchronize albums that match regular expression.
regex is case insensitive and unanchored. e.g. to select two albums:
"^(a full album name|another full name)$" """
"^(a full album name|another full name)$" """,
)
parser.add_argument(
"--log-level",
Expand Down Expand Up @@ -259,6 +259,26 @@ def __init__(self):
help="Declare that the target filesystem is ntfs (or ntfs like)."
"This overrides the automatic detection.",
)
parser.add_argument(
"--month-format",
action="store",
metavar="FMT",
help="Configure the month/day formatting for the album folder/file "
"path (default: %m%d).",
default="%m%d",
)
parser.add_argument(
"--path-format",
action="store",
metavar="FMT",
help="Configure the formatting for the album folder/file path. The "
"formatting can include up to 2 positionals arguments; `month` and "
"`album_name`. The default value is `{0} {1}`."
"When used with --use-flat-path option, it can include up to 3 "
"positionals arguments; `year`, `month` and `album_name`. In this case "
"the default value is `{0}-{1} {2}`",
default=None,
)
parser.add_help = True

def setup(self, args: Namespace, db_path: Path):
Expand Down Expand Up @@ -314,7 +334,9 @@ def setup(self, args: Namespace, db_path: Path):
omit_album_date=args.omit_album_date,
use_hardlinks=args.use_hardlinks,
progress=args.progress,
ntfs_override=args.ntfs
ntfs_override=args.ntfs,
month_format=args.month_format,
path_format=args.path_format,
)

self.google_photos_client = RestClient(photos_api_url, self.auth.session)
Expand Down
3 changes: 3 additions & 0 deletions gphotos/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ class Settings:
progress: bool

ntfs_override: bool

month_format: str
path_format: str
2 changes: 1 addition & 1 deletion gphotos/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def authorize(self):
authorization_url, _ = self.session.authorization_url(
authorization_base_url, access_type="offline", prompt="select_account"
)
print(f"Please go here and authorize, {authorization_url}\n", )
print(f"Please go here and authorize, {authorization_url}\n",)

# Get the authorization verifier code from the callback url
response_code = input("Paste the response token here:\n")
Expand Down

0 comments on commit 9f84f91

Please sign in to comment.