Page 1 of 1
Collection and Genre sorting script
Posted: 22 Aug 2019, 07:24
by zedd
I'm trying to get filebot to sort movies into collections as well as genres. I have some scripts hacked out, but thought I should check to make sure I wasn't missing anything. I think I have to run filebot twice to do this, as I haven't seen any mention of a way to process the same file twice.
Command 1 only hardlinks movies that are in collections into a Collections folder.
Code: Select all
filebot -script fn:amc -rename -r /nasty/Media/Movies/unsorted --db themoviedb --action hardlink --output "/nasty/Media/Movies/Collections/" --def movieFormat={collection}/{plex.name} --filter collection --log-file amc.log --def excludeList=col1.txt
So for the 2045-2053 Batman collection, it outputs:
/nasty/Media/Movies/Collections/Batman's Fake Collection/Riddler (2050).mkv
Command 2 hardlinks all of the files into genre folders, starting with animation and science fiction.
Code: Select all
filebot -script fn:amc -rename -r /nasty/Media/Movies/unsorted --db themoviedb --action hardlink --output "/nasty/Media/Movies" --format "{genres =~ 'Animation' ? 'Animation/' : {genres =~ 'Science Fiction' ? 'Science Fiction/' : genres[0]}}/{plex}/{plex.name}" --log-file amc.log --def excludeList=gen1.txt
So the output for Batman's live action Space Adventure would be:
/nasty/Media/Movies/Science Fiction/Space Batman (2022)/Space Batman (2022).mkv
Batman (1966) would be:
/nasty/Media/Movies/Comedy/Batman (1966)/Batman (1966).mkv
I have some concerns with this set up. Since I have to process everything twice, I'm worried about upsetting themoviedb, and everyone else this might be pinging.
What happens if a movie isn't a collection when the script is run, but then later becomes one? Does Filebot do a check to see if a previous movie in a new collection has already been processed?
Thanks in advance!
Re: Collection and Genre sorting script
Posted: 22 Aug 2019, 10:16
by rednoah
1.
If you're using the amc script to process movies, then I recommend forcing movie mode:

The
--db option is ignored by the amc script and has no effect.
2.
I recommend using
-rename --db xattr on the second pass, or third or n-th pass:
viewtopic.php?t=324
e.g.
Code: Select all
filebot -rename -r "/path/to/Media/Movies" --db xattr --action hardlink --output "/path/to/Movies By Collection" --filter collection --format "{collection}/{plex.name}"
--filter collection is used to include only movie files that belong to a collection.
3.
I recommend having one xattr-tagged primary structure processed and named using the amc script with
{plex} binding, and then you can have an arbitrary number of mirrored secondary structures that you can be build and re-build on demand from the primary structure (e.g. when a movie was added to a collection later on, and you want to re-organize your file structure accordingly).
You will find the examples listed here very inspiring:
viewtopic.php?t=4788
Re: Collection and Genre sorting script
Posted: 22 Aug 2019, 16:27
by zedd
Thank you!
Re: Collection and Genre sorting script
Posted: 02 Oct 2019, 08:52
by techsupport0321
This seems like the right place and I have thus far been unable to find a solution to my problem. I am attempting to sort my movie collection in to genre folders, but I want to set the order of presedence for the genres that Filebot put them in to. For example, lets say a movie returns the result of
Code: Select all
/path.to.movies/Crime-Thriller-Action/name.of.movie.mp4
How do I set filebot to change it to Action-Crime-Thriller?
Here is my current script that I am running on MacOS with GUI, Im not opposed to CLI as I also use that from time to time.
Additional issuesquestions with the expression I am using:
I would like to force filebot to look at IMDB for the genre, is this possible the way I have it written or is it still only going to look at TheMovieDB?
When no rating is returned it is expressing it as 0.0 instead of "NR" as I was hoping my expression would do. Im ok with the 0.0, just wondering why it behaves this way or how to change it, if possible.
Code: Select all
../{any{imdb.genre}{genres.take(3).join('-')}}/{n} ({y}) [{any{imdb.certification}{certification}{"NR"}}, {any{imdb.rating}{rating}{"NR"}}, {vf}]/{n} ({y}) [{any{imdb.certification}{certification}{"NR"}}, {any{imdb.rating}{rating}{"NR"}}, {vf}]
Re: Collection and Genre sorting script
Posted: 02 Oct 2019, 12:41
by rednoah
1.
e.g. take the first 3 genres, and sort them alphabetically, and then join them with dashes:
Code: Select all
genres.take(3).toSorted().join('-')
FileBot does not support IMDb, but OMDb should more or less give you the same information:
Code: Select all
omdb.genres.take(3).toSorted().join('-')

