PySceneDetect icon indicating copy to clipboard operation
PySceneDetect copied to clipboard

Investigate different method of template replacement instead of $-prefixed

Open Breakthrough opened this issue 3 years ago • 3 comments

Description of Problem & Solution Right now using templates in bash requires escaping the dollar signs. Investigate using a style similar to Python instead to help with this, e.g.:

scenedetect [...] split-video -f {VIDEO_NAME}-Scene-{SCENE_NUMBER}.mp4

Proposed Implementation: Allow both dollar signed template $VARIABLES as well as braced {VARIABLES} to mean the same thing. However since {} may need to be escaped (see below), another solution might need to be investigated.

If any best practices exist, those should be followed.

Alternative Solutions: TODO: Research how most other command line interfaces approach this before finalizing a solution.

Breakthrough avatar Sep 04 '21 23:09 Breakthrough

Apparently braces need to be escaped in bash terminals as well, so might need to just use another delimiter symbol. I'm unable to find any documented best practices involving command line arguments specifically for string/template replacement, so any resources someone can point me to would be much appreciated.

Breakthrough avatar Nov 03 '21 22:11 Breakthrough

As found in #291, there also might be issues with only using a prefix, so using a suffix should be considered.

Breakthrough avatar Oct 07 '22 02:10 Breakthrough

I was doing some reading on the python Template class and found out why the behavior identified in #291 occurs. See here for an explanation (tl;dr is that _ is a reserved python character and can break substitution unless braces are also used). For example '$VIDEO_NAME_test.csv' does not work because the variable is followed by _. However, '${VIDEO_NAME}_test.csv' does work because the brackets separate the template variable from the _.

If changing the delimiter is desired, then creating a custom template class that inherits from Template and then rewriting the delimiter might be a good way to go. Template doesn't seem to support a prefix/suffix substitution scheme that I can tell, so this kind of issue with a template variable being followed by a reserved python character would require a different solution (regex substitution?).

Alternatively, this edge case could be documented in the docs with the solution of including braces. Or, the documentation could include braces in all cases and the inclusion of braces is essentially considered the "default" usage.

wjs018 avatar Oct 28 '22 04:10 wjs018