Conditional Structures (if-then-else)

All about user-defined episode / movie / file name format expressions
Locked
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Conditional Structures (if-then-else)

Post by rednoah »

You can use if-then-else blocks or the ternary operator for conditional code.


e.g. Move 3D movies and normal movies into different folders:

Format: Select all

{ fn =~ /3D/ ? '3D Movies' : 'Movies' }

e.g. Move Anime movies and normal movies into different folders:

Format: Select all

{ anime ? 'Anime Movies' : 'Movies' }

e.g. Move Anime episodes and normal TV series episodes into different folders:

Format: Select all

{ anime ? 'Anime' : 'TV Shows' }

e.g. Add [Dual Audio] to files that have multiple audio streams including at least one English audio stream:

Format: Select all

{ audio.size() > 1 && audio.Language =~ /en/ ? ' [Dual Audio]' : null }

e.g. Select files with Japanese audio and SubStation Alpha subtitles (i.e. custom Anime detection) and sort them into a dedicated Anime folder:

Format: Select all

{ audio.Language =~ /ja/ && text.Format =~ /ASS|SSA/ ? 'Anime' : 'TV Shows' }

e.g. Move Documentary episodes and normal TV series episodes into different folders:

Format: Select all

{ genre ==~ /Documentary|News/ ? 'Documentaries' : 'TV Shows' }

e.g. Move 4K movies and normal movies into different folders:

Format: Select all

{ height > 2000 ? '4K Movies' : 'Movies' }

e.g. Add [10bit] to 10-bit videos but not to 8-bit videos:

Format: Select all

{ if (bitdepth == 10) ' [10bit]' }

Format: Select all

{ bitdepth == 10 ? ' [10bit]' : null }

e.g. Add the original name in parenthesis if the original name is different from the name in the preferred language:

Format: Select all

{ n == primaryTitle ? n : n + ' (' + primaryTitle + ')' }

e.g. Sort movies into folders by collection if the movie belongs to a collection or genre folders if not:

Format: Select all

{ any{ collection }{ genre }{ 'No Genre' } }
:idea: The any(Closure...) function will call each of the given Closures until it finds one that yields a non-empty result.


e.g. Sort movies from different years into different destination folders:

Format: Select all

{
	if (y < 1960) {
		return "M:/Old Movies"
	} else if (y < 2000) {
		return "N:/Classic Movies"
	} else if (y < 2020) {
		return "O:/Modern Movies"
	} else {
		return "P:/New Movies"
	}
}
:idea: Use the @file syntax for reading command-line arguments from external text files.





:!: Bindings and functions may throw exceptions so the result may be neither one value nor another:

Format: Select all

{ 'Avatar'.match(/3D/) ? 'X' : 'Y' } ⇨ Exception: Pattern not found
:idea: Please read the FAQ and How to Request Help.
Locked