DonationCoder.com Software > Find And Run Robot
regex default value if nothing entered
(1/1)
jinxx:
for example if I have this farr alias with respective value (some stuff redacted and formatted for readability):
slicevideo "(.*)" (.*) (.*) (.*)
shellexec /k "source file"=$$1 - cut time=$$2 - duration=$$3 - output name=$$4 |
ffmpeg.exe -i "$$1" -ss $$2 -c copy -t $$3 -vf "\ffmpeg output\$$4.mp4"
Say I wanted to sometimes omit the last value "$$4", and if I omitted it then "$$4" would go to the default value of "untitled" so i'd end up spitting out a file "untitled.mp4"
Is this possible? also for multiple trailing values
Obviously as-is it only works for the trailing $$'s
Nod5:
I don't think the FARR alias syntax has any feature for that kind of conditionality.
Not sure if there is a way to do it in the windows cmd part (left side of the | pipe).
My own solution in these kinds of cases is to write a small AutoHotkey script and have FARR run it with the parameters and do the conditional steps in the script. If you go for this option then consider doing only
--- ---slicevideo (.*)
and separate out parameters from that one long string once in the script.
edit: Something like this
FARR alias
alias name: slicevideo
alias regex: slicevideo (.*)
alias result: C:\folder\FARR_slicevideo_helper.exe "$$1"
AutoHotkey script
Saved as FARR_slicevideo_helper.ahk and then compiled to FARR_slicevideo_helper.exe
--- Code: Autohotkey ---#NoEnvSetWorkingDir %A_ScriptDir%#SingleInstance force ; FARR alias slicevideo helper script; 2020-09-19 ; FARR alias syntax:; slicevideo "(.*)"; where the regex sub pattern contains one of these string formats:; - "<filepath>" <start-time-in-seconds> <duration-time-in-seconds> <out-file-name-no-ext>; - "<filepath>" <start-time-in-seconds> <duration-time-in-seconds>; - "<filepath>" <start-time-in-seconds>; rule: only <filepath> can include spaces ; process command line input; split at quote marks to array; -> array item 1 = blank; -> array item 2 = input file path; -> array item 3 = all remaining params, space separatedArrayA := StrSplit(A_Args[1], """"); split above array item 3 at spaces to new arrayArrayB := StrSplit(ArrayA[3], " ") File := ArrayA[2]StartTime := ArrayB[2]Duration := ArrayB[3]OutFile := ArrayB[4] ; input file must exist and starttime must be setif !FileExist(File) or !StartTime ExitApp ; fallback output filenameif !OutFile OutFile := "untitled" ; fallback duration in secondsif !Duration Duration := 60 ; run cmd window that stays open and starts ffmpeg cutRun %comspec% /k " ffmpeg.exe -i "%File%" -ss %StartTime% -c copy -t %Duration% -vf "\ffmpeg output\%OutFile%.mp4" "
wjamoe:
or you can make all 4 fields mandatory like:
slicevideo\s+"([^"]+)"\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)
\s+ = at least one space or tab (white space)
[^"]+ = at least one character until a quote
[^\s]+ = at least one character not being a white space
() = remember contents for use in $$1 $$2 $$3 $$4
Maybe you want to limit the characters for $$2 $$3 $$4 to make sure valid time format and filename
slicevideo\s+"([^"]+)"\s+([\d:]+)\s+([\d:]\w+)\s+(\w+)$
\w+ = at lease one word character 0-9 a-z A-Z and the underscore (word characters)
[\d:]+ =0-9 and ':' (in random order!)
[0-9:] =0-9 and ':' (in random order)
if you want to extend the word characterset with '+' and '-'
replace
\w+
by
[\w+\-]+
please note you need a backslash just before the minus sign
-----
or a simple alternative
add a prefix (e.g. vid_) to each $$4 in the alias this will keep working when $$4 is empty like so:
shellexec /k "source file"=$$1 - cut time=$$2 - duration=$$3 - output name=vid_$$4 |
ffmpeg.exe -i "$$1" -ss $$2 -c copy -t $$3 -vf "\ffmpeg output\vid_$$4.mp4"
Nod5:
Discussion in another thread https://www.donationcoder.com/forum/index.php?topic=50563.0 got me thinking...
An alternative way to do what OP here wants withouth using an external AutoHotkey script is to set up multiple aliases, one for each possible use case.
case 1 would be your original example where all four parameters are typed. Let us call that alias 1. We could there use the regex wjamoe suggested which requires all four parameters to be typed.
regex: slicevideo\s+"([^"]+)"\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)
results:
--- ---shellexec /k "source file"=$$1 - cut time=$$2 - duration=$$3 - output name=$$4 | ffmpeg.exe -i "$$1" -ss $$2 -c copy -t $$3 -vf "\ffmpeg output\$$4.mp4"
case2
Say I wanted to sometimes omit the last value "$$4", and if I omitted it then "$$4" would go to the default value of "untitled" so i'd end up spitting out a file "untitled.mp4"
--- End quote ---
covered by alias 2:
regex: slicevideo\s+"([^"]+)"\s+([^\s]+)\s+([^\s]+)
results:
--- ---shellexec /k "source file"=$$1 - cut time=$$2 - duration=$$3 - output name=untitled | ffmpeg.exe -i "$$1" -ss $$2 -c copy -t $$3 -vf "\ffmpeg output\untitled.mp4"
You can create additional sibling aliases for the other cases you want to cover.
The drawback with this approach is that it is unwieldy to overview and if you want to later on e.g. change the ffmpeg path you need to edit multiple aliases.
Navigation
[0] Message Index
Go to full version