Single genre from genre list by priority??

All about user-defined episode / movie / file name format expressions
Post Reply
skrowl
Posts: 2
Joined: 06 Oct 2014, 22:52

Single genre from genre list by priority??

Post by skrowl »

I'm trying to categorize a bunch of movies into single genre folders.

For example X:\Science Fiction\Avatar (2012).mkv

I'd like to set up a priority system to determine which "wins" and gets to become the folder name.

For example:
  • If genres contains "Romance" then it gets folder name "Chick Flick"
  • If not, but genres contains "Horror" then it gets folder name "Horror"
  • If not, but genres contain "Science Fiction" then it gets folder name "Science Fiction"
  • and so on and so forth
Basically, I'm trying to find ONE "main" or "it fits this best" genre for a movie vs "It falls in to like 8 genres, here's a big list", because just about everything get "Action" or "Drama" or "Thriller" even if they're really Horror or Sci Fi movies.

Any idea how to do that?
User avatar
rednoah
The Source
Posts: 23017
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Single genre from genre list by priority??

Post by rednoah »

Lots of examples here in the forums somewhere.

genres.contains('something') ? A : B
:idea: Please read the FAQ and How to Request Help.
skrowl
Posts: 2
Joined: 06 Oct 2014, 22:52

Re: Single genre from genre list by priority??

Post by skrowl »

rednoah wrote:Lots of examples here in the forums somewhere.

genres.contains('something') ? A : B
A ternary operator like that is nice if I only had 2 options, but I basically need an if / else if / else if / else if / else.

if genres contain "Romance" then folder name is "Chick Flick"
else if genres contain ....

Nesting the ternary doesn't appear to work

Code: Select all

{genres.contains('Romance') ? 'Chick Flick' : {genres.contains('Animation') ? 'Animation' : 'Nope'} }
Yields

Script106$_run_closure1@6612fddc

I think I figured out the if syntax:

Code: Select all

X:\Array\Movies\{
	if (genres.contains('Romance')) {'Chick Flick'}
	else if (genres.contains('Animation')) {'Animation'}
	else if (genres.contains('Horror')) {'Horror'}
	else if (genres.contains('Family')) {'Family'}
	else if (genres.contains('Science Fiction')) {'Science Fiction'}
	else if (genres.contains('Fantasy')) {'Science Fiction'}
	else if (genres.contains('Comedy')) {'Comedy'}
	else if (genres.contains('Documentary')) {'Documentary'}
	else if (genres.contains('History')) {'Documentary'}
	else if (genres.contains('Drama')) {'Drama'}
	else if (genres.contains('Adventure')) {'Adventure'}
	else 'Action'
}\{n} ({y})
It's really a shame that the built in editor doesn't allow multi-lines, then just ignore whitespace when parseing
User avatar
rednoah
The Source
Posts: 23017
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Single genre from genre list by priority??

Post by rednoah »

{expression} can't be nested, but Groovy has {closures} so the semantics are different.

{genres.contains('Romance') ? 'Chick Flick' : genres.contains('Animation') ? 'Animation' : 'Nope'}

But if you have so many mappings you can do something smart with groovy collections.

I'd do something along the lines of

myGenres retainAll genres, take first or default, apply replacements
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23017
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Single genre from genre list by priority??

Post by rednoah »

This is what I came up with:

Code: Select all

{['Romance', 'Animation', 'Horror'].intersect(genres).withDefault{'Action'}[0].replace('Romance', 'Chick Flick')}
:idea: Please read the FAQ and How to Request Help.
coheed83
Posts: 4
Joined: 09 Aug 2014, 05:08

Re: Single genre from genre list by priority??

Post by coheed83 »

Using this name convention how would I substitute (in the .replace part) anything that has 'Action' and 'Comedy' to display 'Action Comedy'?

Bit of a noob question but thanks anyway!
User avatar
rednoah
The Source
Posts: 23017
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Single genre from genre list by priority??

Post by rednoah »

e.g.

Code: Select all

{'Action'.replaceAll(/Action|Comedy/, 'Action Comedy')}
:idea: Please read the FAQ and How to Request Help.
coheed83
Posts: 4
Joined: 09 Aug 2014, 05:08

Re: Single genre from genre list by priority??

Post by coheed83 »

Thanks so if I'm wanting to use skrowls script (with my own preferences) where would it be placed?

Code: Select all

{if (genres.contains('Romance')) {'Chick Flick'} else if (genres.contains('Animation')) {'Animation'} else if (genres.contains('Horror')) {'Horror'} else if (genres.contains('Family')) {'Family'} else if (genres.contains('Science Fiction')) {'Sci-Fi'} else if (genres.contains('Fantasy')) {'Fantasy'} else if (genres.contains('Comedy')) {'Comedy'} else if (genres.contains('Documentary')) {'Documentary'} else if (genres.contains('History')) {'Documentary'} else if (genres.contains('Drama')) {'Drama'} else if (genres.contains('Adventure')) {'Adventure'} else if (genres.contains('Sports')) {'Sports'} else if (genres.contains('Action')) {'Action'}}
Thanks again.
Post Reply