Using mapper to fix episode number

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Using mapper to fix episode number

Post by devster »

I'm having trouble understanding how to use --mapper.
I have the following list of episodes:

Code: Select all

My.Show.S02E01E02.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E03.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E04.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E05.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E06.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E07.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E08.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E09.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E10.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E11.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E12.Extended.720p.BluRay.x264-NTb.mkv
My.Show.S02E13.Extended.720p.BluRay.x264-NTb.mkv
However the episodes are mapped in both TheTVDB and TheMovieDB::TV as:

Code: Select all

my show - 2x01 - Everything Is Great!
my show - 2x02 - Dance Dance Resolution
my show - 2x03 - Team Cockroach
my show - 2x04 - Existential Crisis
my show - 2x05 - The Trolley Problem
my show - 2x06 - Janet and Michael
my show - 2x07 - Derek
my show - 2x08 - Leap to Faith
my show - 2x09 - Best Self
my show - 2x10 - Rhonda, Diana, Jake, and Trent
my show - 2x11 - The Burrito
my show - 2x12 - Somewhere Else
In short, episode X is X-1 in the DB and the first one is actually a single episode, not a double.
Is there any mapper expression I can use to fix this situation?

Code: Select all

docker exec qbittorrent /usr/bin/filebot -script fn:amc --action test --output /Media --conflict skip --log-file amc.log --def ut_dir=/srv/pv/torrent/downloads/complete/tv_shows/My.Show.S02.Extended.720p.BluRay.x264-NTb ut_kind=multi ut_title=My.Show.S02.Extended.720p.BluRay.x264-NTb ut_label=tv_shows --def @/scripts/notify.txt --def movieFormat=@/scripts/movieFormat.groovy --def seriesFormat=@/scripts/seriesFormat.groovy --def animeFormat=@/scripts/animeFormat.groovy --mapper "episode.derive(2, e - 1)"
The above line fails with:

Code: Select all

Syntax Error: net.filebot.format.BindingException: Binding "e": undefined
I only work in black and sometimes very, very dark grey. (Batman)
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Using mapper to fix episode number

Post by kim »

devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Using mapper to fix episode number

Post by devster »

It's not really clear how to run those snippets, are they scripts? mappings?

Also I managed to fix the rename with the following:

Code: Select all

--q 'my show' --filter 's == 3' --mapper "episode.derive(episode.season, episode.episode + 1)"
and using strict mode.
What's not clear is why +1 instead of -1... this is the log:

Code: Select all

Apply mapper [episode.derive(episode.season, episode.episode + 1)] on [12] episodes
Map [The Good Place - 3x01 - Everything Is Bonzer!] to [The Good Place - 3x02]
Map [The Good Place - 3x02 - The Brainy Bunch] to [The Good Place - 3x03]
Map [The Good Place - 3x03 - The Snowplow] to [The Good Place - 3x04]
Map [The Good Place - 3x04 - Jeremy Bearimy] to [The Good Place - 3x05]
Map [The Good Place - 3x05 - The Ballad Of Donkey Doug] to [The Good Place - 3x06]
Map [The Good Place - 3x06 - A Fractured Inheritance] to [The Good Place - 3x07]
Map [The Good Place - 3x07 - The Worst Possible Use Of Free Will] to [The Good Place - 3x08]
Map [The Good Place - 3x08 - Don’t Let The Good Life Pass You By] to [The Good Place - 3x09]
Map [The Good Place - 3x09 - Janet(s)] to [The Good Place - 3x10]
Map [The Good Place - 3x10 - The Book Of Dougs] to [The Good Place - 3x11]
Map [The Good Place - 3x11 - Chidi Sees The Time-Knife] to [The Good Place - 3x12]
Map [The Good Place - 3x12 - Pandemonium] to [The Good Place - 3x13]
Reverse Map [The Good Place - 3x02] to [The Good Place - 3x01 - Everything Is Bonzer!]
Reverse Map [The Good Place - 3x03] to [The Good Place - 3x02 - The Brainy Bunch]
Reverse Map [The Good Place - 3x04] to [The Good Place - 3x03 - The Snowplow]
Reverse Map [The Good Place - 3x05] to [The Good Place - 3x04 - Jeremy Bearimy]
Reverse Map [The Good Place - 3x06] to [The Good Place - 3x05 - The Ballad Of Donkey Doug]
Reverse Map [The Good Place - 3x07] to [The Good Place - 3x06 - A Fractured Inheritance]
Reverse Map [The Good Place - 3x08] to [The Good Place - 3x07 - The Worst Possible Use Of Free Will]
Reverse Map [The Good Place - 3x09] to [The Good Place - 3x08 - Don’t Let The Good Life Pass You By]
Reverse Map [The Good Place - 3x10] to [The Good Place - 3x09 - Janet(s)]
Reverse Map [The Good Place - 3x11] to [The Good Place - 3x10 - The Book Of Dougs]
Reverse Map [The Good Place - 3x12] to [The Good Place - 3x11 - Chidi Sees The Time-Knife]
Reverse Map [The Good Place - 3x13] to [The Good Place - 3x12 - Pandemonium]
and the rename actually is correct but it seems counterintuitive.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Using mapper to fix episode number

Post by rednoah »

kim wrote: 17 Oct 2021, 19:34 you can use this
viewtopic.php?p=18802#p18802
This custom script from 2016 is just a generic file rename script, the kind that you could easily write yourself in your favorite scripting language. It predates Plain File Mode so it's probably not the most straight-forward filebot-y way of doing that nowadays. The idea is to fix the numbers in the file path first (as opposed to using --mapper) so that normal filebot calls then work as usual in a second step.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Using mapper to fix episode number

Post by rednoah »

Code: Select all

$ filebot -rename "The Good Place - 3x02.mp4" --q 311711 --db TheTVDB -non-strict --action TEST --filter regular --mapper "episode.number(s, e + 1)"
* Consider using --mode interactive to enable interactive mode
...
Apply mapper [episode.number(s, e + 1)] on [50] episodes
...
Map [The Good Place - 3x01 - Everything Is Bonzer!] to [The Good Place - 3x02 - Everything Is Bonzer!]
...
Reverse Map [The Good Place - 3x02 - Everything Is Bonzer!] to [The Good Place - 3x01 - Everything Is Bonzer!]
[TEST] from [The Good Place - 3x02.mp4] to [The Good Place - 3x01 - Everything Is Bonzer!.mp4]
...
--mapper allows you to transform the Episode objects from the database, as if the database had sent back different Episode information, for the purpose of matching, but not for the purpose of renaming.



:idea: --mapper "episode.number(s, e + 1)" means that Episode 3x01 is matched as if it was Episode 3x02 and so "Episode that is actually 3x01 but mapped to 3x02 for the purpose of matching" will now match "File with 3x02 in the name" allowing you to rename / renumber "File with 3x02 in the name" to official database "Episode 3x01":

Code: Select all

Map [The Good Place - 3x01 - Everything Is Bonzer!] to [The Good Place - 3x02 - Everything Is Bonzer!]

Code: Select all

Reverse Map [The Good Place - 3x02 - Everything Is Bonzer!] to [The Good Place - 3x01 - Everything Is Bonzer!]
[TEST] from [The Good Place - 3x02.mp4] to [The Good Place - 3x01 - Everything Is Bonzer!.mp4]


:!: --filter regular preemptively excludes special episodes which don't have {s} and {e} numbers so that our --mapper expression doesn't have to worry about how to deal with those:

Code: Select all

Map [The Good Place - Special 1 - Comic-Con Panel 2019] to [...] failed: net.filebot.format.BindingException: Binding "s": undefined



EDIT:


Since --mapper maps Episode objects (as opposed to File objects) we can use the -list command (which is unrelated to renaming or matching files) for testing:

Code: Select all

$ filebot -list --db TheTVDB --q 311711  --filter regular --mapper "episode.number(s, e + 1)" --log OFF
The Good Place - 1x02 - Everything is Fine
The Good Place - 1x03 - Flying
...
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Using mapper to fix episode number

Post by rednoah »

Note that you will find Linear Rename more straight-forward for this particular use case:

Code: Select all

$ filebot -list -rename *.mp4 --db TheTVDB --q 311711 --filter "s == 2" --action TEST --log INFO
[TEST] from [My.Show.S02E01E02.mp4] to [The Good Place - 2x01 - Everything Is Great!.mp4]
[TEST] from [My.Show.S02E03.mp4] to [The Good Place - 2x02 - Dance Dance Resolution.mp4]
[TEST] from [My.Show.S02E04.mp4] to [The Good Place - 2x03 - Team Cockroach.mp4]
...
:idea: Please read the FAQ and How to Request Help.
Post Reply