Collection and Genre

All about user-defined episode / movie / file name format expressions
Post Reply
Chump
Posts: 4
Joined: 13 Oct 2024, 17:27

Collection and Genre

Post by Chump »

Hey,

I just started to code with filebot. I want to sort everything in a weighted genre folder. At the moment I am struggling with collections, because if I try to sort them, then the non-series-movies will not be sorted under a genre file. Before I started to involve collections everything worked fine, but series movie have sometimes different genres so they are not sorted right or they will be sorted under differen genres with the same collection-folder-name. Can someone help? I tried a lot even with ChatGpt :?

Groovy: Select all

movies/
{def genreOrder = ['Animation': 1, 'Comedy': 2, 'Horror': 3, 'Science-Fiction': 4, 'Fantasy': 5, 'Romance': 6, 'Drama': 7, 'Action': 9, 'Thriller': 8].withDefault{ 100 }
def sortedGenres = genres.toSorted{ genreOrder[it] }

def collectionGenre = collection ? model.findAll{ it.collection == collection }.collectMany{ it.genres }.unique().min{ genreOrder[it] } : sortedGenres[0]
'Marvel Studios' in info.productionCompanies ? 'Marvel/' : collectionGenre + '/'}
/
{collection = {it.lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[*\s]+/, " ").replaceAll(/^(The)\s(.+)/i, /$2, $1/)}}
{collection}/{model.findAll{ it.collection == collection }.sort{ it.d }.findIndexOf{ it.id == id } + 1 + '. '}
{n} ({y})
/
{n} ({y}) [{vf} {fn.match(/3D|Extended|Special Edition|Unrated|Uncensored|Remastered/) ? fn.match(/3D|Extended|Special Edition|Unrated|Uncensored|Remastered/) : ""} {vc} {ac} {af}]
User avatar
rednoah
The Source
Posts: 23468
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Collection and Genre

Post by rednoah »

Can you provide a specific set of sample files that we can use for testing and specifying based-on-example what we want?
:idea: Please read the FAQ and How to Request Help.
Chump
Posts: 4
Joined: 13 Oct 2024, 17:27

Re: Collection and Genre

Post by Chump »

Hey,
of course. Here you go:

Console Output: Select all

Abenteuer\\Bill & Ted Filmreihe\\Bill & Teds verrückte Reise durch die Zeit (1989)\\Bill & Teds verrückte Reise durch die Zeit (1989) [2160p x265 DTS 2ch].mkv {"@type":"Movie","year":1989,"imdbId":96928,"tmdbId":1648,"language":"de-DE","id":1648,"name":"Bill & Teds verrückte Reise durch die Zeit","aliasNames":["Bill & Ted's Excellent Adventure"]}
Ant-Man and the Wasp (2018)\\Ant-Man and the Wasp [1080p x264 AC3 6ch].mkv {"@type":"Movie","year":2013,"imdbId":359950,"tmdbId":116745,"language":"de-DE","id":116745,"name":"Das erstaunliche Leben des Walter Mitty","aliasNames":["The Secret Life of Walter Mitty"]}
Abenteuer\\Das erstaunliche Leben des Walter Mitty (Secret Life of Walter Mitty, The, 2013)\\Das erstaunliche Leben des Walter Mitty [1080p x264 DTS 6ch].mkv {"@type":"Movie","year":2018,"imdbId":5095030,"tmdbId":363088,"language":"de-DE","id":363088,"name":"Ant-Man and the Wasp","aliasNames":[]}
@https://pastebin.com/embed_js/E9jufMPZ?theme=dark%22

I have noted a strange behaviour as I prepared you the sample files. While I put the adress (like \\nas/media) in the beginning of the code, I haven't seen the genre for the non-series-movies as firstly posted. BUT when I only put "media/" in the beginning collections get the following structure: media/genre/collection..., while non-series-title get: genre/media/... so it is setting up a folder BEFORE the defined structure

?.?
User avatar
rednoah
The Source
Posts: 23468
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Collection and Genre

Post by rednoah »

Test Case:

Code: Select all

The Secret Life of Walter Mitty (2013).mkv
Bill & Ted's Excellent Adventure (1989).mkv
Bill & Ted's Bogus Journey (1991).mkv
Bill & Ted Face the Music (2020).mkv
Ant-Man and the Wasp (2018).mkv

Format:

Format: Select all

{ drive }
/
{
	def genreOrder = ['Animation': 1, 'Comedy': 2, 'Horror': 3, 'Science-Fiction': 4, 'Fantasy': 5, 'Romance': 6, 'Drama': 7, 'Action': 9, 'Thriller': 8].withDefault{ 100 }

	any
	{ if ('Marvel Studios' in info.productionCompanies) 'Marvel' }
	{ genres.min{ genreOrder[it] } }
	{ 'No Genre' }
}
/
{ collection }
/
{ ny }

Output:
Screenshot
:idea: Please read the FAQ and How to Request Help.
Chump
Posts: 4
Joined: 13 Oct 2024, 17:27

Re: Collection and Genre

Post by Chump »

Hey,
super. It looks very simple. In that test case it seems to be functional. i tested it, but unfortunatly there are other series-movies that will then be categorized under different genres.

Console Output: Select all

