Sort movies by its video bitrate

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc
Post Reply
darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Sort movies by its video bitrate

Post by darchap » 14 Mar 2019, 12:45

Hello im trying to sort my movies by its video bitrate. Right now im able to sort by its video+audio bitrate but i only want video bitrate. with this code im able to sort them into different folders with entire bitrate:

Code: Select all

{vf =~ /2160p|4K|4k|UHD/ ? "4K" : fn =~ /3D|3d|3dhsbs|H-SBS|3dhou|H-OU/ ? "3D" :genres =~ /Animado|Cartoon|Animación/ ? "Dibujos" :vf == "1080p" ? (bitrate / 1e6d).round(1) > 7.0 ? "1080p": "m1080p":(bitrate / 1e6d).round(1) > 4.0 ? "720p": "SD"}
And with this one im able to get isolated video bitrate:

Code: Select all

{  def A = audio.size ;
   def V = video.bitrate;
if (V.toString().substring(1,V.toString().indexOf("]"))!= "null") 
{(V.toString().substring(1,V.toString().indexOf("]")).toFloat() / 1e6d).round(1) }  
else{ 
		if (A >= 1 && A < 2)  
		return (     (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )    )/1e6d).round(1)
        ;
		if (A >= 2 && A < 3) 
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;
		if (A >= 3 && A < 4)		 	
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )  
					 -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;
		if (A >= 4 && A < 5)
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[3].bitrate == null ? 0 : audio[3].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;			 
		if (A >= 5 && A < 6)
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[3].bitrate == null ? 0 : audio[3].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  
					 -(audio[4].bitrate == null ? 0 : audio[4].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
}}mbps
My problem is i dont know how to get it working, i can get the video bitrate in movie title but cant use that code to sort movies. Any help would be appreciated.

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

Re: Sort movies by its video bitrate

Post by rednoah » 14 Mar 2019, 16:17

1.
Not sure what you mean.

Here's how you can get the bitrate from the first video stream, converted from String to Integer so you can do numerical comparisons:

Code: Select all

def b = video[0].bitrate as int

2.
Any Groovy code can be used as format expression, and whatever value your Groovy code yields, that's what FileBot will use for the destination path.
:idea: Please read the FAQ and How to Request Help.

darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Re: Sort movies by its video bitrate

Post by darchap » 14 Mar 2019, 19:25

rednoah wrote:
14 Mar 2019, 16:17
1.
Not sure what you mean.

Here's how you can get the bitrate from the first video stream, converted from String to Integer so you can do numerical comparisons:

Code: Select all

def b = video[0].bitrate as int

2.
Any Groovy code can be used as format expression, and whatever value your Groovy code yields, that's what FileBot will use for the destination path.
Thanks for your reply, ill try to explain it a lil bit better.

I have this code that is actually working:

Code: Select all

{vf =~ /2160p|4K|4k|UHD/ ? "4K" : fn =~ /3D|3d|3dhsbs|H-SBS|3dhou|H-OU/ ? "3D" :genres =~ /Animado|Cartoon|Animación/ ? "Dibujos" :vf == "1080p" ? (bitrate / 1e6d).round(1) > 7.0 ? "1080p": "m1080p":(bitrate / 1e6d).round(1) > 4.0 ? "720p": "SD"}

that code sorts any film into different folders depending on its vf and its bitrate. the problem is if i have(example):

-Avatar [1080p][EN+ES+FR] and 7.1mbps of bitrate provided by this command (bitrate / 1e6d).round(1)

FB would move this film into "1080p" folder as of the command that i explained, BUT thats not the real video bitrate because if i have exactly the same video file with only one audio language:

-Avatar [1080p][EN]

if i apply this command (bitrate / 1e6d).round(1) it gonna return me a lower bitrate value, therefore FB would move this film into "m1080p" folder instead. Do yo know what i mean?



So, second part. Im able to get the video bitrate to avoid that problem, with this following code

Code: Select all

