let filebot choose genre from a list

All about user-defined episode / movie / file name format expressions
Post Reply
Mendeln
Donor
Posts: 7
Joined: 04 Nov 2016, 02:56

let filebot choose genre from a list

Post by Mendeln »

hi :)

first thinks first, thank you very much for this wonderful program rednoah

im quite happy with my expression, especially the collection handling :ugeek:
thanks to the forum and many many hours of reading and trail and error i came up with this:

Code: Select all

I:/{any{readLines('H:/Filmdatenbank/Filmreihe.txt').find{ it =~ imdbid }.after(':')}{any{model.findAll{ it.collection == collection }.genres.flatten().countBy{it}.sort{it.value}.keySet().first()}{genres[0]}}}/{n.replaceAll(/[`´‘’“”""]/, "'").replace(/:/, " - ").replace(/·/, "-").replaceAll(/[½]/, " 1'2").replaceAll(/[⅓]/, " 1'3").replace(/ß/,"ss").replace(/ä/,"ae").replace(/ö/,"oe").replace(/ü/,"ue")} ({y}) [{vf}] [{ac} {af.replace('8ch',' 7.2').replace('7ch',' 6.1').replace('6ch',' 5.1').replace('3', ' 2.1').replace('3ch',' 2.1').replace('2ch',' Stereo')}] [{genres.take(3).join(', ').replaceAll(/ä/,"ae").replaceAll(/ö/,"oe").replaceAll(/ü/,"ue")}]
Filmreihe.txt

Code: Select all

StarTrek
tt0079945;tt0111280;tt0253754;tt0796366;tt1408101;tt2660888;tt0092007;tt0098382;tt0102975;tt0117731;tt0120844;tt0084726;tt0088170:Science Fiction

Insidious
tt1591095;tt2226417;tt3195644:Horror

Pippi Langstrumpf
tt0066265;tt0066227;tt0366905;tt0093744:Familie

X-Men mit Wolverine und Deadpool
tt0120903;tt3385516;tt0376994;tt1270798;tt1877832;tt0290334;tt0458525;tt1431045:Abenteuer

Sissi
tt0048624;tt0049762;tt0050974:Drama

Harry Potter
tt0330373;tt0304141;tt0417741;tt0373889;tt0241527;tt0926084;tt1201607;tt0295297:Familie

Alien
tt0078748;tt0090605;tt0103644;tt0118583:Horror

Matrix
tt0133093;tt0234215;tt0242653:Action
but i have too many genres... i dont want Foreign, Abenteuer, Historie, Musik, Western or Animation
is there a way to let filebot choose the best genre from a list?
in my case there would only be Action, Drama, Familie, Fantasy, Horror, Komödie, Lovestory, Mystery, Science Fiction and Thriller.

im using v4.7.2 r4178 win7
User avatar
rednoah
The Source
Posts: 23926
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: let filebot choose genre from a list

Post by rednoah »

1.
If you have lots of replace-repetition, you can just pass in a map of replacements:

Code: Select all

{'äiüeö'.replace([ä:'a', ü:'u', ö:'o'])}
And those replacement mappings could be encapsulated in an external csv file:

Code: Select all

{'äiüeö'.replace(csv("$HOME/aiueo.csv"))}

2.
You can sort {genres} any way you want (e.g. by using your own value/order map).

e.g. sample code

Code: Select all

{def order = [A:1, B:2, C:3, D:4].withDefault{ 100 }; ['D', 'C', 'K', 'X', 'B', 'A'].sort{ order[it] } }
Please use an external csv file for your Value->Priority mappings.


Once you have a list of genres sorted by your preferred priority order, then you can just take the Top N items:

e.g. take the first 3 genres (without any custom sort)

Code: Select all

{genres.take(3)}
:idea: Please read the FAQ and How to Request Help.
Mendeln
Donor
Posts: 7
Joined: 04 Nov 2016, 02:56

Re: let filebot choose genre from a list

Post by Mendeln »

i use this expression for science

Code: Select all

{def order = [Horror:1, Action:2, 'Science Fiction':3, Fantasy:4, Komödie:5, Drama:6, Lovestory:7, Mystery:8, Familie:9, Thriller:10, Abenteuer:11, Animation:12, Foreign:13, Historie:14, Musik:15, Western:16].withDefault{ 100 }; genres.take(1).sort{ order[it] } } {n}
but it will only sort the genres if write: genres.take(2)

and how do i combine this to let it work with my actual "in use" expression?

Code: Select all

{any{readLines('H:/Filmdatenbank/Filmreihe.txt').find{ it =~ imdbid }.after(':')}{any{model.findAll{ it.collection == collection }.genres.flatten().countBy{it}.sort{it.value}.keySet().first()}{genres[0]}}}
User avatar
rednoah
The Source
Posts: 23926
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: let filebot choose genre from a list

Post by rednoah »

So you reduce the list to one 1 single item first and then you sort the result? :lol:

Code: Select all

genres.take(1).sort{ order[it] } }
Taking the first item AFTER sorting them probably makes more sense. ;)

Code: Select all

genres.sort{ order[it] }.take(1)
If you just want the first item, then this will be easier:

Code: Select all

genres.max{ order[it] }
:idea: Please read the FAQ and How to Request Help.
Post Reply