Group audio languages by audio codec

All about user-defined episode / movie / file name format expressions
Post Reply
Ultragian
Posts: 2
Joined: 03 Jun 2021, 21:28

Group audio languages by audio codec

Post by Ultragian »

Hello there,

I've been using Filebot for a while now and I have this "default" renaming code I made from multiple sources at some point. It is absolutely perfect to me, has the necessary amount of detail and looks clean.
The thing is, I never used a version other than 4.8.5 and below, and after trying version 4.9.3, which I liked because of the redesign and dark theme, it turned out that part of my code didn't work anymore, so I couldn't actually update and use it.

So why didn't I just fix this? Well, I have almost zero programming experience and, despite researching and reading the documentation, I don't understand how I should modify it. I got part of the code from different sources mind you.

This is the code: {n} - {e00} - {t} [{resolution} - {vc} - {audio.groupBy{ it.Codec }.collect{ c, a -> [c] + a*.Language }.join('.')}]

The result should be:
Image
(I modified the episode title naming a bit, not important though)

It adds a name, the episode number (not always), episode title, a bracket for the video resolution, the video codec, and groups the audio by codec along with the languages for each codec.

Now, the part that doesn't work in the newer versions is the audio codec part. In the image there, what you see as PCM/DTS-HD/DTS is output as NULL, and the grouping with the languages for each codec doesn't work, it just writes [null, ja, ja, ja, ja, ja], with "ja" being the language.

Like this:
Image

I believe some of the language used for coding changed at some point and part of the code doesn't work anymore because of it. That part being {audio.groupBy{ it.Codec }.collect{ c, a -> [c] + a*.Language }.join('.')}.

I hope someone would help me, thanks!
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Help migrating code to the new Filebot version

Post by rednoah »

1.
MediaInfo property Codec may be undefined, depending on the specific file and the specific version of libmediainfo used by FileBot:
viewtopic.php?t=4285

:idea: audio.Codec is undefined for me, for my very small set of test files at the very least.



2.
I'd rewrite your format like this:

Code: Select all

{
    kodi.derive{
        [
            resolution,
            vc,
            audio.groupBy{ a -> any{ a.Codec }{ a.Format }{ 'NA' } }
                 .collect{ c, a -> [c] + a*.Language }
                 .joiningDistinct('.')
        ].joining(' - ', ' [', ']')
    }.name
 }

TL;DR

Code: Select all

audio.groupBy{ a -> any{ a.Codec }{ a.Format }{ 'NA' } }.collect{ c, a -> [c] + a*.Language }.joiningDistinct('.')
any{ a.Codec }{ a.Format }{ 'NA' } ... pick whichever value is defined (to make it work across different files and different version of libmediainfo)
joiningDistinct ... join distinct values excluding null values and empty values (use joining if you want to retain duplicate values)
:idea: Please read the FAQ and How to Request Help.
Ultragian
Posts: 2
Joined: 03 Jun 2021, 21:28

Re: Group audio languages by audio codec

Post by Ultragian »

Wow, hey man, it's all working now!

I should probably learn programming at some point... Thanks for describing the code too hahahaha, I'm still a ways to go in understanding it all though, thanks a lot man!
Post Reply