Requires Multiple Patterns to Match

All about user-defined episode / movie / file name format expressions
Post Reply
note4shawn
Posts: 5
Joined: 10 Dec 2020, 18:48

Requires Multiple Patterns to Match

Post by note4shawn »

Hello,
I have been searching for examples for my specific use-case but have not found the answers yet.

I want to rename and move files that have either HEVC OR x265, AND 1080P in the file name (or better yet Mediainfo bindings because many times the filename has both HEVC and x265, but other times they may have just one of them). Once I get this basic expression figured out I will then want to expand on it to have more combos like AVC/x264, 720P/2160P etc.

With the above criteria, here is the format I am wanting to rename these files to:

Code: Select all

{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)
AND be moved to: /mnt/to-be-sorted

From my research this is a way to do a basic either/or expression off of the filename.

Code: Select all

{fn =~ /HEVC|x265/ ? 'HEVC 1080P'}
How do I add the rest of the AND statement to the above expression and use Mediainfo bindings instead of filename?

Shawn
User avatar
rednoah
The Source
Posts: 23945
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Requires Multiple Patterns to Match

Post by rednoah »

Here's how and works:

Code: Select all

{fn =~ /HEVC|x265/ && fn =~ /1080P/ ? 'HEVC 1080P' : null}

Here's how MediaInfo bindings work:
viewtopic.php?t=4285

e.g.

Code: Select all

{vc} {vf}
:idea: Please read the FAQ and How to Request Help.
note4shawn
Posts: 5
Joined: 10 Dec 2020, 18:48

Re: Requires Multiple Patterns to Match

Post by note4shawn »

I just found some other expressions in some posts that used the &&. I was in the middle of putting something together. I will continue to work with it and see what I can get that part to work.

I will research and see how to implement the {vc} and {vf} bindings into my code correctly.

Thanks rednoah!
note4shawn
Posts: 5
Joined: 10 Dec 2020, 18:48

Re: Requires Multiple Patterns to Match

Post by note4shawn »

Real quick, if I wanted to write an if/then statement to rename would it be something like this?

Code: Select all

--def "seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)' : '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (AVC 1080P)'}"
Also can I assign identifiers in Groovy (to help keep things clean) for the naming expressions like:

Code: Select all

def rn-HEVC1080P = {n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)
def rn-AVC1080P = {n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (AVC 1080P)
And then call them like:

Code: Select all

--def "seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '$rn-HEVC1080P' : '$rn-AVC1080P'}"
Sorry if this is really messed up. I have messed around with bash scripts and python but completely new to Groovy. Just trying to find the common ground between them.
note4shawn
Posts: 5
Joined: 10 Dec 2020, 18:48

Re: Requires Multiple Patterns to Match

Post by note4shawn »

I am still working on and needing some help with the previous question but I ran into an issue that was causing me a lot of troubles when trying to run my bash script from the terminal.

When trying to rename files using this expression (which works great in the gui)

Code: Select all

{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)
It gives me this error

Code: Select all

"-" is not a valid option
Is there different syntax for this that will work?
User avatar
rednoah
The Source
Posts: 23945
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Requires Multiple Patterns to Match

Post by rednoah »

1.
Please read Cmdline and Argument Passing. That'll explain why FileBot is complaining about getting passed invalid arguments.


2.
You can use variables, but only within the context of a Groovy expression:
https://groovy-lang.org/single-page-documentation.html

e.g.

Code: Select all

{
	def x = n + y
	return x
}
:idea: Please read the FAQ and How to Request Help.
note4shawn
Posts: 5
Joined: 10 Dec 2020, 18:48

Re: Requires Multiple Patterns to Match

Post by note4shawn »

Thanks for the info. I am working on my arguments doc now. Will have to look into the variables after I figure these other things out. So much to learn and understand.

Can you/someone tell me if it is possible to have a if/then statement to rename files? If so, can you guide me on how to fix my code here?

Code: Select all

--def "seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)' : '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (AVC 1080P)'}"
Thanks for all the help!
User avatar
rednoah
The Source
Posts: 23945
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Requires Multiple Patterns to Match

Post by rednoah »

rednoah wrote: 11 Dec 2020, 03:08 Please read Cmdline and Argument Passing. That'll explain why FileBot is complaining about getting passed invalid arguments.
I'd focus on passing arguments correctly first. If the shell mangles your arguments, then it doesn't matter if the format is correct or not.


BAD:

Code: Select all

filebot -script fn:sysenv --def "seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)' : '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (AVC 1080P)'}"

Did you read the manual?
└ https://www.filebot.net/cli.html

Did you quote and escape your arguments correctly?
└ https://www.filebot.net/help/args.html

args[1] = -script
args[2] = fn:sysenv
args[3] = --def
args[4] = seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '{n.replaceAll(/[:|]/,
args[5] = -
args[6] = )} {s00e00} - {t.replaceAll(/[:|]/,
args[7] = -
args[8] = )} (HEVC 1080P)' : '{n.replaceAll(/[:|]/,
args[9] = -
args[10] = )} {s00e00} - {t.replaceAll(/[:|]/,
args[11] = -
args[12] = )} (AVC 1080P)'}

"-" is not a valid option

GOOD:

Code: Select all

# Arguments #
args[0] = -script
args[1] = fn:sysenv
args[2] = --def
args[3] = seriesFormat={fn =~ /HEVC|x265/ && fn =~ /1080P/ ? '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (HEVC 1080P)' : '{n.replaceAll(/[:|]/, " - ")} {s00e00} - {t.replaceAll(/[:|]/, " - ")} (AVC 1080P)'}
:!: Note that your format is still syntactically incorrect. But that's unrelated to passing arguments correctly.



:arrow: Please use the Format Editor for testing and prototyping format code, otherwise you're just making things unnecessarily hard for yourself:
Image
:idea: Please read the FAQ and How to Request Help.
Post Reply