-
Notifications
You must be signed in to change notification settings - Fork 94
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
Allow templates to be nested in templates (e.g. use another template field as the DEFAULT value for a template) #363
Comments
Unfortunately this isn't currently possible. I've considered this use case several times -- it would make the templating system very powerful to be able to nest templates. The template system is currently implemented with a regular expression (pattern matching) algorithm that does simple substitutions and can't handle nested patterns. To implement this would require significant re-work of the templating engine. Coupled with the boolean templates I'm working on implementing you could do some really complex export scenarios quite easily. It's something I'd like to tackle eventually but have a number of higher priority things at the moment. However, I do think it would be easy to create a work-around for your specific use case. I could add
|
Thanks, this workaround would be great! |
I've implemented --album and --not-in-album in v0.40.8 which should let you do the double-export as referenced above. This will even work with --update as both exports will use the same export database in your export directory to track exported files. The only limitation will be you cannot use --cleanup as this would think the photos from the second export were not needed and delete them. Also, be advised that with using {album} as a template could result in duplicate photos if a photo is in more than one album. Also, if you have any album names that match {created.mm} format (e.g. "03"), you'll possibly get name collisions. |
I've been experimenting with pyparsing and I think I can implement a full PEG parser for the template system which would allow arbitrary nesting of templates. This will take a bit of a learning curve and rework of the templating system so it won't happen quickly but definitely something for the roadmap. If anyone has experience with pyparsing and wants to help, I'll take it! |
After spending a couple hours studying pyparsing, I'm still finding it difficult to understand. Luckily I found textx and am making progress on grammar implementation for the osxphotos template language which should allow the templating system to be much more capable. |
So textx is amazing and easy to use! I've been able to get a full parser working that allows arbitrary nesting of templates! It'll take some work to refactor the template code in osxphotos to use this but I think it'll be much easier than I first expected. @saruter this means you'll be able to do something like this once implemented:
|
I got the new template parser working -- need to add some more tests then I'll release it in next week or so. It is much more powerful than the current template system -- allows arbitrary nesting of templates and allows any template to be used as a boolean. |
Wohoo, sounds amazing. Thanks for your work in this! |
I've released v0.41.0 with a completely re-written template engine which now allows nested templates. For example, this now works:
|
Hi,
thanks for developing this great tool, found nothing better!
I have one question concerning templating the folder structure when exporting.
What I want to achieve:
Exporting Photos to a folder-structure like this (DEFAULT value is another field):
--directory "{created.year}/{folder_album,created.mm}"
Which means that photos which are included in albums are exported in a folder like this (example):
2020/myalbum/img-xxxxx.jpg
and for photos which are not present in any album a default value of the month in which the photo was taken:
2020/03/img-xxxxx.jpg
resulting in a folder structure like this:
Is this currently possible?
The text was updated successfully, but these errors were encountered: