Renaming titles starting with "The" to a comma

Support for Windows users
Post Reply
Rancor
Posts: 3
Joined: 18 Nov 2024, 08:40

Renaming titles starting with "The" to a comma

Post by Rancor »

Hi rednoah, shout out from Melbourne, Australia. Love your product and have been using it forever.

I am a registered user running FileBot v.5.1.1 on a Windows 2019 Server.

I have had a problem for a while that I am not entirely sure how to fix, couldn't fix a solution in the forum, so here we go.
In short I want movies that starts with The, for example "The Artifice Girl (2022)" to be renamed: "Artifice Girl, The".
The following script was working at some stage but no more it seems.

I am running a PowerShell script on a scheduler that checks a folder and renames the content, here is the command pruned for easy reading:

Console Output: Select all

Start-Process -FilePath "C:\Program Files\FileBot\filebot.exe" -ArgumentList `
@(
"-script fn:amc X:\_Downloads\Complete --output X:\",
"--def movieFormat=`"{n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')/n.sortName('$2, $1')}{' CD'+pi}`"",
"--def seriesFormat=`"Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}`" -non-strict",
"--def clean=y",
"--def ignore=_UNPACK_",
"--conflict skip",
"--def subtitles=en",
"--def plex=192.168.60.2:XXXXXXXXXXXXXXXXXXXX",
"--log-file $LogFile"
) -NoNewWindow -Wait
Now this does work 99% of the time, except if the titles starts with "The", in that case both the subtitle and movie file gets renamed to a comma.
See below FileBot log output for an example.

Console Output: Select all

Run script [fn:amc] at [Sun Nov 17 22:40:05 AEDT 2024]
Parameter: movieFormat = {n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName(', ')/n.sortName(', ')}{' CD'+pi}
Parameter: seriesFormat = Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}
Parameter: clean = y
Parameter: ignore = _UNPACK_
Parameter: subtitles = en
Parameter: plex = *****
Argument[0]: X:\_Downloads\Complete
Input: X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4
Input: X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt
Group: {Movie=The Artifice Girl (2023), Series=null} => [The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4, The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt]
Rename movies using [TheMovieDB]
Auto-detect movie from context [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4]
[MOVE] from [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4] to [X:\Movies\,\,.mp4]
[MOVE] from [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt] to [X:\Movies\,\,.srt]
Processed 2 files
Clean clutter files and empty folders
Done ヾ(@⌒ー⌒@)ノ
Any suggestions on how I fix this?
User avatar
rednoah
The Source
Posts: 23924
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Renaming titles starting with "The" to a comma

Post by rednoah »

PowerShell is interpreting the $1 and $2 before the format is passed onto FileBot, and so the format you think you are using is not the format you are actually using.

This is the format you effectively pass:

Console Output: Select all

Parameter: movieFormat = {n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName(', ')/n.sortName(', ')}{' CD'+pi}

Groovy: Select all

n.sortName(', ')
and so filebot does what it is instructed to do exactly. Unfortunately, your accidental code is valid enough to parse, but does of course not work as intended when used to generate target file paths.



:idea: Please read Cmdline and Argument Passing › Escape Arguments for details and examples.


:arrow: You will want to use @file syntax for reading command-line arguments from external text files for all static text argument values:

Shell: Select all

filebot @X:/amc.args --log-file "$LogFile"
:idea: Please read the FAQ and How to Request Help.
Rancor
Posts: 3
Joined: 18 Nov 2024, 08:40

Re: Renaming titles starting with "The" to a comma

Post by Rancor »

I ended up getting it working using a Filebot args file (as per your suggestion) and adding relevant parameters in there, looking like this:

filebot_folderchanges_args.txt

Console Output: Select all

-script
fn:amc
X:\_Downloads\Complete
--output
X:\
--def
movieFormat={n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')/n.sortName('$2, $1')}{' CD'+pi}
seriesFormat=Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}
-non-strict
--def
clean=y
--def
ignore=_UNPACK_
--conflict
skip
--def
subtitles=en
--def
plex=192.168.60.2:xxxxxxxxxxxxxxxxxxxx

And here is an pruned example of the renaming.

Console Output: Select all

Run script [fn:amc] at [Wed Nov 20 00:13:29 AEDT 2024]
Parameter: movieFormat = {n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')[/color]/n.sortName('$2, $1')[/color]}{' CD'+pi}
Parameter: seriesFormat = Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}
Parameter: clean = y
Parameter: ignore = _UNPACK_
Parameter: subtitles = en
Parameter: plex = *****
Argument[0]: X:\_Downloads\Complete
Input: X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4
       └─ Metadata: The Artifice Girl (2023)
Input: X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt
       └─ Metadata: The Artifice Girl (2023)
Group: {Movie=The Artifice Girl (2023)} => [The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4, The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt]
Rename movies using [TheMovieDB]
Auto-detect movie from context [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4]
[XATTR] The Artifice Girl (2023) (X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4)
[MOVE] from [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4] to [X:\Movies\Artifice Girl, The\Artifice Girl, The.mp4]
[MOVE] from [X:\_Downloads\Complete\The Artifice Girl (2022) [1080p] [WEBRip] [5.1] [YTS.MX]\The.Artifice.Girl.2022.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt] to [X:\Movies\Artifice Girl, The\Artifice Girl, The.srt]
Processed 2 files
Done ヾ(@⌒ー⌒@)ノ
Seeing ('$2, $1') being passed, and correct renaming [X:\Movies\Artifice Girl, The\Artifice Girl, The.mp4]

So that's now working which is great, thank you sir...

But the reality is I would really like to get it working in script, as the script have a good amount of pre-checks and post cleanup tasks and I like the idea of having everything isolated in that one script without having to get those parameters from a separate file.

As a result I read though the recommended KB's you mentioned and did a additional research from these articles touching on the same issue.
viewtopic.php?t=9895
viewtopic.php?f=5&t=211
viewtopic.php?t=11304

In the last article you a mention quote:
You're using "..." so $1 and $2 are interpreted by your shell, and expanded to empty string. You'll need to use '...' to pass $ literally. That also implies that the ' occurring literally in your format, will need to be escaped or replaced appropriately.

So based on that information I was trying to modify my own original PowerShell script in attempting to escape the $ entries, but didn't get it working yet.

Format: Select all

"--def movieFormat=`"{n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')/n.sortName('$2, $1')}{' CD'+pi}`"",
Do you think it is possible with the correct syntax to get it working with my existing PowerShell script and if not maybe it would be it possible to instead use the line separation already applied in the filebot_folderchanges_args.txt (which is working) but instead put those same entries directly in script as workaround.

