Trouble with audio channels

Any questions? Need some help?
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

Remove "eng" from the list:

Code: Select all

audioLanguages.ISO3 - 'eng'
:idea: Please read the FAQ and How to Request Help.
Morgenstern72
Donor
Posts: 39
Joined: 09 May 2014, 18:57

Re: Trouble with audio channels

Post by Morgenstern72 »

rednoah wrote: 25 Jul 2017, 09:07 Remove "eng" from the list:

Code: Select all

audioLanguages.ISO3 - 'eng'

What's the ISO3 for?

So instead of
{audioLanguages}

it would be
{audioLanguages.ISO3 - 'eng'}
?
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

audioLanguages will give you a list of Language objects, so for each Language object, we get the ISO3 property, that gives use a list of String objects, from which we can remove the String object "eng".
:idea: Please read the FAQ and How to Request Help.
Morgenstern72
Donor
Posts: 39
Joined: 09 May 2014, 18:57

Re: Trouble with audio channels

Post by Morgenstern72 »

rednoah wrote: 25 Jul 2017, 09:49 audioLanguages will give you a list of Language objects, so for each Language object, we get the ISO3 property, that gives use a list of String objects, from which we can remove the String object "eng".
Thank you for the explanation :)
For the nice support and the free upgrade o the new version as an early donor I just sent you another small donation. Thank you for your dedication :)
Silke79
Posts: 26
Joined: 11 Dec 2018, 22:13

Re: Trouble with audio channels

Post by Silke79 »

Could use some help to get this working as it should if it's possible to fix it.
I used copy past on most of the script to put this togetter and are not that good at this typ of writing, so bare that in mind when you answer this.
  • 1) First problem is when there are more then one sub fil with the same language tag and it want to give it CD1 and so on and not give it .eng and then eng.forced as it should have been.
  • 2) Is that srt subs don't get the right folder name when it's a DC, TC or Remastered that I could use some help with too.
  • 3) Is it possible when it's both a Remastered and DC to be able to get that in the folder name?
  • 4) And fix the problem when : shows in the name and change it to - instead.
Code I use for Movie/Anime

Code: Select all

Filmer/{n} {' ['+fn.replaceAll(/(?i)directors|theatrical|ultimate/,'$0 Cut').matchAll(/UNRATED|REMASTERED|EXTENDED|UNCUT|DIRECTORS.CUT|THEATRICAL.CUT|ULTIMATE.CUT|SPECIAL.EDITION/).join('][').upperInitial().lowerTrail()+']'} ({y}) {vf} {source} {gigabytes} {audioLanguages}/{n} ({y}) {' CD'+pi} - {dim} {vf} {vc} [{ac}{fn.match("-HD.MA.")}-{af}]{'.'+lang}
Result
Image
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
I'm not exactly sure what you try to do here. But if you have multiple subtitles for the same language for the same video file, then then accounting for that in your format is somewhat tricky.

The {subt} binding will give you .eng or .eng-forced so it's possible to have a pair of normal / forced subtitles, but that only works if the original file already has "forced" in the subtitle filename.


2.
Have you tried using {tags} instead? Your format explicitly checks the filename, so if the filename doesn't contain "UNRATED" then the destination path doesn't contain "UNRATED", which is the case for your badly named subtitle files.

:idea: {tags} will also check accompanying video files for tags, but I'm not sure if it'll work in your particular case, since video and subtitle files have completely different names in your particular case.


3.
Yes, just add another{tags} to your custom format, e.g.

Code: Select all

Movies/{ny} {tags}/{plex.name}

4.
{plex} does take care of that already. But there's a built-in convenience methods for that as well, e.g.

Code: Select all

{ny.colon(' - ')}
:idea: Please read the FAQ and How to Request Help.
Silke79
Posts: 26
Joined: 11 Dec 2018, 22:13

Re: Trouble with audio channels

Post by Silke79 »

Thanks rednoah

Got most of the problem fixed, but not #1 and that I can managed manually if need be.

But I stumble upon a new problem with my choice of having {gigabytes} in the script when I get movie folders/files that have CD1, CD2 and so on and it then makes a new folder for every CD1, CD2 and so on based on the files size and I would like it to put all in the same folder instead and if possible calculate the total size at the end of the main folder?

