Custom code to guess media source based on file size and video bit rate

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc
Post Reply
User avatar
eurotrato
Posts: 4
Joined: 20 Oct 2021, 09:52

Custom code to guess media source based on file size and video bit rate

Post by eurotrato »

Hi there. I have this code that does not work with version 4.9.4

I want to select multimedia by format and bitrate. Or even format, video bitrate and file size.

Code: Select all

{ny} - 

{  (hd == 'SD' && vf == '240p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1.1e6d ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
   (hd == 'SD' && vf == '360p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1.1e6d ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
   (hd == 'SD' && vf == '480p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1.1e6d ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
   (hd == 'SD' && vf == '576p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1.1e6d ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :

   ((hd == 'HD') ?
          (((bytes/1073741824).round(0) > 0 && bitrate >= 18e6 ? 'BDRemux' :
            (bitrate > 8e6) ? {any{text.size()}{0} > 0 ? 'BDRip':'BDRip'} :
            (bitrate > 2.2e6) ? {any{text.size()}{0} > 0 ? 'MicroHD':'MicroHD'} :
            {any{text.size()}{0} > 0 ? 'HDRip':'HDRip'})) :
                        
    (hd == 'UHD') ?
          (((bytes/1073741824).round(1) > 0 && bitrate >= 32e6d ? 'UHDRemux' :
            (bitrate > 16e6d) ? {any{text.size()}{0} > 0 ? 'UHDRip':'UHDRip'} :
            {any{text.size()}{0} > 0 ? 'MicroUHD':'MicroUHD'}))
}

Another alternative, but format is missing (480p, 720p, 1080p, etc):

Code: Select all

{
	if (bitrate > 18e6)
		" BDRemux"
	else if (bitrate > 5e6)
		" BDRip"
	else if (bitrate > 1.5e6)
		" MicroHD"
	else
		""
}

Thanks for the help.
User avatar
rednoah
The Source
Posts: 20271
Joined: 16 Nov 2011, 08:59

Re: I'm doing something wrong

Post by rednoah »

{bytes} and {bitrate} are no longer simple Number objects, so you might need to update your custom format a little bit. See linked post for details:
viewtopic.php?p=55485#p55485


:!: Note that your format is also syntactically incorrect, which is unrelated to {bytes} and {bitrate}, somewhere in that incomprehensible sequence of nested ternary expressions:

Code: Select all

SyntaxError: expecting ':', found ''

:?: Did you write the code yourself for your specific purpose or did you copy & paste it from somewhere? The code above seems to guess source media based on resolution / file size / video length. However, source media bindings {vs} and {source} is probably more suitable for typical use cases where you can guess the source media from the file path.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 20271
Joined: 16 Nov 2011, 08:59

Re: Custom code to guess media source based on file size and video bit rate

Post by rednoah »

I'd rewrite the code in a more human-readable manner like so:

Code: Select all

{
	if (hd == 'SD')
		if (bytes.MB >= 700 && bitrate.mbps >= 1.1)
			return 'DVDRip'
		else
			return 'TVRip'

	if (hd == 'HD')
		if (bytes.GB >= 1 && bitrate.mbps >= 18)
			return 'BDRemux'
		else if (bitrate.mbps >= 8)
			return 'BDRip'
		else if (bitrate.mbps >= 2.2)
			return 'MicroHD'
		else
			return 'HDRip'

	if (hd == 'UHD')
		if (bytes.GB >= 1 && bitrate.mbps >= 32)
			return 'UHDRemux'
		else if (bitrate.mbps >= 16)
			return 'UHDRip'
		else
			return 'MicroUHD'
}
:idea: Please read the FAQ and How to Request Help.
User avatar
eurotrato
Posts: 4
Joined: 20 Oct 2021, 09:52

Re: I'm doing something wrong

Post by eurotrato »

Hi there. This is the correct code and working in version 4.8.5 and that in the new version it does not work:

Code: Select all

  { (hd == 'SD' && vf == '240p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1100000 ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
    (hd == 'SD' && vf == '360p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1100000 ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
    (hd == 'SD' && vf == '480p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1100000 ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :
    (hd == 'SD' && vf == '576p') ? ( ((bytes/1073741824).round(1) >= 0.7 && bitrate >= 1100000 ? 'DVDRip' : {any{text.size()}{0} > 0 ? 'TVRip':'TVRip'})) :

   ((hd == 'HD') ?
          (((bytes/1073741824).round(1) > 0 && bitrate >= 18000000 ? 'BDRemux' :
            (bitrate > 8000000) ? {any{text.size()}{0} > 0 ? 'BDRip':'BDRip'} :
            (bitrate > 2200000) ? {any{text.size()}{0} > 0 ? 'MicroHD':'MicroHD'} :
            {any{text.size()}{0} > 0 ? 'HDRip':'HDRip'})) :
                        
    (hd == 'UHD') ?
          (((bytes/1073741824).round(1) > 0 && bitrate >= 32000000 ? 'BDRemux' :
            (bitrate > 16000000) ? {any{text.size()}{0} > 0 ? 'BDRip':'BDRip'} :
            {any{text.size()}{0} > 0 ? 'MicroHD':'MicroHD'})) :

    (hd == 'HD' && vf == '10XXX80p' ?
            ((bytes/1073741824).round(1) > 5 && bitrate >= 18000000) ? 'BDRemux_1080p' :
            (bitrate > 8000000) ? {any{text.size()}{0} > 0 ? 'BDRip_720p':'BDRip_1080p'} :
            {any{text.size()}{0} > 0 ? 'BRRip_1080p_1':'BRRip_1080p_1'} :
            {any{text.size()}{0} > 0 ? 'BRRip_1080p_2':'BRRip_1080p_2'}))}
My knowledge is very poor and I only copy and paste script from other people.
I appreciate the help and that you serve as my guru.
Thanks if you can fix the transition of the new variables for me.

P.S. I use google translator from Spain and a registered version of the program. Thanks again.
User avatar
eurotrato
Posts: 4
Joined: 20 Oct 2021, 09:52

Re: Custom code to guess media source based on file size and video bit rate

Post by eurotrato »

:P You are a crack. In the end I have left the code like this:

Code: Select all

{
	if (hd == 'SD')
		if (bytes.MB >= 700 && bitrate.mbps >= 1.1)
			return 'DVDRip'
		else
			return 'TVRip'

	if (hd == 'HD' && vf == '720p')
		if (bytes.GB >= 0.1 && bitrate.mbps >= 18)
			return 'BDRemux'
		else if (bitrate.mbps >= 8)
			return 'BDRip'
		else if (bitrate.mbps >= 2.2)
			return 'MicroHD'
		else
			return 'HDRip'

	if (hd == 'HD' && vf == '1080p')
		if (bytes.GB >= 0.1 && bitrate.mbps >= 18)
			return 'BDRemux'
		else if (bitrate.mbps >= 8)
			return 'BDRip'
		else if (bitrate.mbps >= 2.2)
			return 'MicroHD'
		else
			return 'BRRip'

	if (hd == 'UHD')
		if (bytes.GB >= 0.1 && bitrate.mbps >= 32)
			return 'UHDRemux'
		else if (bitrate.mbps >= 16)
			return 'UHDRip'
		else if (bitrate.mbps >= 4)
			return 'MicroUHD'
		else
			return 'BRRip'

}
Thank you very much for the help. Without you I would not have made it.
User avatar
rednoah
The Source
Posts: 20271
Joined: 16 Nov 2011, 08:59

Re: Custom code to guess media source based on file size and video bit rate

Post by rednoah »

Why unnecessarily duplicate large swathes of code when just want to add an extra condition? :roll:

Code: Select all

{
  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 'MicroHD'
    else if (vf == '1080p')
      return 'BRRip'
    else
      return 'HDRip'

  if (hd == 'UHD')
    if (bytes.MB >= 100 && bitrate.mbps >= 32)
      return 'UHDRemux'
    else if (bitrate.mbps >= 16)
      return 'UHDRip'
    else if (bitrate.mbps >= 4)
      return 'MicroUHD'
    else
      return 'BRRip'
}
:idea: Please read the FAQ and How to Request Help.
User avatar
eurotrato
Posts: 4
Joined: 20 Oct 2021, 09:52

Re: Custom code to guess media source based on file size and video bit rate

Post by eurotrato »

Perfect. Thanks.
Post Reply