How to add "Part_X" to end of filename for multipart files

All about user-defined episode / movie / file name format expressions
Post Reply
simonbolster
Posts: 5
Joined: 10 Mar 2021, 17:26

How to add "Part_X" to end of filename for multipart files

Post by simonbolster »

Hello and thanks in advance for any assist. I've done my best to find the answer to this among the trove of invaluable advice and examples in the forums, but alas I have failed.

I have a movie naming scheme that I am happy with, borrowed and plagiarized extensively and shamelessly from others' examples.

Code: Select all

{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() })}; norm(n)}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}){genres != null && (genres.contains('animation') || genres.contains('Animation')) ? ' (Animation)':""}{genre != null && !genres.contains('animation') && !genres.contains('Animation') ? ' ('+{genre}+')':""}{if (any{imdb.certification}{certification} != null) ' ('+any{imdb.certification}{certification}+')'} {'{imdb-'+imdbid+'}'}\{norm(n)}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}){genres != null && (genres.contains('animation') || genres.contains('Animation')) ? ' (Animation)':""}{genre != null && !genres.contains('animation') && !genres.contains('Animation') ? ' ('+{genre}+')':""}{if (any{imdb.certification}{certification} != null) ' ('+any{imdb.certification}{certification}+')'} {languages.toString().toUpperCase()} ({vs == "" ? "" : vs+" "}{vf.removeIllegalCharacters()}) ({AC} {channels}) ({vc.replaceAll('AVC','h264').replaceAll('HEVC','h265')})
This results in output like this:

[*]101 Dalmatians II - Patch's London Adventure (2003) (Animation) (G) {imdb-tt0324941}/101 Dalmatians II - Patch's London Adventure (2003) (Animation) (G) [ENG] (BluRay 1080p) (AC3 5.1) (x265)
[*]Escape Plan 2 - Hades (2018) (Action) (R) {imdb-tt6513656}/Escape Plan 2 - Hades (2018) (Action) (R) [ENG] (BluRay 720p) (DTS 5.1) (x264)

What I cannot master is one final piece: If a movie is split across multiple files, I'd like to add "Part_X" to the end of the name. The original name of the file will contain, somewhere in it, words such as "CD1", "Part1", "Part 1", Part_1", "PT_1" and so forth.
I can do a "contains" statement to check for the existence of such phrases - like

Code: Select all

original.toUpperCase().contains('CD')
But I cannot uncover how to then use the number of the "part".

I suspect there is a clever RegEx that might accomplish it, but when it comes to regular expressions I'm afraid I am at sea.

Does anybody have any suggestions? Or even point me to an existing post that covers this kind of thing?

Eternally grateful :-)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to add "Part_X" to end of filename for multipart files

Post by rednoah »

The {pi} part index binding should do the job:

Code: Select all

{' CD'+pi}

:!: The {pi} part index only works if FileBot has identified a multi-part set of files, i.e. same movie match, same resolution, same video codec, etc.
:idea: Please read the FAQ and How to Request Help.
simonbolster
Posts: 5
Joined: 10 Mar 2021, 17:26

Re: How to add "Part_X" to end of filename for multipart files

Post by simonbolster »

Thanks @rednoah!

I have this:

Code: Select all

{pi>0 ? ' - pt'+{pi} : ''}
Is the "if" logic required, or will your suggestion only insert the ' CD'+pi if there are multiple parts?

Thanks again - and also for the very swift response :D
simonbolster
Posts: 5
Joined: 10 Mar 2021, 17:26

Re: How to add "Part_X" to end of filename for multipart files

Post by simonbolster »

Don't worry about that last question - I confirmed through testing that your solution is perfect - there's no need for my "if" logic.

Final naming scheme:

Code: Select all

{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() })}; norm(n)}{fn.contains('3D') || fn.contains('3-D') ? ' 3D' :""} ({y}){genres.contains('animation') || genres.contains('Animation') ? ' (Animation)':""}{genre != null && !genres.contains('animation') && !genres.contains('Animation') ? ' ('+{genre}+')':""}{any{imdb.certification}{certification} != null ? ' ('+any{imdb.certification}{certification}+')' : ''} {'{imdb-'+imdbid+'}'}\{norm(n)}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}){genres.toUpperCase().contains('ANIMATION') ? ' (Animation)':""}{genre != null && !genres.toUpperCase().contains('ANIMATION') ? ' ('+genre+')':""}{if (any{imdb.certification}{certification} != null) ' ('+any{imdb.certification}{certification}+')'}{languages.toString().toUpperCase()!="" ? " "+languages.toString().toUpperCase() : ""} ({vs != "" ? vs : ""}{vs != "" && vf!="" ? " " : ""}{vf.removeIllegalCharacters()}) ({AC} {channels}) ({vc.replaceAll('AVC','h264').replaceAll('HEVC','h265')}){' - pt'+pi}
Which generates:
  • Crazy Rich Asians (2018) (Comedy) (PG-13) {imdb-tt3104988}\Crazy Rich Asians (2018) (Comedy) (PG-13) [ZHO, ENG] (BluRay 1080p) (AC3 2.0) (h264) - pt1
  • Crazy Rich Asians (2018) (Comedy) (PG-13) {imdb-tt3104988}\Crazy Rich Asians (2018) (Comedy) (PG-13) [ZHO, ENG] (BluRay 1080p) (AC3 2.0) (h264) - pt2
  • Escape Plan 2 - Hades (2018) (Action) (R) {imdb-tt6513656}\Escape Plan 2 - Hades (2018) (Action) (R) [ENG] (BluRay 720p) (DTS 5.1) (x264)
  • South Park - Bigger, Longer & Uncut (1999) (Animation) (R) {imdb-tt0158983}\South Park - Bigger, Longer & Uncut (1999) (Animation) (R) [ENG] (BluRay 1080p) (AC3 5.1) (x264)