How I changed the script

Code: Select all

Movies/{n.colon(' - ')} {tags} ({y}) {vf} {source} {gigabytes} {audioLanguages}/{ny.colon(' - ')} - [{resolution}] [{vf} & {vc}] [{ac}{fn.match("-HD.MA.")}-{af}]{' CD'+pi}{'.'+lang}
BTW are there a more elaborated page then this one that go deeper in how scripts works in Filebot and how to change and to be able to write them yourself and learn how to?
https://www.filebot.net/naming.html

I tried to use this script with {plex.name}, but there was one problem that it put the sub files lang tag before this [{resolution}] [{vf} & {vc}] [{ac}{fn.match("-HD.MA.")}-{af}] and I need the lang tag at the end for it to work.

Code: Select all

Filmer/{n.colon(' - ')} {tags} ({y}) {vf} {source} {gigabytes} {audioLanguages}/{plex.name} - [{resolution}] [{vf} & {vc}] [{ac}{fn.match("-HD.MA.")}-{af}]
BTW is it possible for Filebot to have more then on script for Movies, Music, Episods?
For example I got anime on one HDD, movies on another HDD and so on to make it easier for me, but I use different scripts when i'm om the HDD with anime then I do on the HDD with movies or Episodes.
So it could be nice when i'm naming on my Anime HDD it change to that script and the one I use for my Movie HDD and so on automatically.

Otherwise a great program, but a few things for the next update I would like to see would be a color setup for different file so one easy can see what typ of file it is instead of the Yellow background and Black font as it is now.
Don't know if this is with my Windows 10 or it is the program itself, but it could be nice if the pop up screen you get when going into Edit Format stay at the size I had last time and is not go back to the small one every time.
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
FileBot provides the data, but the code is effectively Groovy, which runs on top of the Java runtime, so you can do anything, and any Groovy or Java skills will help you understand and write FileBot format expressions.

Unfortunately, there's no "easy advanced" tutorial for writing Groovy code with FileBot format expressions in mind specifically.

In this case, {folder} is a FileBot binding, but everything else is just plain Groovy code and Java File API:

Code: Select all

{(folder.listFiles()*.length().sum() / 1e9).round(1) + " GB"}

2.
The File.derive(Closure...) method takes care of adding additional information after the name but before the extension part:

Code: Select all

{plex.derive{" by $director"}{" [$vf, $vc, $ac]"}}

3.
You can make Presets for different use cases. Alternatively, you can have your format be smart enough to just do different things depending on where the files are located. Ideally, once set up, you won't have to modify your format ever again.
:idea: Please read the FAQ and How to Request Help.
Silke79
Posts: 26
Joined: 11 Dec 2018, 22:13

Re: Trouble with audio channels

Post by Silke79 »

Thanks ones more for your patience rednoah with me. :D

I guess i'm again doing something wrong because with the new path you posted to me and I put into the script I use I get the problem that it will give me a folder from everything with different size as can be seen on the picture I put here.

Next problem is that the Plex path will give me the sub folder Movies that I don't like to have there.

New mod on the script

Code: Select all

Movies/{n.colon(' - ')} {tags} ({y}) {vf} {source} {(folder.listFiles()*.length().sum() / 1e9).round(1) + " GB"}/{plex.derive{" [$resolution]"}{" [$vf-$vc] [$ac-$af]"}}
New Problem
Image
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
Strange indeed. My code assumes that video and subtitle files are in the same folder, which may or may not be the case for you.

You could do something like this for testing, to see the file list for each folder, which should be the same for files that are in the same folder:

Code: Select all

{folder.listFiles()*.name}
:idea: If you provide more detailed information (i.e. full file paths) then I may be able to help you write code that works for you.


2.
Using standard folder names is highly recommended, however, you can pick the path tail like so:

Code: Select all

{plex.tail}
:idea: viewtopic.php?f=5&t=4116
:idea: Please read the FAQ and How to Request Help.
Silke79
Posts: 26
Joined: 11 Dec 2018, 22:13

