File Renaming
-
- Posts: 8
- Joined: Tue Jul 09, 2019 12:46 am
File Renaming
I'm certain this is a dumb question but I've been struggling with it.
I have a workflow that will take various formats in and create different encodes based on them.
I'd like to replace some values in the original filename for the resulting encodes but am not sure the best way to to go about it.
The input names have values like:
FilmsMan_TestingNames_203_RUS_f2398_UHD_239.mov
NewPalPost_HistoryOfTheShowName_ENG_f25_UHD_1237.mov
OldPalShows_OurVideoShow_ep12_f25_SD_404_1986.mov
The output filenames will need to be changed according to the encodes performed_(f\d+)_ to f2997 for example. _(UHD)_ to HD etc. This wouldn't be so bad with append and using variables, the issue i'm having is that I need to capture the number string at the end first, and replace it afterwards. _(239).mov, _(1237).mov etc.
Any ideas what nodes I should investigate for this?
Any help pointing me down the right path is greatly appreciated.
I have a workflow that will take various formats in and create different encodes based on them.
I'd like to replace some values in the original filename for the resulting encodes but am not sure the best way to to go about it.
The input names have values like:
FilmsMan_TestingNames_203_RUS_f2398_UHD_239.mov
NewPalPost_HistoryOfTheShowName_ENG_f25_UHD_1237.mov
OldPalShows_OurVideoShow_ep12_f25_SD_404_1986.mov
The output filenames will need to be changed according to the encodes performed_(f\d+)_ to f2997 for example. _(UHD)_ to HD etc. This wouldn't be so bad with append and using variables, the issue i'm having is that I need to capture the number string at the end first, and replace it afterwards. _(239).mov, _(1237).mov etc.
Any ideas what nodes I should investigate for this?
Any help pointing me down the right path is greatly appreciated.
Re: File Renaming
Hey TMH,
welcome to the forum!
your Announcement thread is great, i like it
Your question is a little confusing for me as you already do lots of regex, so i don't understand what exactly is your problem: are you having problems getting the regex done or do you have totally different problems. However, here how i understood what you want to do:
Take a Populate Variables processor, create a new User variable to hold the calculated target filename (in my example "new_filename") and do your regext like that:
The first regex with the "1111" at the end will take any number before a dot followed by three characters (i hope your extensions always have 3 characters)
The last part, "1111", "29.9" and "SD" sure needs to be replaced by some other text/variable from you, it represents the stuff that is inserted into the new filename.
welcome to the forum!
your Announcement thread is great, i like it
Your question is a little confusing for me as you already do lots of regex, so i don't understand what exactly is your problem: are you having problems getting the regex done or do you have totally different problems. However, here how i understood what you want to do:
Take a Populate Variables processor, create a new User variable to hold the calculated target filename (in my example "new_filename") and do your regext like that:
Code: Select all
$replace("%s_source%",$regext("%s_source%","(\d+)\...."),"1111")
Code: Select all
$replace("%s_new_filename%",$regext("%s_source%","_(f\d+)_"),"29.9")
Code: Select all
$replace("%s_new_filename%",$regext("%s_source%","_(UHD)_|_(HD)_|_(SD)_"),"SD")
The last part, "1111", "29.9" and "SD" sure needs to be replaced by some other text/variable from you, it represents the stuff that is inserted into the new filename.
emcodem, wrapping since 2009 you got the rhyme?
-
- Posts: 8
- Joined: Tue Jul 09, 2019 12:46 am
Re: File Renaming
I see now that the root of my problem is being ignorant of the syntax of functions.
Your examples look like they'll help a lot!
I can't wait to try this out.
Your examples look like they'll help a lot!
I can't wait to try this out.
Re: File Renaming
Hello encodem,
I'm trying to understand this Regext function but I must admit it's a little bit difficult. I understand the first part ($regext("%s_source%") "catch" the source file name but the second _(f\d+)_ or (\d+)\.... is quiet drak for me
I know $regext is a FFastrans Function but there is only 2 examples in help file so I believe I don't understand all the "subtleties."
Can you give me more example please ? I think I could use these great function .
Thank you very much.
Cheers.
I'm trying to understand this Regext function but I must admit it's a little bit difficult. I understand the first part ($regext("%s_source%") "catch" the source file name but the second _(f\d+)_ or (\d+)\.... is quiet drak for me
I know $regext is a FFastrans Function but there is only 2 examples in help file so I believe I don't understand all the "subtleties."
Can you give me more example please ? I think I could use these great function .
Thank you very much.
Cheers.
Re: File Renaming
@thmlegolas great, let me know if it works out for you
@momocampo
Regex is very mighty and very complex. It is like it's own little programming language for finding stuff in text. The good thing about it is that a developer can use it in almost every programming language. So even if one changes the used language, finding text always works the same.
Even tough i believe it is easier to understand for you if you find some french language tutorial for regex in the internet, i'll try to explain a little:
i believe the biggest problem using regex is that you need to be able to "see" or recognize what part of the regex is "looking for a plain character" and what part is a function in regex.
The first thing that i do when looking at a regex is to get out what are actual plain text characters and what are regex functions.
Above regex explained, let us remove the parantheses first, i'll come to that part as last thing.
Explained:
-) The first 2 characterst "_f" are looking for "plain text", so the first occurence of "_f"
-) \d is not "plain text", it is a regex function to find a number. \d+ means "one or more numbers", e.g. 13834
-) The last character _ is "plain text" again.
-) when you put all that together, the regex is looking for something like "_f43352_" In case the text looks different like "_fABC_" or "_f1234ABC", the regex would not match anything.
Now with parantheses
In Words: please find "f" followed by one or more numbers, but only if before "f" there is at least one "_" and after the number also there is at least one "_"
-) Still exactly the same as above, but the parantheses define that we do not want the "_" at start and end in the match result.
-) without the parantheses, the match result for "_f1234_" would be "_f1234_" but with parantheses the match result is "f1234"
-) Other Examples:
-) ABC_f5432_DEF --> regex finds: f5432
-) 123_f1_6542 --> regex finds: f1
-) 123_f12_6542 --> regex finds: f12
-) 123_f54ABC32_6542 --> regex finds: nothing
In Words: give me the number where before the number there is a "_" and after the number one "dot (.)" followed by 3 charcters minimum
-) ABC123_456.mov --> regex finds 456
-) ABC123_456.m4 --> regex finds nothing
-) ABC123_456.mxfmxf --> regex finds 456
-) ___1.mp4 --> regex finds 1
.
-) ABC123_456.mov --> regex finds _456.mov
-) ABC123_456.m4 --> regex finds nothing
-) ABC123_456.mxfmxf --> regex finds _456.mxf
-) ___1.mp4 --> regex finds _1.mp4
In parts:
-) ABC123 --> regex finds A (the first occurence of exactly one character)
-) ABC123 --> regex finds AB (the first occurence of exactly two characters)
-) ABC123 --> regex finds nothing
-) ABC123.mxf --> regex finds the "."
-) ABC123.mxf --> regex finds .mxf
-) ABC123 --> regex finds 1 (the first occurence of a number)
-) ABC123 --> regex finds 12 (the first occurence of 2 numbers in a row)
-) ABC123 --> regex finds 123 (the first occurence of a series of numbers)
-) ABC123 --> regex finds 123 (the first occurence of a series of numbers)
-) ABC123 --> regex finds A (the first occurence of a letter character [a-z])
@momocampo
Regex is very mighty and very complex. It is like it's own little programming language for finding stuff in text. The good thing about it is that a developer can use it in almost every programming language. So even if one changes the used language, finding text always works the same.
Even tough i believe it is easier to understand for you if you find some french language tutorial for regex in the internet, i'll try to explain a little:
i believe the biggest problem using regex is that you need to be able to "see" or recognize what part of the regex is "looking for a plain character" and what part is a function in regex.
The first thing that i do when looking at a regex is to get out what are actual plain text characters and what are regex functions.
Above regex explained, let us remove the parantheses first, i'll come to that part as last thing.
Code: Select all
Regex: _f\d+_
-) The first 2 characterst "_f" are looking for "plain text", so the first occurence of "_f"
-) \d is not "plain text", it is a regex function to find a number. \d+ means "one or more numbers", e.g. 13834
-) The last character _ is "plain text" again.
-) when you put all that together, the regex is looking for something like "_f43352_" In case the text looks different like "_fABC_" or "_f1234ABC", the regex would not match anything.
Now with parantheses
Code: Select all
Regex: _(f\d+)_
-) Still exactly the same as above, but the parantheses define that we do not want the "_" at start and end in the match result.
-) without the parantheses, the match result for "_f1234_" would be "_f1234_" but with parantheses the match result is "f1234"
-) Other Examples:
-) ABC_f5432_DEF --> regex finds: f5432
-) 123_f1_6542 --> regex finds: f1
-) 123_f12_6542 --> regex finds: f12
-) 123_f54ABC32_6542 --> regex finds: nothing
Code: Select all
Regex: _(\d+)\....
-) ABC123_456.mov --> regex finds 456
-) ABC123_456.m4 --> regex finds nothing
-) ABC123_456.mxfmxf --> regex finds 456
-) ___1.mp4 --> regex finds 1
Code: Select all
Without parantheses: _\d+\...
-) ABC123_456.mov --> regex finds _456.mov
-) ABC123_456.m4 --> regex finds nothing
-) ABC123_456.mxfmxf --> regex finds _456.mxf
-) ___1.mp4 --> regex finds _1.mp4
In parts:
Code: Select all
Regex: .
Code: Select all
Regex: ..
Code: Select all
Regex: \.
-) ABC123.mxf --> regex finds the "."
Code: Select all
Regex: \.mxf
Code: Select all
Regex: \d
Code: Select all
Regex: \d\d
Code: Select all
Regex: \d+
Code: Select all
Regex: \d+
Code: Select all
Regex: \w
emcodem, wrapping since 2009 you got the rhyme?
Re: File Renaming
My god
This is a real tutorial !! It's so kind from you
I have to read that very carefully but I can't wait to try all of this
Thank you so much for the time you spent to teach us
cheers.
This is a real tutorial !! It's so kind from you
I have to read that very carefully but I can't wait to try all of this
Thank you so much for the time you spent to teach us
cheers.
-
- Posts: 8
- Joined: Tue Jul 09, 2019 12:46 am
Re: File Renaming
wow, encodem you are a true saint.
momocampo, if you want to practice some of the examples encodem gives, sites like this may help:
https://regexone.com/
https://regexr.com/
If you search "regex tester" in your native language you may find some that work better.
momocampo, if you want to practice some of the examples encodem gives, sites like this may help:
https://regexone.com/
https://regexr.com/
If you search "regex tester" in your native language you may find some that work better.
-
- Posts: 8
- Joined: Tue Jul 09, 2019 12:46 am
Re: File Renaming
Encodem. First off, thank you so much for helping, your method does work. However, I think I have a better handle now on the functions and my question to you was unclear.
I realize now that I want to Capture those name segments mentioned as variables. This way I can tear apart and rebuild as necessary. I am not sure If what i'm asking is possible.
Assuming %s_original_name%.%s_original_ext% is NewPalPost_HistoryOfTheShowName_ENG_f25_UHD_1237.mov
Imagine I want populate the variable %s_framerate% from the string %s_original_name%.%s_original_ext% using the regex ^.+_(f25)_.+$
Is that possible? I think you can see that I am more video editor than computer programmer:)
Again, thank you so much for your time, your previous method will work, but will not allow me to use the variables created from captured filename values for other things if i needed.
I realize now that I want to Capture those name segments mentioned as variables. This way I can tear apart and rebuild as necessary. I am not sure If what i'm asking is possible.
Assuming %s_original_name%.%s_original_ext% is NewPalPost_HistoryOfTheShowName_ENG_f25_UHD_1237.mov
Imagine I want populate the variable %s_framerate% from the string %s_original_name%.%s_original_ext% using the regex ^.+_(f25)_.+$
Is that possible? I think you can see that I am more video editor than computer programmer:)
Again, thank you so much for your time, your previous method will work, but will not allow me to use the variables created from captured filename values for other things if i needed.
Re: File Renaming
Thanks Tmhlegolas, I found a good tutorial in French. It will help me to begin with regex.
About FFastrans, I usually use the functions and try to "aim" the good character to create a variable. Regex seems to be more specific
Cheers.
About FFastrans, I usually use the functions and try to "aim" the good character to create a variable. Regex seems to be more specific
Cheers.
Re: File Renaming
Sure, on the left side in the populate vars processor, you choose your s_framerate variable and on the right side something like that:tmhlegolas wrote: ↑Wed Jul 31, 2019 6:40 pm Imagine I want populate the variable %s_framerate% from the string %s_original_name%.%s_original_ext% using the regex ^.+_(f25)_.+$
$regext("%s_original_name%.%s_original_ext%","_(f\d+)_")
Simplified (you don't need to use the extension variable for matching stuff in the original filename):
Code: Select all
$regext("%s_original_name%","_(f\d+)_")
I changed your regex to _(f\d+)_ because i did not understand why you would specify start and end with ^.+ .+$, it should work without that. Also \d+ in order to match all framerates, not only 25.
As you might recognize, the matched value will be like "f25". If you change the parantheses to _f(\d+)_, the matched value will be like 25. You always get the "first matchgroup" (first value in parantheses) as result. In case there are no parantheses you get the full match back, e.g. for _f\d+_ the matched value would be like _f25_
emcodem, wrapping since 2009 you got the rhyme?