{  def A = audio.size ;
   def V = video.bitrate;
if (V.toString().substring(1,V.toString().indexOf("]"))!= "null") 
{(V.toString().substring(1,V.toString().indexOf("]")).toFloat() / 1e6d).round(1) }  
else{ 
		if (A >= 1 && A < 2)  
		return (     (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )    )/1e6d).round(1)
        ;
		if (A >= 2 && A < 3) 
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;
		if (A >= 3 && A < 4)		 	
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )  
					 -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;
		if (A >= 4 && A < 5)
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[3].bitrate == null ? 0 : audio[3].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
		;			 
		if (A >= 5 && A < 6)
		return (  (  (bitrate-(audio[0].bitrate == null ? 0 : audio[0].bitrate.substring (audio[0].bitrate.indexOf("/")+1).toFloat()     )
                     -(audio[1].bitrate == null ? 0 : audio[1].bitrate.substring (audio[1].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[2].bitrate == null ? 0 : audio[2].bitrate.substring (audio[2].bitrate.indexOf("/")+1).toFloat()     )    
			         -(audio[3].bitrate == null ? 0 : audio[3].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  
					 -(audio[4].bitrate == null ? 0 : audio[4].bitrate.substring (audio[3].bitrate.indexOf("/")+1).toFloat()     )  )  )/1e6d).round(1)
}}mbps
My problem is i dont know how to apply that big code to replace the (bitrate / 1e6d).round(1) expression here:

Code: Select all

{vf =~ /2160p|4K|4k|UHD/ ? "4K" : fn =~ /3D|3d|3dhsbs|H-SBS|3dhou|H-OU/ ? "3D" :genres =~ /Animado|Cartoon|Animación/ ? "Dibujos" :vf == "1080p" ? (bitrate / 1e6d).round(1) > 7.0 ? "1080p": "m1080p":(bitrate / 1e6d).round(1) > 4.0 ? "720p": "SD"}

darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Re: Sort movies by its video bitrate

Post by darchap » 14 Mar 2019, 20:07

Heres a real example of the problem:
Image

That movie is in "1080p" folder, BUT as you can read in the title says 5.0mbps (provided by the big code i posted, not this one (bitrate / 1e6d).round(1)).

So actually it should be in m1080p folder, but as sorted by this expression (bitrate / 1e6d).round(1) means that bitrate its bigger than 7.0 because of this command

Code: Select all

{vf =~ /2160p|4K|4k|UHD/ ? "4K" : fn =~ /3D|3d|3dhsbs|H-SBS|3dhou|H-OU/ ? "3D" :genres =~ /Animado|Cartoon|Animación/ ? "Dibujos" :vf == "1080p" ? (bitrate / 1e6d).round(1) > 7.0 ? "1080p": "m1080p":(bitrate / 1e6d).round(1) > 4.0 ? "720p": "SD"}
while in reality the bitrate is 5.0

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

Re: Sort movies by its video bitrate

Post by rednoah » 15 Mar 2019, 04:21

Well, {...} is all the same to FileBot, no matter if it's a few characters or half a page of code. Since your code is messy and unmaintainable, I can't help you fix it. That being said. If I knew what you were trying to do, then I could probably help rewrite the code in a more readable manner.

:?: You want the video bitrate? Or the audio bitrate? Or the maximum bitrate of all video bitrates + maximum bitrate of all audio bitrates?
:idea: Please read the FAQ and How to Request Help.

darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Re: Sort movies by its video bitrate

Post by darchap » 15 Mar 2019, 05:53

I want to sort my movies into folders, by video bitrate only, not video+audio bitrate(this is what i get with (bitrate / 1e6d).round(1))

So, as i said a few post ago, this command works, but sort my movies by its video+audio bitrate, and i only want video bitrate

Code: Select all

{vf =~ /2160p|4K|4k|UHD/ ? "4K" : fn =~ /3D|3d|3dhsbs|H-SBS|3dhou|H-OU/ ? "3D" :genres =~ /Animado|Cartoon|Animación/ ? "Dibujos" :vf == "1080p" ? (bitrate / 1e6d).round(1) > 7.0 ? "1080p": "m1080p":(bitrate / 1e6d).round(1) > 4.0 ? "720p": "SD"}
Thanks @rednoah

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

Re: Sort movies by its video bitrate

Post by rednoah » 15 Mar 2019, 06:26

Here's an example for that:

Code: Select all

{
	def vbr = (video[0].bitrate.toInteger() / 1e6).round(1)
	vbr > 4.0 ? "720p" : "SD"
}
:idea: Please read the FAQ and How to Request Help.

darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Re: Sort movies by its video bitrate

Post by darchap » 15 Mar 2019, 06:59

Thank you so much, will try that an report my results

darchap
Posts: 6
Joined: 14 Mar 2019, 12:34

Re: Sort movies by its video bitrate

Post by darchap » 18 Mar 2019, 17:34

Working like a charm, i had to modify the line but now works. Thank you @rednoah

Code: Select all

(video[0].bitrate.toInteger() / 1e6d).round(1)

Post Reply