Re: Trouble with audio channels

Post by Silke79 »

The subtitles are in a sub folder when you have media that's from RARBG, but you have it in the main folder V:\Rocky.1976.REMASTERED.1080p.BluRay.H264.AAC-RARBG\Sub.
I tried moving the subtitle to the main folder and then the script worked with putting it all in the same main folder, but you still got the same problem with Plex path putting a \Movies\Rocky (1976)\ with the folders that I don't want.

This is what I get.
V:\Filmer\Rocky [Remastered] (1976) 1080p BluRay 2.5 GB\Movies\Rocky (1976)\Rocky (1976) [1920x1040] [1080p-x264] [AAC-6ch].MP4

V:\Filmer\Rocky [Remastered] (1976) 1080p BluRay 0.0 GB\Movies\Rocky (1976)\Rocky (1976) [1920x1040] [1080p-x264] [AAC-6ch].srt

This is what I get in the Edit Format.
Filmer/Avatar [Remastered] (2009) 1080p BluRay 0.0 GB/Movies/Avatar (2009)/Avatar (2009) CD1 [1920x1040] [1080p-x264] [AAC-6ch]

This is what I would like it to do
Filmer\Rocky [Remastered] (1976) 1080p BluRay 2.5 GB\Rocky (1976) [1920x1040] [1080p-x264] [AAC-6ch].MP4

Filmer\Rocky [Remastered] (1976) 1080p BluRay 2.5 GB\Rocky (1976) [1920x1040] [1080p-x264] [AAC-6ch].eng.srt

This is the script I need help fixing so it might do what I want in the end.

Code: Select all

Filmer/{n.colon(' - ')} {tags} ({y}) {vf} {source} {folder.listFiles()*.name}/{plex.derive{" [$resolution]"}{" [$vf-$vc] [$ac-$af]"}}
So if you could help me fixing the script to work as I want it to work I would be very happy for the help.
That it will work even if the subtitles are in a sub folder and be able to put in if it's Remastered, DC and so on when that is in the Folder/File name.
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
This code will take all the matches currently loaded into FileBot, find the ones that match the current match by id, and then sum all the file sizes:

Code: Select all

model.findAll{ it.id == id }.file.length.sum()
So here's the format snippet for that, formatted as 0.0 GB value:

Code: Select all

{def size = model.findAll{ it.id == id }.file.length.sum(); (size / 1e9).round(1) + ' GB'}

2.
This snippet will give you the REMASTERED|DC value if the file path contains that value:

Code: Select all

{f.path.match(/REMASTERED|DC/)}
:!: The obvious limitation being that this doesn't work if REMASTERED does not appear in the full path of the subtitle file (i.e. it'll work for the use case you have given, but may not work for other use cases you have not given).


3.
This snippet will give you the file name part of the Plex path:

Code: Select all

{plex.derive{" [$resolution]"}{" [$vf-$vc] [$ac-$af]"}.name}
:idea: Please read the FAQ and How to Request Help.
Silke79
Posts: 26
Joined: 11 Dec 2018, 22:13

Re: Trouble with audio channels

Post by Silke79 »

Thanks for all the help I got from you rednoah :D

It works great for me so far after I have tested a few different typs of file and folders with DC and not and other media files.

For my Anime Movies

Code: Select all

Anime/{n.colon(' - ')} {tags} ({y}) {vf} {source} {def size = model.findAll{ it.id == id }.file.length.sum(); (size / 1e9).round(1) + ' GB'} {imdbid} {audioLanguages}/{plex.derive{" [$resolution]"}{" [$vf-$vc] [$ac-$af]"}.name}
Example
Anime\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) 1080p BluRay 4.1 GB tt2210479 [jpn]\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) [1920x816] [1080p-x264] [FLAC-6ch]

Anime\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) 1080p BluRay 4.1 GB tt2210479 [jpn]\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) [1920x816] [1080p-x264] [FLAC-6ch].eng

Regular Movies

Code: Select all