Any suggestions in which direction I could go in an attempt to try to get it working all in script?
Last edited by Rancor on 20 Nov 2024, 02:58, edited 1 time in total.
User avatar
rednoah
The Source
Posts: 23924
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Renaming titles starting with "The" to a comma

Post by rednoah »

I'd go with Quoting Rules :: Here-strings if you need to pass complex argument values from PowerShell code:

powershell: Select all

echo @'
movieFormat={n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')/n.sortName('$2, $1')}{' CD'+pi}
'@
:idea: Please read the FAQ and How to Request Help.
Rancor
Posts: 3
Joined: 18 Nov 2024, 08:40

Re: Renaming titles starting with "The" to a comma

Post by Rancor »

I played around with with the Here-strings and I can see how that might be a good idea, however after reading up Quoting Rules
https://learn.microsoft.com/en-us/power ... rshell-7.4

I found out the the back-tick or ` can be used in PowerShell as the escape character, after that I amended my code to this:

Console Output: Select all

$Args = @(
    "-script fn:amc X:\_Downloads\Complete --output X:\",
    "--def movieFormat=`"{n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('`$2, `$1')/n.sortName('`$2, `$1')}{' CD'+pi}`"",
    "--def seriesFormat=`"Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}`" -non-strict",
    "--def clean=y",
    "--def ignore=_UNPACK_",
    "--conflict skip",
    "--def subtitles=en",
    "--def plex=192.168.60.2:xxxxxxxxxxxxxxxxxxxx",
    "--action test"
    )

Start-Process -FilePath "C:\Program Files\FileBot\filebot.exe" -ArgumentList $Args -Verbose -NoNewWindow -Wait

Amending these entries to be specific.
Screenshot
Now getting what I wanted with the original code:

Console Output: Select all

Run script [fn:amc] at [Wed Nov 20 14:40:03 AEDT 2024]
Parameter: movieFormat = {n =~ /UFC/ ? 'UFC'/n.sortName() : 'Movies'/n.sortName('$2, $1')/n.sortName('$2, $1')}{' CD'+pi}
Parameter: seriesFormat = Series/{n.sortName()}/{'Season '+s}/{n.sortName()} {s00e00}
Parameter: clean = y
Parameter: ignore = _UNPACK_
Parameter: subtitles = en
Parameter: plex = *****
Argument[0]: X:\_Downloads\Complete
[TEST] --def clean is incompatible with --action TEST and has been disabled
Input: X:\_Downloads\Complete\The Artifice Girl\The Artifice Girl.mp4
       └─ Metadata: The Artifice Girl (2023)
Group: {Movie=The Artifice Girl (2023)} => [The Artifice Girl.mp4]
Rename movies using [TheMovieDB]
Auto-detect movie from context [X:\_Downloads\Complete\The Artifice Girl\The Artifice Girl.mp4]
[XATTR] The Artifice Girl (2023) (X:\_Downloads\Complete\The Artifice Girl\The Artifice Girl.mp4)
[TEST] from [X:\_Downloads\Complete\The Artifice Girl\The Artifice Girl.mp4] to [X:\Movies\Artifice Girl, The\Artifice Girl, The.mp4]
Processed 1 files
Finished without processing any files
Done ¯\_(ツ)_/¯

Full script action seen here:
Screenshot

Hope someone finds this useful.

Thanks rednoah for your constructive feedback...
Post Reply