Abenteuer\X-Men - Der letzte Widerstand (X-Men - The Last Stand, 2006)\X-Men - Der letzte Widerstand [1080p x264 DTS 7ch].mkv	{"@type":"Movie","year":2006,"imdbId":376994,"tmdbId":36668,"language":"de-DE","id":36668,"name":"X-Men: Der letzte Widerstand","aliasNames":["X-Men: The Last Stand"]}
X-Men - Apocalypse (2016)\X-Men - Apocalypse [1080p x264 DTS 7ch].mkv	{"@type":"Movie","year":2016,"imdbId":3385516,"tmdbId":246655,"language":"de-DE","id":246655,"name":"X-Men: Apocalypse","aliasNames":[]}
X-Men - Erste Entscheidung (X-Men - First Class, 2011)\X-Men - Erste Entscheidung [1080p x264 AC3 6ch].mkv	{"@type":"Movie","year":2011,"imdbId":1270798,"tmdbId":49538,"language":"de-DE","id":49538,"name":"X-Men: Erste Entscheidung","aliasNames":["X-Men: First Class"]}
X-Men - Zukunft ist Vergangenheit (X-Men - Days of Future Past, 2014)\X-Men - Zukunft ist Vergangenheit [1080p x264 DTS 6ch].mkv	{"@type":"Movie","year":2014,"imdbId":1877832,"tmdbId":127585,"language":"de-DE","id":127585,"name":"X-Men: Zukunft ist Vergangenheit","aliasNames":["X-Men: Days of Future Past"]}
@https://pastebin.com/NixqURM7

Those x-men movies will then be categorized under adventure, fantasy and action. That's why I tried to sort them by collecting all movies and then start to search the weighted category for them.

As I mentioned in my last post. My code seems somehow to work, but the code will write the genre alway before the given path for non-series-movies. It does not show up if you use a path like "\\nas\media". Only if sort them without a path or give only a seperate folder. Is this maybe a bug?

edit: I tried to reproduce the "bug", but did not work :cry:
User avatar
rednoah
The Source
Posts: 23468
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Collection and Genre

Post by rednoah »

:idea: Looking at the {genres} we find that only Action and Adventure are common to all movies, so we'll want to give genres that are typically more common a higher priority, so that all the movies likely end up in the same genres folder:

Console Output: Select all

$ filebot -rename *.mkv --db TheMovieDB -non-strict --action TEST --log INFO --format "{ny} {genres}"
[TEST] from [X-Men - Days of Future Past.mkv] to [X-Men Days of Future Past (2014) [Action, Adventure, Science Fiction].mkv]
[TEST] from [X-Men - First Class.mkv] to [X-Men First Class (2011) [Action, Science Fiction, Adventure].mkv]
[TEST] from [X-Men - The Last Stand.mkv] to [X-Men The Last Stand (2006) [Adventure, Action, Science Fiction, Thriller].mkv]
[TEST] from [X-Men - Apocalypse.mkv] to [X-Men Apocalypse (2016) [Action, Adventure, Science Fiction, Fantasy].mkv]


:arrow: This snippet will yield Action for all the X-Men movies in this specific test case at the very least:

Format: Select all

{
	def genreOrder = ['Action': 0.1, 'Adventure': 0.2, 'Animation': 1, 'Comedy': 2, 'Horror': 3, 'Science Fiction': 4, 'Fantasy': 5, 'Romance': 6, 'Drama': 7, 'Thriller': 8].withDefault{ 100 }

	any
	{ if ('Marvel Studios' in info.productionCompanies) 'Marvel' }
	{ genres.min{ genreOrder[it] } }
	{ 'No Genre' }
}


:!: A problem would arise if there was an X-Men movie that doesn't have Action as one if its genres. That would significantly increase the complexity of the problem and thus the complexity of the solution. We can cross that bridge when we have an actual test case that necessitates a more complex solution.





EDIT:
Chump wrote: 14 Oct 2024, 11:37 As I mentioned in my last post. My code seems somehow to work, but the code will write the genre alway before the given path for non-series-movies. It does not show up if you use a path like "\\nas\media". Only if sort them without a path or give only a seperate folder. Is this maybe a bug?
You'll want to use my code, especially if you're code was conjured up by ChatGPT, unless you completely and thoroughly understand how your code works and what it does. The behaviour you describe is likely the result of your format code not doing what you think it does, but you would have to share screenshots for me to make any kind of educated guess as to what is actually going on.

:arrow: You can do Double-Click ➔ Edit Format on the movie that is causing trouble to open the Format Editor and see what your custom format is doing for the specific File / Movie match at hand.

:!: At a glance, your code does not account for the possibility of undefined bindings, e.g. the code that uses collection will always fail and never yield any value for movies where collection is undefined.
:idea: Please read the FAQ and How to Request Help.
Chump
Posts: 4
Joined: 13 Oct 2024, 17:27

Re: Collection and Genre

Post by Chump »

Okay,
thank you so far. Really appreciate your input.

Do you have maybe an idea, why my code is not working? I mean for collection it seems to work pretty well, but why sortedGenres[0] is not working in this part but standalone ?.?:

Groovy: Select all

def collectionGenre = collection ? model.findAll{ it.collection == collection }.collectMany{ it.genres }.unique().min{ genreOrder[it] } : sortedGenres[0]
'Marvel Studios' in info.productionCompanies ? 'Marvel/' : collectionGenre + '/'}
in the end, I could end up renaming collection and non-collection-movies seperatly to calm down my smoking head :lol: . But I am still looking for the perfect code for me

EDIT: Ok, saw your edit. I will try to rework it of the very beginning. Starting with your code as base. Let's see if I can reach a good point. ;)
User avatar
rednoah
The Source
Posts: 23468
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Collection and Genre

Post by rednoah »

It's really hard to come up with a movie that isn't part of a collection nowadays... So here's what you'd get if you debug your format step by step on a relevant test case:
Screenshot

:idea: Learn how {expressions} work and useful Helper Functions explains why / how an error in the {code} breaks the entire {code} unless you account for and handle the error.
:idea: Please read the FAQ and How to Request Help.
Post Reply