feat: add optional filename_format parameter to download_videos()#1211
Open
SamStorer wants to merge 1 commit intofronzbot:devfrom
Open
feat: add optional filename_format parameter to download_videos()#1211SamStorer wants to merge 1 commit intofronzbot:devfrom
SamStorer wants to merge 1 commit intofronzbot:devfrom
Conversation
309fa5f to
dc48f22
Compare
- Add _format_filename_default() method to encapsulate default filename formatting
- Add filename_format parameter to download_videos() allowing custom filename generation
- Update _parse_downloaded_items() to accept and use custom format function
- Maintain full backward compatibility (defaults to existing slugified format)
- Add test cases for custom format functions in tests/test_download_format.py
The filename_format parameter accepts a callable with signature:
filename_format(created_at: str, camera_name: str, path: str) -> str
Where created_at is an ISO 8601 timestamp string, and the function must return
the full filepath including filename and extension.
Usage example:
def custom_fmt(created_at, camera_name, path):
dt = datetime.datetime.fromisoformat(created_at).astimezone(
pytz.timezone('US/Eastern')
)
clean_name = camera_name.replace(' ', '')
return os.path.join(path, f'{dt:%Y%m%d_%H%M%S}_{clean_name}.mp4')
await blink.download_videos(path, filename_format=custom_fmt)
This change is backward compatible; existing code without the parameter
continues to work with the default slugified format.
dc48f22 to
ea47bd3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Usage example: