Keep everything that's not already in the new name?

All about user-defined episode / movie / file name format expressions
Post Reply
fluxtendu
Posts: 3
Joined: 19 Mar 2016, 20:20

Keep everything that's not already in the new name?

Post by fluxtendu »

Hi,

My sample files are:
  • 11.22.63.S01E04.WEBRip.XviD-FUM[ettv].avi
    11.22.63.105.hdtv-lol[ettv].mp4
and I would like to get :
  • /11.22.63/S01/11.22.63 - S01E04 - episode title (WEBRip.XviD-FUM[ettv]).avi
    /11.22.63/S01/11.22.63 - S01E05 - another episode title (hdtv-lol[ettv]).mp4
The first part is easy to achieve with this

Code: Select all

/{n}/{episode.special ? 'Special' : 'S'+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t}
But how to get the part in bold that corresponds to everything that's not already in the new name?

(I know that I can use {group} {vc}, etc... But I want to keep everything, not just those that match)

Thank you.
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Keep everything that's not already in the new name?

Post by rednoah »

You could try something like this:

Code: Select all

{fn.after(/S\d+E\d+./)}
Or this:

Code: Select all

{fn.match(/(?:WEBRip|hdtv).+$/)}
Either way, you'll have to tweak the regex patterns.
:idea: Please read the FAQ and How to Request Help.
fluxtendu
Posts: 3
Joined: 19 Mar 2016, 20:20

Re: Keep everything that's not already in the new name?

Post by fluxtendu »

Thank you!

The first one is what I was looking for... I ended up with:

Code: Select all

{fn.after(/[- ._](S\d+E\d+|\d{3,4}|\d+x\d+)[- ._]/)}
That match anything after those: ".S02E04." " 1x05 " "-108-" "_01X07_" ".s3e5-" etc...

But my quest to find the perfect naming scheme gave me two more questions:

1) Can I use tags (e.g. {n},{t}) in regular expressions? Something like

Code: Select all

{fn.replaceAll({n},"")}
My tests were not successful, but maybe it's me...

2) In my sample names from the first post, there's two {group}, and filebot always give me the second one: ettv, how can I get the first one? Is it possible to not parse specific part of a name?
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Keep everything that's not already in the new name?

Post by rednoah »

1.
Outer {...} (FileBot Groovy expressions) have completely different semantics from inner {...} (Groovy closure).

You want:

Code: Select all

fn.replaceAll(n, '')
@see viewtopic.php?f=5&t=1895


2.
{group} will pick the last one. If combinations like FUM[ettv] where to be added to the groups list it could probably work.

@see viewtopic.php?f=5&t=4
:idea: Please read the FAQ and How to Request Help.
fluxtendu
Posts: 3
Joined: 19 Mar 2016, 20:20

Re: Keep everything that's not already in the new name?

Post by fluxtendu »

1) Yes I was looking for replaceAll(n, '')
but do you have something like:

Code: Select all

fn.replaceAll(y, '')

to replace the year?

I try to adapt the code for movies, but the year is not always in the source name and I don't have other unique separator, so I imagined something like this:

Code: Select all

/{n} ({y})/{n} - {y}{' CD'+pi}{'.'+lang}{' ('+fn.replaceAll(n.space('.'), '').replaceAll(n, '').replaceAll(y, '').+')'}
(I also need to remove the first character if it's one of these character: ._ - but I will try later...)

2) I do not want that the combination of groups is added and recognized, but that the group [ettv] is excluded to keep only the other part.
The best I have found is this:

Code: Select all

/{n}/{episode.special ? 'Special' : 'S'+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t} {"("+fn.after(/[- ._](S\d+E\d+|\d{3,4}|\d+x\d+)[- ._]/).replaceAll("\\[ettv\\]", '')+")"}
But a personal exclusion list would be helpful to avoid growing code... (Ideally used before parsing)
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Keep everything that's not already in the new name?

Post by rednoah »

1.
If it doesn't work already, it's probably because replaceAll wants a String and y gives you an Integer.

This will work:
fn.replaceAll(y as String, '')

Replace leading ._ characters:
fn.replaceAll(/^[._]+/, '')


2.
You'll need your own group matching logic then. You can use text files. FileBot gives you the csv(path) or readLines(path) functions to do that easily.
:idea: Please read the FAQ and How to Request Help.
Post Reply