Excellent ;-)
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to add "Part_X" to end of filename for multipart files

Post by kim »

Your format is a mess
maybe use something like this:

Code: Select all

{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{genres =~ /Animation/ ? ' (Animation)' : " ($genre)"}{ any{" ($omdb.certification)"}{" ($certification)"} }{" {imdb-$imdbid}"}.name }/
{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{ any{" ($omdb.certification)"}{" ($certification)"} }{languages ? " ${languages.toString().upper()}" : ''}{allOf{vs}{vf}.joining(' ', ' (', ')') }{allOf{ac}{channels}.joining(' ', ' (', ')') }{" (${vc.replaceAll('AVC','h264').replaceAll('HEVC','h265')})"}{" - pt$pi"}.name }
simonbolster
Posts: 5
Joined: 10 Mar 2021, 17:26

Re: How to add "Part_X" to end of filename for multipart files

Post by simonbolster »

Calling my format a "mess" is putting it politely!! It's a shambles.

Yours on the other hand... there's something to be said for elegant code. And it works perfectly, except...

If the movie is a single-part file, all is well. It returns the following (for example):
/Movies/12 Strong (2018) (War) (R) {imdb-tt1413492}/12 Strong (2018) (War) (R) [ENG] (BluRay 1080p) (AC3 5.1) (x265)
Stupendous. The problem arises when it is a multi-part movie, in which case FileBot appends the string "- CDX" and that causes an issue, particularly in the path.
/Movies/12 Strong (2018) (War) (R) {imdb-tt1413492} - CD2/Movies/12 Strong (2018)/12 Strong (2018) (War) (R) [ENG] (BluRay 1080p) (AC3 5.1) (x265) - pt2 - CD2
I don't mind having the - CD2 at the end of the filename - I can just remove the - pt2 suffix and go with that. It is only the mess it makes of the path that is the problem.

Any suggestions for a tweak to your code that would eliminate this situation? I've tried various approaches but to my shame and the shame of my ancestors I have abjectly failed...
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to add "Part_X" to end of filename for multipart files

Post by kim »

just add

Code: Select all

.replaceAll(/\s-\sCD\d/)

Code: Select all

{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{genres =~ /Animation/ ? ' (Animation)' : " ($genre)"}{ any{" ($omdb.certification)"}{" ($certification)"} }{" {imdb-$imdbid}"}.name.replaceAll(/\s-\sCD\d$/) }/
{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{ any{" ($omdb.certification)"}{" ($certification)"} }{languages ? " ${languages.toString().upper()}" : ''}{allOf{vs}{vf}.joining(' ', ' (', ')') }{allOf{ac}{channels}.joining(' ', ' (', ')') }{" (${vc.replaceAll('AVC','h264').replaceAll('HEVC','h265')})"}{" - pt$pi"}.name.replaceAll(/\s-\sCD\d$/) }
or
replace

Code: Select all

 {" - pt$pi"}
with

Code: Select all

.replaceAll(/CD/,'pt')

Code: Select all

{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{genres =~ /Animation/ ? ' (Animation)' : " ($genre)"}{ any{" ($omdb.certification)"}{" ($certification)"} }{" {imdb-$imdbid}"}.name.replaceAll(/\s-\sCD\d$/) }/
{plex.derive{"${fn.contains('3D') || fn.contains('3-D') ? ' 3D' : ''}"}{ any{" ($omdb.certification)"}{" ($certification)"} }{languages ? " ${languages.toString().upper()}" : ''}{allOf{vs}{vf}.joining(' ', ' (', ')') }{allOf{ac}{channels}.joining(' ', ' (', ')') }{" (${vc.replaceAll('AVC','h264').replaceAll('HEVC','h265')})"}.name.replaceAll(/CD/,'pt') }
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to add "Part_X" to end of filename for multipart files

Post by rednoah »

This is a very entertaining and technically solid thread! :)
:idea: Please read the FAQ and How to Request Help.
Post Reply