Removing bracket [] when Audio Track title not found

All about user-defined episode / movie / file name format expressions
Post Reply
Mikuni
Posts: 2
Joined: 09 Feb 2023, 05:21

Removing bracket [] when Audio Track title not found

Post by Mikuni »

Hi everyone,

I use this code to extract the Audio Track Name from the video file. I prefer to use the track name because sometime he have more version of the same language like english and english British. The code work but when the file do not contain any Audio Track Name, the code put the bracket [] on the name even if I used the -null.

How can I remove the []?

Example With Audio Track: 1917 (2019) - MULTi[VFQ,VFF, ENG,GER] 2160p 10bit 4K Light HDR10 x265 AC3 5.1.mkv
Example Without Audio Track: 1917 (2019) - [] 2160p 10bit 4K Light HDR10 x265 AC3 5.1.mkv

Code: Select all

{audio.collect{ au -> any{au.title}{''} } - null}

Full Code that I used for the examples :

Code: Select all

{
	norm = {
		it
		.upperInitial()
		.lowerTrail()
		.replaceTrailingBrackets()
		.replaceAll(/[`´‘’ʻ""“”]/, "'")
		.replaceAll(/[:*?"<>|?]/)
		.replaceAll(':', ':')
		.replaceAll(/[?]/, "?")
	}
	 ;norm(n)
} 

({y}) -  
{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'} 
{
	if (audioLanguages.size() == 2)
		return "MULTi"
	if (audioLanguages.size() > 2)
		return "MULTi"
}


{audio.collect{ au -> any{au.title}{''} } - null}

{' '}
{vf}
{' '}
{' '}
{ bitdepth == 10 ? ' 10bit' : null }
{' '}
{
  if (hd == 'SD')
    if (bytes.MB >= 700 && bitrate.mbps >= 1.1)
      return 'DVDRip'
    else
      return 'TVRip'

  if (hd == 'HD')
    if (bytes.MB >= 100 && bitrate.mbps >= 18)
      return 'BDRemux'
    else if (bitrate.mbps >= 8)
      return 'BDRip'
    else if (bitrate.mbps >= 2.2)
      return 'HDLight'
    else if (vf == '1080p')
      return 'BRRip'
    else
      return 'HDRip'

  if (hd == 'UHD')
    if (bytes.MB >= 100 && bitrate.mbps >= 32)
      return '4K Remux'
    else if (bitrate.mbps >= 16)
      return '4K'
    else if (bitrate.mbps >= 3)
      return '4K Light'
    else
      return '4K BRRip'
}
{' '}{hdr}
{' '}{ video[0].CodecID =~ /HEVC/ ? 'x265' : 'H.264'}
{' '}{ac} 
{' '}{channels}
User avatar
rednoah
The Source
Posts: 22899
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Removing bracket [] when Audio Track title not found

Post by rednoah »

e.g.

Code: Select all

{ audio.title.joining(', ', '[', ']') }
:idea: The Collection.joining() extension method takes care of all the corner cases, ignore null values, fail on empty lists, etc.
:idea: Please read the FAQ and How to Request Help.
Mikuni
Posts: 2
Joined: 09 Feb 2023, 05:21

Re: Removing bracket [] when Audio Track title not found

Post by Mikuni »

Fantastic! Many thanks for responding so quickly and teaching me this new extension. This is exactly what I was looking for!
Post Reply