Request for supporting user-specified rules for episode match in command line

All your suggestions, requests and ideas for future development
Post Reply
gdlk
Posts: 12
Joined: 12 Mar 2025, 08:48

Request for supporting user-specified rules for episode match in command line

Post by gdlk »

I hope that user-specified matching rules can be supported.

For some anime series, the naming conventions for different seasons can be inconsistent. Episodes in each season may be numbered separately starting from 01, or all seasons' episodes may be numbered continuously from 01 without resetting. This discrepancy can lead to mismatches between the actual files and TMDb data.

For example, https://www.themoviedb.org/tv/107371 uses a unified numbering system across all seasons, but the files I downloaded from PT use season-based numbering. For instance, a file might be named `S03E39`, but TMDb does not recognize this because the corresponding episode is actually listed as `S01E145` on TMDb.

Therefore, I would like the ability to specify matching rules via the command line to handle such cases. These rules should include mappings between `SxxExx` from the downloaded files and the correct `SxxExx` numbers from TMDb, as well as the directories where these rules should be applied.

Additionally, it would be best to support a list of mapping rules, where each entry defines a specific matching adjustment for different shows that require special handling.
User avatar
rednoah
The Source
Posts: 23922
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Request for supporting user-specified rules for episode match in command line

Post by rednoah »

:?: What are the specific file paths you're having issues with? Please post sample file paths as text as console output so that we can see the issue at hand.


:arrow: The --mapper option is likely the feature you're looking for. You will want to read [Anime] Convert Absolute to SxE numbers as well if you're having trouble matching up AniDB named files with TMDB / TVDB episode listings.


:arrow: You can run different commands on different files as needed. See How do I process specific files with specific command-line options? for details and examples.
:idea: Please read the FAQ and How to Request Help.
gdlk
Posts: 12
Joined: 12 Mar 2025, 08:48

Re: Request for supporting user-specified rules for episode match in command line

Post by gdlk »

Input episodes: S03E38 - S03E40
Output episodes: S01E38-S01E40
Output I want: S01E144 - S01E146

The two episodes S03E38 and S03E39 were manually renamed by me.
The S03E40 is an episode newly added.

How can I do this using --mapper ?

My command is

Shell: Select all