Movies/{n.colon(' - ')} {tags} ({y}) {vf} {source} {def size = model.findAll{ it.id == id }.file.length.sum(); (size / 1e9).round(1) + ' GB'} {imdbid}/{plex.derive{" [$resolution]"}{" [$vf-$vc] [$ac-$af]"}.name}
Example
Movie\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) 1080p BluRay 4.1 GB tt2210479\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) [1920x816] [1080p-x264] [FLAC-6ch]

Movie\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) 1080p BluRay 4.1 GB tt2210479\Berserk - The Golden Age Arc 1 - The Egg of the King (2012) [1920x816] [1080p-x264] [FLAC-6ch].eng

BTW are there some why when you are renaming documentaries to have the company that made it, like BCC?
kim
Power User
Posts: 1027
Joined: 15 May 2014, 16:17

Re: Trouble with audio channels

Post by kim »

only if in path name or in

Code: Select all

{info.productionCompanies}
ca81
Posts: 18
Joined: 14 Dec 2019, 20:08

Re: Trouble with audio channels

Post by ca81 »

Hi,

I have a file with multiple audio tracks and each track is of a different language, has a different codec and different number of channels.

I am a noob at Groovy and after going through multiple forum posts, I am using the code

Code: Select all

{"$channels-$ac"}-{audioLanguages.ISO3B*.upper().joining('-')}
The 1st part of the above code give me the audio channels and codec only for the 1st audio track and the 2nd part gives me the languages for each of audio tracks in the file.

Can someone please help me get the channels & codec info for each of the audio tracks similar to the way I am able to get the audio language for each of the audio tracks?

I tried the code

Code: Select all