Note that there is no
{imdb} binding, so those bits of your code always fail.
2.
Please give an example of a movie that has no rating / 0 rating. I'll need samples for testing, otherwise I can't give you a well-tested solution.
Re: Collection and Genre sorting script
Posted: 02 Oct 2019, 21:45
by techsupport0321
Understood on the alphabetical sort. Thanks for that! However, what I am trying to do is set and order or precedence for the genre sorting of movies.
Example:
Order of Precedence
1. Animation
2. Musical
3. Documentary
4. Horror
5. Action
6. Comedy
7. Crime
8. Family
9. Adventure
Therefore, after running:
Bad Boys would be found in file path of: ./Action/Action-Comedy-Crime/Bad Boys (1994)/Bad Boys (1994).mp4
WALL-E would be found in file path of: ./Animation/Animation-Family-Adventure/WALL-E(2008)/WALL-E (2008).mp4
World War Z would be found in file path of: ./Horror/Horror-Action-Adventure/World War Z (2013)/World War Z (2013).mp4
Thoughts on how to do this?
Re: Collection and Genre sorting script
Posted: 02 Oct 2019, 22:31
by techsupport0321
The movie Bare Knuckle Brawler returned with: Bare Knuckle Brawler (2019) [NR, 0.0, 1080p].mp4
Re: Collection and Genre sorting script
Posted: 02 Oct 2019, 22:59
by techsupport0321
@rednoah
Based off of an old post I found I have written this to a text file as my "map" How do I implement it in to a command line call of filebot on a folder of videos?
Code: Select all
{
def genreOrder = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18]
}
Am I even on the right path here??
I still need the final out put to be ex: ./Action/Action-Comedy-Crime/Bad Boys (1994)/Bad Boys (1994).mp4 for the movie Bad Boys
Thanks in advance!
Re: Collection and Genre sorting script
Posted: 03 Oct 2019, 06:44
by rednoah
List.toSorted() will sort by name by default. But you can of course use your own comparison function, e.g. with your own priority map as detailed above. It's just format code, so it'll work the same in both GUI and CLI
(use the GUI for efficient prototyping!!!) and you probably have already found copy & paste solutions here in the forums.
e.g.
viewtopic.php?p=45110#p45110

Re: Collection and Genre sorting script
Posted: 03 Oct 2019, 08:16
by techsupport0321
Hey brother, I have no idea how to utilize this to get the intended result. Here is what I have
Code: Select all
{
def genreOrder = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18].withDefault{ 100 }
genres.toSorted{ genreOrder[it] }}
/{n} ({y})/{n} ({y})
When applied to Avatar it gives
Code: Select all
/path/Science Fiction, Fantasy, Action, Adventure/Avatar (2009)/Avatar (2009)
Gotta remove the space in Science Fiction somehow also and replace with Science-Fiction or Sci-Fi - i know normally you would use .replace('Science Fiction', 'Sci-Fi') but no matter where I put it in the above code, it didn't work.
So it is def accepting the order, however, I need the path to have 2 separate genre folders. In this case the first folder would be Science Fiction
and the second folder would be Science Fiction-Fantasy-Action
Code: Select all
/path/to/file/Sci-Fi/Sci-Fi-Fantasy-Action/Avatar (2009)/Avatar (2009).mp4
Re: Collection and Genre sorting script
Posted: 03 Oct 2019, 09:02
by rednoah
1.
Code: Select all
{
def genreOrder = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18].withDefault{ 100 }
genres.toSorted{ genreOrder[it] }.take(3).join('-').replace('Science Fiction', 'Sci-Fi')
}
2.
Code: Select all
{
def order = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18].withDefault{ 100 }
def map = ['Science Fiction': 'Sci-Fi']
def genres = genres.toSorted{ order[it] }*.replace(map)
genres.first() / genres.take(3).join('-')
}
Re: Collection and Genre sorting script
Posted: 05 Oct 2019, 06:49
by techsupport0321
This is great! Only question I have is how do I add a {'No Genre'} in to the code? I tried it a few ways and no matter what, when I ran the rename/editor it gave 'No Genre' for every movie.
Re: Collection and Genre sorting script
Posted: 05 Oct 2019, 15:21
by rednoah
e.g.
Code: Select all
{
any
{
def order = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18].withDefault{ 100 }
def map = ['Science Fiction': 'Sci-Fi']
def genres = genres.toSorted{ order[it] }*.replace(map)
genres.first() / genres.take(3).join('-')
}
{
'No Genre'
}
}
Re: Collection and Genre sorting script
Posted: 07 Oct 2019, 15:39
by rednoah
Movie Object:
Format:
Code: Select all
{
any
{
def order = ['Animation': 1, 'Musical': 2, 'Documentary': 3, 'Family': 4, 'History': 5, 'Science Fiction': 6, 'Horror': 7, 'Fantasy': 8, 'War': 9, 'Western': 10, 'Action': 11, 'Comedy': 12, 'Crime': 13, 'Thriller': 14, 'Adventure': 15, 'Mystery': 16, 'Romance': 17, 'Drama': 18].withDefault{ 100 }
def map = ['Science Fiction': 'Sci-Fi']
def genres = genres.toSorted{ order[it] }*.replace(map)
genres.first() / genres.take(3).join('-')
}
{
'No Genre'
}
}
/{plex.name}
Destination Path:
Code: Select all
Animation/Animation-Family-Comedy/A Goofy Movie (1995)
Re: Collection and Genre sorting script
Posted: 10 Jan 2025, 10:53
by rednoah