Page 1 of 1
Single genre from genre list by priority??
Posted: 06 Oct 2014, 22:57
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?
Re: Single genre from genre list by priority??
Posted: 07 Oct 2014, 01:25
by rednoah
Lots of examples here in the forums somewhere.
genres.contains('something') ? A : B
Re: Single genre from genre list by priority??
Posted: 07 Oct 2014, 02:00
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
Re: Single genre from genre list by priority??
Posted: 07 Oct 2014, 03:03
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
Re: Single genre from genre list by priority??
Posted: 07 Oct 2014, 20:03
by rednoah
This is what I came up with:
Code: Select all
{['Romance', 'Animation', 'Horror'].intersect(genres).withDefault{'Action'}[0].replace('Romance', 'Chick Flick')}
Re: Single genre from genre list by priority??
Posted: 30 Nov 2014, 06:21
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!
Re: Single genre from genre list by priority??
Posted: 30 Nov 2014, 14:41
by rednoah
e.g.
Code: Select all
{'Action'.replaceAll(/Action|Comedy/, 'Action Comedy')}
Re: Single genre from genre list by priority??
Posted: 01 Dec 2014, 07:17
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.