Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option for file name capitalization handling #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions elodie/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def get_file_name(self, metadata):

if('File' in config and 'capitalization' in config['File'] and config['File']['capitalization'] == 'upper'):
return name.upper()
elif('File' in config and 'capitalization' in config['File'] and config['File']['capitalization'] == 'title'):
# Mine is:
# date=%d-%H%M%S
# name=%date [%city] %original_name.%extension
# Since strings before "]" are quite stable, it ensures that they can be split properly by "]" no matter what the original name is.
# "]" is replaceable.
return name.split(']', maxsplit=1)[0].title() + ']' + name.split(']', maxsplit=1)[1]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you proposing that text within []'s gets special treatment? Is the goal here that, for example, the i in img_0001.jpg does not get capitalized?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your reply.

Initially, I wanted to keep the original filename unchanged, but capitalize the first letter of the city name in the filename so it looks good. For example, a photo named iOS_IMG_0144.Heic would be renamed to:

└── 2023-Mar
│   ├── 25-235959 [Toronto] iOS-IMG_0144.heic

The iOS remains the same, while Heic is changed to heic to align with the requirements of other parts of this project.


After customizing my own naming rules, I thought it would be helpful to let people know that they can easily split and modify their filenames. I chose the "]" character as a good separator based on my naming rules.

For example, adding another elif statement and using the rsplit() function in the following code can help people to convert the filename extension to lowercase while keeping the rest of the filename in uppercase:

elif('File' in config and 'capitalization' in config['File'] and config['File']['capitalization'] == 'up_name_with_low_ext'):
            return name.rsplit('.', maxsplit=1)[0].upper() + '.' + name.rsplit('.', maxsplit=1)[1].lower()

Perhaps I should commit this code that is more suitable for others, rather than the one that is just for myself?

As a beginner in coding, please feel free to point out any issues with my code or ideas.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, that makes sense.

As a beginner in coding, please feel free to point out any issues with my code or ideas.

This parsing logic is one of the more complex parts of this code base (as seen by the ratio of comments to code in get_file_name. Uppercasing the entire file name is easy to do here because we don't have to be precise - we just uppercase the whole thing.

If we want to capitalize specific parts of the file name it might more suitable to do it higher up in this function. Either in the for loop starting at line 151 or after the for loop when we interpolate into the templated string around line 210.

What do you think?

else:
return name.lower()

Expand Down