filebot -script fn:amc --lang=Chinese -non-strict --conflict skip  \
  --action test\
  --apply nfo cover artwork metadata  \
  --def excludeList=/data/exclude.txt \
  --def movieDB=TheMovieDB seriesDB=TheMovieDB::TV animeDB=TheMovieDB::TV \
  --def seriesFormat="{~emby.id} - {allOf{allOf{source}{vc.length()>5?vcf:vc}{vf}{hdr}{ac}.join('.').replace('Dolby Vision','DV')}{group}.join('-')}"  \
  --output "/mnt/media/DongMan"   \
  --q 107371  \
    /Download/video/anim/YiNianYH/\[一念永恒第三季\].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/*E13[7-9]*  
Output is:

Console Output: Select all

Run script [fn:amc] at [Thu Mar 13 01:37:13 CST 2025]
Parameter: excludeList = /data/exclude.txt
Parameter: movieDB = TheMovieDB
Parameter: seriesDB = TheMovieDB::TV
Parameter: animeDB = TheMovieDB::TV
Parameter: movieFormat = {~emby.id} {allOf{allOf{source}{vc.length()>5?vcf:vc}{vf}{hdr}{ac}.join('.').replace('Dolby Vision','DV')}{group}.join('-')}
Parameter: seriesFormat = {~emby.id} - {allOf{allOf{source}{vc.length()>5?vcf:vc}{vf}{hdr}{ac}.join('.').replace('Dolby Vision','DV')}{group}.join('-')}
Parameter: animeFormat = {~emby.id} - {allOf{allOf{source}{vc.length()>5?vcf:vc}{vf}{hdr}{ac}.join('.').replace('Dolby Vision','DV')}{group}.join('-')}
Parameter: jellyfin = *****
Parameter: emby = *****
Argument[0]: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
Argument[1]: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
Argument[2]: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
Use excludes: /data/exclude.txt (14)
Input: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
       └─ xattr metadata: 一念永恒 - 1x144 - 叛乱惊起
Input: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
       └─ xattr metadata: 一念永恒 - 1x145 - 险象环生
Input: /Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4
Group files by movie or series
Group: {Series=一念永恒} => [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4, [一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4]
Group: {Series=Will (2017)} => [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4]
Rename episodes using [TheMovieDB] with [Airdate Order]
Lookup via [] [107371]
Fetching episode data for [107371]
* 一念永恒 [107371] | 200 episodes | 1x01-200
[TEST] from [/Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [/mnt/media/DongMan/一念永恒 (2020) [tmdbid=107371]/Season 01/一念永恒 (2020) - S01E38 - 罚你出宗 - WEB-DL.o264.1080p.AAC-OurTV.mp4]
[TEST] from [/Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [/mnt/media/DongMan/一念永恒 (2020) [tmdbid=107371]/Season 01/一念永恒 (2020) - S01E39 - 潜入血溪宗 - WEB-DL.o264.1080p.AAC-OurTV.mp4]
Processed 2 files
Rename episodes using [TheMovieDB] with [Airdate Order]
Lookup via [] [107371]
Fetching episode data for [107371]
* 一念永恒 [107371] | 200 episodes | 1x01-200
[TEST] from [/Download/video/anim/YiNianYH/[一念永恒第三季].A.Will.Eternal.S03.2024.1080p.WEB-DL.H264.AAC-OurTV/[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [/mnt/media/DongMan/一念永恒 (2020) [tmdbid=107371]/Season 01/一念永恒 (2020) - S01E40 - 人才的光环 - WEB-DL.o264.1080p.AAC-OurTV.mp4]
Processed 1 file
Finished without processing any files
Done ¯\_(ツ)_/¯
User avatar
rednoah
The Source
Posts: 23922
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Request for supporting user-specified rules for episode match in command line

Post by rednoah »

:idea: In this case I'd use the Linear Rename approach:

Console Output: Select all

$ filebot -list --q 107371 --db TheMovieDB::TV --format "{plex.id}" --filter "e >= 144" -rename *.mp4 --log INFO
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E144 - Episode 144.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E145 - Episode 145.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E146 - Episode 146.mp4]




:idea: Note that the files you have use TheTVDB numbering, so using TheTVDB to match the files will just work:

Console Output: Select all

$ filebot -rename *.mp4 --db TheTVDB -non-strict --log INFO
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [A Will Eternal - 3x38 - 第144集.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [A Will Eternal - 3x39 - 第145集.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [A Will Eternal - 3x40 - 第146集.mp4]


:idea: You can use --action TEST to do dry runs. You can use --log INFO to reduce the console output.






EDIT:

:!: This series has notably been entered into the DB twice, so there's a good chance that one of the two IDs (probably the higher one) will be deleted at some point:
* https://www.themoviedb.org/tv/107371
* https://www.themoviedb.org/tv/285779

:!: A --mapper solution is not possible in this case because 107371 has no associated TVDB ID and a TVDB ID cannot be added because it's already associated with 285779.
:idea: Please read the FAQ and How to Request Help.
gdlk
Posts: 12
Joined: 12 Mar 2025, 08:48

Re: Request for supporting user-specified rules for episode match in command line

Post by gdlk »

Thanks for your reply!
rednoah wrote: 12 Mar 2025, 19:50 :idea: In this case I'd use the Linear Rename approach:

Console Output: Select all

$ filebot -list --q 107371 --db TheMovieDB::TV --format "{plex.id}" --filter "e >= 144" -rename *.mp4 --log INFO
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E144 - Episode 144.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E145 - Episode 145.mp4]
[MOVE] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E146 - Episode 146.mp4]
Can I automate the correspondance?
For example, get the input episode number 38, store it in a variable, say in, and then use
--filter "e >= in+106" .

The question is how can I get the number 38 and use it in --filter?
--filter "e >= e00 + 106" does not work as my will.

By the way, I can not access tvdb in China. And another reason I use tmdb is that only tmdb supports Chinese the best.
User avatar
rednoah
The Source
Posts: 23922
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Request for supporting user-specified rules for episode match in command line

Post by rednoah »

gdlk wrote: 13 Mar 2025, 03:38 get the input episode number 38, store it in a variable, say in, and then use
--filter "e >= in+106" .

The question is how can I get the number 38 and use it in --filter?
That is a good question. How does FileBot know the episode number? Remember that FileBot does not know anything until the file has already been matched to an episode. You could probably have your own bash code guess that part though, and then generate a --filter option accordingly:

Console Output: Select all

$ ls | egrep -o 'S[0-9]+E[0-9]+' | egrep -o '[0-9]+$'
38



:arrow: Looks like we're back to using the use --mapper option. That'll allow us to match the episode as if it was a different episode:

Console Output: Select all

$ filebot -rename *.mp4 --output . --format "{plex.id}" --db TheMovieDB::TV -non-strict --q 107371 --filter "e > 106" --mapper "episode.derive(1, e - 106)" --action TEST --log INFO
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E144 - Episode 144.mp4]
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E145 - Episode 145.mp4]
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E146 - Episode 146.mp4]



:arrow: On further thought, if you're always processing the latest episode on a strictly weekly basis, then the --filter option is the way to go, but in the form of an age filter. That way we can force FileBot to match whichever episode was aired this week. That's much easier and it'll work the same for any ongoing series:

Console Output: Select all

$ filebot -rename *.mp4 --output . --format "{plex.id}" --db TheMovieDB::TV -non-strict --q 107371 --filter "age < 7" --action TEST --log INFO
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E146 - Episode 146.mp4]




gdlk wrote: 13 Mar 2025, 03:38 By the way, I can not access tvdb in China. And another reason I use tmdb is that only tmdb supports Chinese the best.
I'm sure there's a way around the GFW. That said, I would generally recommend using TheMovieDB for everything, and contributing if you find something missing.
:idea: Please read the FAQ and How to Request Help.
gdlk
Posts: 12
Joined: 12 Mar 2025, 08:48

Re: Request for supporting user-specified rules for episode match in command line

Post by gdlk »

Thank you very much!
This method can solve my problem.
rednoah wrote: 13 Mar 2025, 05:47

Console Output: Select all

$ filebot -rename *.mp4 --output . --format "{plex.id}" --db TheMovieDB::TV -non-strict --q 107371 --filter "e > 106" --mapper "episode.derive(1, e - 106)" --action TEST --log INFO
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E38.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E144 - Episode 144.mp4]
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E39.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E145 - Episode 145.mp4]
[TEST] from [[一念永恒第三季].A.Will.Eternal.S03E40.2024.1080p.WEB-DL.H264.AAC-OurTV.mp4] to [TV Shows/A Will Eternal {tmdb-107371}/Season 01/A Will Eternal - S01E146 - Episode 146.mp4]
I do not have to use age, because I only pass the latest file to filebot.
Post Reply