How to match "year - director - moviename.ext"

All about user-defined episode / movie / file name format expressions
Post Reply
MagnusDaMan
Posts: 4
Joined: 27 Jul 2020, 12:33

How to match "year - director - moviename.ext"

Post by MagnusDaMan »

Hi.
I am trying to figure out how to do the matchings for movies.
I have worked with regular expressions in two other programming languages, but find this very hard.

All my movies are in the format of "1984 - James Cameron - Peace and Love.mkv".
If I want to have the result "Peace and Love (1984)", I need to somehow identify the director name and then ignore it,or don't I?
I have tried to use the fn.after, but I can't figure out how to match after the second " - ".
In the "Format expressions" page https://www.filebot.net/naming.html I found that there is a function names "di", but I can't figure out how to use it.
And I'm not even sure if this is the way to go.

Any help would be greatly appreciated.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to match "year - director - moviename.ext"

Post by rednoah »

Use Plain File Mode to pre-process your files into nice Name (Year) patterns first before matching them against TheMovieDB in a second step:

Code: Select all

{fn.after(" - ").after(" - ")} ({fn.before(" - ")})
:idea: Please read the FAQ and How to Request Help.
MagnusDaMan
Posts: 4
Joined: 27 Jul 2020, 12:33

Re: How to match "year - director - moviename.ext"

Post by MagnusDaMan »

Oh yes!

Thank you!
As usual, when you see the solution, you think "Oh, it was that easy...".
It would have taken me some time to figure that one out though.

Works like a charm!
Thanks a lot.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to match "year - director - moviename.ext"

Post by kim »

or with regex

Code: Select all

{fn.replaceAll(/(^(?:19|20)\d{2}) - (.+) - (.+)$/),'$3 ($1) - $2'}
Peace and Love (1984) - James Cameron
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to match "year - director - moviename.ext"

Post by rednoah »

This also works quite nicely~ :lol:

Code: Select all

{fn.split('-', 3)[2,0].join(' ')}
:idea: Please read the FAQ and How to Request Help.
MagnusDaMan
Posts: 4
Joined: 27 Jul 2020, 12:33

Re: How to match "year - director - moviename.ext"

Post by MagnusDaMan »

After some testing neither of these work very well.
When I create a preset (Named Movies and set datasource to TheMovieDB) and try {fn.replaceAll(/(^(?:19|20)\d{2}) - (.+) - (.+)$/),'$3 ($1) - $2'}, then "11940 - Anatole Litvak - City for Conquest.avi" becomes "City for Conquest (1940) - Anatole Litvak".

When using the format {fn.split('-', 3)[2,0].join(' ')} in file mode it can't find anything, but sends up the popup "Please identify the following files".
(Just a question on the split. Is the number 3 the third part? Does this mean that the split is 1-based and not 0-based?)

It seems to me that the {fn.after(" - ").after(" - ")} ({fn.before(" - ")}) gets more matches than the other two do.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to match "year - director - moviename.ext"

Post by kim »

rednoah wrote: 28 Jul 2020, 11:40 Use Plain File Mode to pre-process your files into nice Name (Year) patterns first before matching them against TheMovieDB in a second step:

Code: Select all

{fn.after(" - ").after(" - ")} ({fn.before(" - ")})
MagnusDaMan wrote: 29 Jul 2020, 12:39 When I create a preset (Named Movies and set datasource to TheMovieDB) and try {fn.replaceAll(/(^(?:19|20)\d{2}) - (.+) - (.+)$/),'$3 ($1) - $2'}, then "11940 - Anatole Litvak - City for Conquest.avi" becomes "City for Conquest (1940) - Anatole Litvak".
this new filename works 100%, sounds like you don't do the 2 steps
1. rename using this format
2. match using an other format e.g.

Code: Select all

 {plex.tail}
MagnusDaMan
Posts: 4
Joined: 27 Jul 2020, 12:33

Re: How to match "year - director - moviename.ext"

Post by MagnusDaMan »

Ok. That renaming works perfect if there is only the movie file itself. I removed the name of the director, since I don't need it. I want to add a library to it as well, so I changed it to:

Code: Select all

{fn.replaceAll(/(^(?:19|20)\d{2}) - (.+) - (.+)$/),'./$3 ($1)/$3 ($1)'}
and then it works perfect for one file.
But when I have subtitles as well, then each subtitle get's it's own folder as well, so that becomes very weird.

I have to understand this second step as well. I am using Emby, so I guess plex is not right (or is it?). And in which format would this be used? In the movie format?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to match "year - director - moviename.ext"

Post by rednoah »

1.
You'll need to adjust your format to account for subtitles as well. Please read How to Request Help if you need more specific help.


2.
{plex} will work just fine. Emby will be happy with standard Plex naming.
:idea: Please read the FAQ and How to Request Help.
Post Reply