Regex-based naming scheme misnaming one file

All about user-defined episode / movie / file name format expressions
Post Reply
brijazz
Posts: 37
Joined: 25 May 2022, 20:53

Regex-based naming scheme misnaming one file

Post by brijazz »

Sorry for the awkward subject line, but I wasn't sure how to express my issue concisely. I've been using this command for about a year without issue. But for some reason, it's inaccurately naming episodes of ONE show (while continuing to work properly on other new episodes for other shows):

Shell: Select all

/Applications/FileBot.app/Contents/MacOS/filebot.sh -rename "$1" --db TheMovieDB::TV -non-strict -non-strict --log-file ~/Documents/filebot.log --format "{~plex} ({vf}{video.HDR_Format =~ /Dolby Vision/ && video.HDR_Format_Compatibility =~ /HDR/ ? '  - DV+HDR10)' : video.HDR_Format =~ /Dolby Vision/ && video.HDR_Format_Compatibility !=~ /HDR/ ? ' - DV)' : video.HDR_Format !=~ /Dolby Vision/ && video.HDR_Format_Compatibility =~ /HDR10/ ? ' - HDR10)': ')'}" -exec touch {folder} {folder.dir}
Essentially, the command attaches the {plex} binding, then – using regex – appends HDR info based on what type of HDR is present in the file (typically Dolby Vision and/or HDR10).

The issue with the file in question is that it is naming episodes of the show in question as 'HDR' and not 'HDR10' despite HDR10 being present in the file. MediaInfo output is at https://pastebin.com/dUP1YrRi

Any idea what's not working here for this one particular show?
User avatar
rednoah
The Source
Posts: 24520
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex-based naming scheme misnaming one file

Post by rednoah »

:!: I see what you did there. Except !=~ is not the operator you think it is. Note how both of these expression evaluate to true rather counterintuitive so:

Groovy: Select all

'HDR' !=~ /HDR/   // this is true

Groovy: Select all

'HDR' =~ /HDR/    // this is true

:idea: So while !=~ does not exist as a not-find operator, it is syntactically valid, and interpreted like this:

Groovy: Select all

'HDR' != (~/HDR/) // this is true
which is always true because String "HDR" is never equal to Regular Expression /HDR/


:arrow: If you need a not-find then you need to write code like this to get the correct true / false values:

Groovy: Select all

!('HDR' =~ /HDR/) // this is false

:arrow: This you need to modify your code like so:

Groovy: Select all

!(video.HDR_Format_Compatibility =~ /HDR/)

Groovy: Select all

!(video.HDR_Format =~ /Dolby Vision/)
:idea: Please read the FAQ and How to Request Help.
brijazz
Posts: 37
Joined: 25 May 2022, 20:53

Re: Regex-based naming scheme misnaming one file

Post by brijazz »

That worked, thank you so much!

I'm curious as to why my original version has previously been working on every file except for this one. For example, here's the MediaInfo for a different file that has the exact same HDR/DV info: https://pastebin.com/J27nhZ7F

Any idea what would have caused my command to work on one file but not the other?
User avatar
rednoah
The Source
Posts: 24520
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex-based naming scheme misnaming one file

Post by rednoah »

The code fundamentally never worked, but since there's lots of conditions, you probably just never tested that specific code path.


:idea: Here's the code you effectively had running, so you can insert the variables and check the conditions to find out what it does and why:

Format: Select all

{video.HDR_Format =~ /Dolby Vision/ && video.HDR_Format_Compatibility =~ /HDR/ ? '  - DV+HDR10)' : video.HDR_Format =~ /Dolby Vision/ && true ? ' - DV)' : true && video.HDR_Format_Compatibility =~ /HDR10/ ? ' - HDR10)': ')'}

:idea: Note that different versions of libmediainfo may give you different MediaInfo tables. The exact values for the HDR related properties are known to have been refined over the last few years. HDR_Format_Compatibility was introduce rather recently as well. A newer version of FileBot may generate different file paths with the same code since a newer version of FileBot comes with a newer version of libmediainfo thus giving your code different variable values to work with. That said, I don't know if this is relevant for in your specific case.
:idea: Please read the FAQ and How to Request Help.
brijazz
Posts: 37
Joined: 25 May 2022, 20:53

Re: Regex-based naming scheme misnaming one file

Post by brijazz »

Thanks again. I always appreciate your speedy and helpful replies!
Post Reply