{audios.collect{it.channels} '-' {it.CodecFamily} '-' {it.language}.join(' + ')}
but unfortunately this code does not give me anything and even the information that I was getting with the prior code is lost :(

also, can someone please advise if I need to use ISO3B* or can I simply use ISO3

thanks,
~kg
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
You may access arbitrary MediaInfo properties for any number of streams via the {audio} top-level binding:
viewtopic.php?t=4285

e.g.

Code: Select all

{audio.Codec}

Code: Select all

{audio.Channels}

Code: Select all

{audio.Language}

Image


2.
ca81 wrote: 30 Aug 2020, 21:16 can someone please advise if I need to use ISO3B* or can I simply use ISO3
This largely depends on your preferences, and expectations of 3rd party programs that will be interpreting your file names. If you're using Plex, then ISO 639-2/B (i.e. Language.ISO3B) is recommended. That being said, it generally doesn't matter, unless you're Dutch.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1027
Joined: 15 May 2014, 16:17

Re: Trouble with audio channels

Post by kim »

Look here:
viewtopic.php?f=5&t=5285&p=51634#p48827

you can use

Code: Select all

allStreams.join(' & ').space('.')
but I do not recommend it as it can get very long, so maybe just use

Code: Select all

allStreams.take(3).join(' + ')
btw:

Code: Select all

{audios.collect{it.channels} '-' {it.CodecFamily} '-' {it.language}.join(' + ')}
"FIX"

Code: Select all

{audio.collect{it.channels + '-' + it.Format + '-' + it.language}.join(' + ')}
ca81
Posts: 18
Joined: 14 Dec 2019, 20:08

Re: Trouble with audio channels

Post by ca81 »

Thanks @rednoah / @kim for your kind suggestions.

After posting my code snippet yesterday, I have made some changes to the code as I realized that I need to get the information for only the 1st & 2nd Audio streams (only if 2nd audio stream is present) and not for any additional audio streams.

Updated code snippet below:

Code: Select all

{audioLanguages[0].ISO3.upper()}-{Channels}-{ac}
{audio.size() > 1 ? ' + ' : null}
{audio.size() > 1 ? audio[1].Language.upper() : null}
{audio.size() > 1 ? '-' : null}
{audio.size() > 1 ? audio[1].Channels : null}
{audio.size() > 1 ? '-' : null}
{audio.size() > 1 ? audio[1].Format : null}, 
to get the filename output as "JPN-2.0-Opus + EN-2-Opus"

I am testing this code with a media file for which the MediaInfo details are pasted below:
Audio #1
ID : 2
Format : Opus
Codec ID : A_OPUS
Duration : 24 min 29 s
Bit rate : 100 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 50.001 FPS (960 SPF)
Compression mode : Lossy
Delay relative to video : -7 ms
Stream size : 17.5 MiB (9%)
Title : Audio 1
Language : Japanese
Default : No
Forced : No

Audio #2
ID : 3
Format : Opus
Codec ID : A_OPUS
Duration : 24 min 28 s
Bit rate : 93.9 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 50.000 FPS (960 SPF)
Compression mode : Lossy
Delay relative to video : -7 ms
Stream size : 16.4 MiB (8%)
Title : Audio 2
Language : English
Default : Yes
Forced : No



Now the issues with the above code snippet:
  • {audioLanguages[0].ISO3.upper()} works properly and gives me 'JPN' as the output but somehow if I use {audio[1].Language.ISO3.upper()} I get a blank output and ISO3 seems to work only when I use audioLanguages[1] and not audio[1].Language. Am I doing something wrong?
  • {Channels} provides the output as '2.0' but if I use audio[0].Channels or audio[1].Channels then I get the output as '2'. Any suggestions on how I can get the full audio setup i.e. '2.0' in this case?
  • As I am a noob at Groovy, I am using a crude multi-line code for the 'if' condition. If there any way to make it better?
thanks,
~kg

ps: I am using Plex but this part of the filename is not read by Plex as I've put it inside [square brackets]. I want this information in the filename mainly so that I can easily identify the important attributes of the media file without needing to open the file via MediaInfo...
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

1.
{audioLanguages} and {channels} are top-level bindings that look at various raw MediaInfo properties from all streams to give you the structured information you likely want to see.

:idea: audioLanguages will give you structured Language objects, as opposed to audio.language which will give you String objects. Language objects have properties such as Language.ISO3 while String objects do not.

:idea: channels is inferred based on interpreting the ChannelLayout properties of all streams. Replicating the code is possible but non-trivial.


2.
Keeping things simple, this will get you most of what you want with minimal effort:

Code: Select all

{
	audio.take(2).collect{ a -> allOf
		{ a.Language.upper() }
		{ a.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1') }
		{ a.Format }
	}.join(' + ')
}
Result:

Code: Select all

[EN, 2.0, AC-3] + [JA, 2.0, AC-3]
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1027
Joined: 15 May 2014, 16:17

Re: Trouble with audio channels

Post by kim »

with Language_String3

Code: Select all

{
	audio.take(2).collect{ a -> allOf
		{ a.Language_String3.upper() }
		{ a.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1') }
		{ a.Format }
	}.join(' + ')
}
ca81
Posts: 18
Joined: 14 Dec 2019, 20:08

Re: Trouble with audio channels

Post by ca81 »

Many thanks @rednoah / @kim !!!

One small question to make this code ideal for me...

Code: Select all

{
	audio.take(2).collect{ a -> allOf
		{ a.Language_String3.upper() }
		{ a.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1') }
		{ a.Format }
	}.join(' + ')
}
The output I get for my test file is [JPN, 2.0, Opus] + [ENG, 2.0, Opus].....in this output is it possible to replace the comma+space (, ) with a hyphen (-) and the [square brackets] with (round brackets) ???

thanks,
~kg
User avatar
rednoah
The Source
Posts: 18985
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Trouble with audio channels

Post by rednoah »

e.g.

Code: Select all

{
	audio.take(2).collect{ a -> allOf
		{ a.Language_String3.upper() }
		{ a.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1') }
		{ a.Format }
	}*.joining('-', '(', ')').join(' + ')
}
:idea: Please read the FAQ and How to Request Help.
ca81
Posts: 18
Joined: 14 Dec 2019, 20:08

Re: Trouble with audio channels

Post by ca81 »

rednoah wrote: 02 Sep 2020, 02:18 e.g.

Code: Select all

{
	audio.take(2).collect{ a -> allOf
		{ a.Language_String3.upper() }
		{ a.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1') }
		{ a.Format }
	}*.joining('-', '(', ')').join(' + ')
}
this is super awesome!!!

many thanks,
~kg

ps: Until this I did not realize join() and joining() were different...another small step for my Groovy learnings
Post Reply