Commentary track

All about user-defined episode / movie format expressions
Post Reply
jerome
Posts: 12
Joined: 25 Feb 2019, 02:21

Commentary track

Post by jerome »

I use the GUI interface and I'm trying to rename my files that have multiple audio tracks and also have a Commentary track per the MediaInfo data.
I realize that if the track is not named as "Commentary" in the MediaInfo data then the renaming will be null. For those files with a Commentary track but not tagged as such in MediaInfo I'll have to go through each file that is listed with multiple audio tracks and check manually. For those, I will use mkvtools to fix the metadata and rerun the file naming code I have created with the help of these forums.

Nevertheless, here is the test code I have that seems to work (assuming 5 audio tracks max), but I'm thinking there is an easier code that works for the part to tag the filename with 'Commentary'.

{(audio.size() > 1) ? audio.size() + 'AUD.' : ""}
{audio[0].title.contains('Commentary') ? 'Commentary.' :
audio[1].title.contains('Commentary') ? 'Commentary.' :
audio[2].title.contains('Commentary') ? 'Commentary.' :
audio[3].title.contains('Commentary') ? 'Commentary.' :
audio[4].title.contains('Commentary') ? 'Commentary.' : ''}

I thought one of these might work but I was wrong.
{audio().title.contains =~ /Commentary/ ? 'COMMENTARY' : ''}
{audio.title().contains =~ /Commentary/ ? 'COMMENTARY' : ''}
{audio.title.contains() =~ /Commentary/ ? 'COMMENTARY' : ''}

I have tried various other alternatives that were not a if then else statement but none of those worked either.
I'm hoping that a more simple code will help me not only in this example but to also understand better how the coding works and that might help me with other similar examples I have in my coding for nested if then else. I apologize in advance if there is a simple answer that I'm not seeing but I'm not a programmer.

TIA
J
kim
Power User
Posts: 1046
Joined: 15 May 2014, 16:17

Re: Commentary track

Post by kim »

This was the best I can make:

Code: Select all

{ audio.collect{ au -> any{au.title}{} } =~ /(?i:Commentary)/  ? 'COMMENTARY' : '' }
look up groovy and/or java code
jerome
Posts: 12
Joined: 25 Feb 2019, 02:21

Re: Commentary track

Post by jerome »

Thanks Kim

Your code works much better than mine, obviously. Even caught instances my simplistic code was missing.

Now I just need to do some research to break down its complexity so that I can understand what each part of it is doing. I'm reasoning that you are combining all the audio data into a new variable "au" and then checking that variable for any instance of the word "commentary" and if true tag with Commentary else null. I'll need to research what --> and ?i means and why it requires brackets.

Again thanks for the help.

I can't tell you how much time this program has saved me in renaming files. Maybe in a couple of years I'll be confident enough to move to the automated programming.

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

Re: Commentary track

Post by rednoah »

If you're just checking for a keyword, then this should work just as well:

Code: Select all

audio.title =~ /Commentary/ ? 'COMMENTARY' : null
or

Code: Select all

'Commentary' in audio.title ? 'COMMENTARY' : null
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1046
Joined: 15 May 2014, 16:17

Re: Commentary track

Post by kim »

FYI:
this does not work

Code: Select all

Binding "title": undefined
why does the e.g. GUI fail at this when it does not if in the htpc.groovy ?
https://github.com/filebot/scripts/blob ... roovy#L277

I think it will just ignore it ?

so what I'm saying is why not make it report errors but keep going ?
User avatar
rednoah
The Source
Posts: 19140
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Commentary track

Post by rednoah »

kim wrote: 18 Nov 2020, 19:21 FYI:
this does not work

Code: Select all

Binding "title": undefined
Strange. I'll look into it. This behaviour should not apply to properties.


EDIT: Yep. We incorrectly throw an error when we encounter an audio stream where title is undefined. I guess title is one of the view properties that may be defined for some audio streams but not others. My test file had a title for each audio track, so it didn't encounter the issue. Fixed with FileBot r8185.


kim wrote: 18 Nov 2020, 19:21 why does the e.g. GUI fail at this when it does not if in the htpc.groovy ?
https://github.com/filebot/scripts/blob ... roovy#L277
{audio} is not related to this code, and this code is not related to {audio}, other than MediaInfo being use internally at some point.
:idea: Please read the FAQ and How to Request Help.
jerome
Posts: 12
Joined: 25 Feb 2019, 02:21

Re: Commentary track

Post by jerome »

I tested various snippets on some of my files and I can say that these two fail to recognise "Commentary" in the title when it is written in lowercase as "'commentary"
audio[0].title =~ /Commentary/ ? 'Commentary' : null
'Commentary' in audio[0].title ? 'Commentary' : null

However, either of these two snippets extracted the correct answer for both lowercase or uppercase "Commentary" in the title
audio[0].title =~ /(?i:Commentary)/ ? 'Commentary' : null
audio[0].title =~ /Commentary|commentary/ ? 'Commentary' : null

So the "binding not defined" error would also explain why I'm getting inconsistent results with another snippet of code I'm testing. I'm on Windows 10 and I usually use the msi package to install updates. How would I update filebot for the latest beta release? I see a bunch of files in the Beta folder but none are msi.

Thanks
J
kim
Power User
Posts: 1046
Joined: 15 May 2014, 16:17

Re: Commentary track

Post by kim »

I'm 99% sure audio[0] (track 1) never has "Commentary"

?i = case-insensitive

viewtopic.php?f=7&t=1609


maybe try this to find missing

Code: Select all

{(audio.size() > 1) ? audio[1].Format == 'AC-3' && audio[1].channels == '2' ? 'Possible Commentary track' : '' : ''}
jerome
Posts: 12
Joined: 25 Feb 2019, 02:21

Re: Commentary track

Post by jerome »

Kim

That was just a sample code based on the first audio track. I actually test each audio track, up to 5, as I expect that would likely be the max.

Sorry for causing a misunderstanding.

I checked the links you posted and I think my annual license purchases are directly from FIlebot because the emails say payment processed through paddle.com. I will try and attempt the portable installation.

Again, appreciate all the help on these forums.

J
Post Reply