Best method for keeping filename specific info

Any questions? Need some help?
Post Reply
ByteShare
Posts: 7
Joined: 13 Mar 2018, 15:38

Best method for keeping filename specific info

Post by ByteShare » 11 May 2018, 07:43

I'm using a script like this for movies:

Code: Select all

{n.upperInitial()} ({y}) {' CD'+pi} {fn.match(/(?i)Unrated/).replaceAll('(?i)Unrated','[UR]')} {fn.match(/(?i)\[UR\]/).replaceAll('(?i)UR','UR')} {fn.match(/(?i)DC/).replaceAll('(?i)DC','[DC]')} {fn.match(/(?i)ENG,JPN/).replaceAll('(?i)ENG,JPN','[ENG,JPN]')} {fn.match(/(?i)\[Comm\]/).replaceAll('(?i)Comm','Comm')} {fn.match(/(?i)Commentary/).replaceAll('(?i)Commentary','[Comm]')} {fn.match(/(?i)\[Rifftrax\]/).replaceAll('(?i)Rifftrax','Rifftrax')} {fn.match(/(?i)\[Doc\]/).replaceAll('(?i)Doc','Doc')}{'.'+lang}
My question is using the

Code: Select all

{fn.match(/PATTERN/).replaceAll('PATTERN','PATTERN')}
over and over the best method?
I was hoping for something like:

Code: Select all

{fn.match(/.*/).replaceAll('PATTERN01','PATTERN01'|'PATTERN02','PATTERN02')}
or something?

I suppose it doesn't matter that much in terms of total length but it does add up.

User avatar
rednoah
The Source
Posts: 13407
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Best method for keeping filename specific info

Post by rednoah » 11 May 2018, 08:57

A few of those replacements could be better handled in a more generic way, and not by handling one by one pattern.

e.g. matching multiple patterns and adding [...] to each of them:

Code: Select all

{'[' + fn.match(/Rifftrax|Dic/).upperInitial() + ']'}
e.g. check if pattern is found, and then yield arbitrary value:

Code: Select all

{fn.match(/Commentary/); '[Comm]'}
e.g. upper-case all characters:

Code: Select all

{fn.match(/\[(UR|DC)\]/).upper()}
My (very excellent) support depends on Windows Store and Mac App Store sales and Patreon support. Paying users, donors and everyone who contributes to FileBot in one way or another will get the very best support.

:idea: Please read the FAQ and How to Request Help.

ByteShare
Posts: 7
Joined: 13 Mar 2018, 15:38

Re: Best method for keeping filename specific info

Post by ByteShare » 11 May 2018, 19:52

Thank you for the ideas.
Using a text file: "Water Boyy (2015) [UR] [Comm] [Doc].txt"
I tried the following:
A:

Code: Select all

{n.upperInitial()} ({y}) {' CD'+pi} {'[' + fn.match(/Riff|Doc|UR|Comm/).upperInitial() + ']'}
Is sorta of the same problem I was already having with the pipes [Or: "|"], it is only matching the first thing and not doing all of them if they are in the filename.

B:

Code: Select all

{n.upperInitial()} ({y}) {' CD'+pi} {fn.match(/[\Comm\]/); 'Comm'}
I tried it with and without the "[\" around the match but with only the 'Comm' it only puts "Comm" without brackets and if I put it '\[Comm\]' I get an error with my syntax, and if I put just '[Comm]' it yields nothing.

C:

Code: Select all

{n.upperInitial()} ({y}) {fn.match(/\[(UR|DC)\]/).upper()}
This works as well, but like with A, it only matches one at a time.

Is there a way to match several things like in A and C but also keep the loop going to match more things.

I was hoping to take a file like "Water.Boyy.2015.Unrated.HEVC.1080p.Commentary.Documentary.txt" or "Water Boyy [UR] [Comm] [Doc].txt" (say missing the year because I did it manual a long time ago but keep my personalized info) and turn both into:
"Water Boyy (2015) [UR] [Comm] [Doc].txt"

kim
Power User
Posts: 531
Joined: 15 May 2014, 16:17

Re: Best method for keeping filename specific info

Post by kim » 12 May 2018, 02:26

Try

Code: Select all

matchAll

Code: Select all

{fn.matchAll(/\[(UR|DC)\]/).toString().upper()}
wrong:

Code: Select all

{fn.match(/[\Comm\]/); 'Comm'}
ok:

Code: Select all

{fn.match(/\[Comm\]/); 'Comm'}

Water.Boyy.2015.Unrated.HEVC.1080p.Commentary.Documentary or Water Boyy [UR] [Comm] [Doc]
both to
Water Boyy (2015) [UR] [Comm] [Doc]
use this

Code: Select all

{n.upperInitial()} ({y}) {fn.matchAll(/Unrated|\[UR\]/)? '[UR]' : ''} {fn.matchAll(/Commentary|\[Comm\]/)? '[Comm]' : ''} {fn.matchAll(/Documentary|\[Doc\]/)? '[Doc]' : ''}

ByteShare
Posts: 7
Joined: 13 Mar 2018, 15:38

Re: Best method for keeping filename specific info

Post by ByteShare » 12 May 2018, 16:05

Thank you a ton. The difference between someone that knows what they're doing a me a monkey at a keyboard is a-mazing!
The matchAll is nice because it also matches different cases so I don't need to use (?i) in front of expressions.
My over all script went from 903 characters to 669, and I still have things to add, this will help a lot.
Thank you again.

ByteShare
Posts: 7
Joined: 13 Mar 2018, 15:38

Re: Best method for keeping filename specific info

Post by ByteShare » 13 May 2018, 14:58

Thank you all for the help again. Incase anyone wanted to see what I've come up with thus far with the help...
Movie:

Code: Select all

.\{n.upperInitial()} ({y}) {fn.matchAll(/\[(ENG|JPN|SPA|GER|RUS|CHI|ENG,JPN)\]/).toString().upper()} {fn.matchAll(/Commentary|\[Comm\]/)? '[Comm]' : ''} {fn.matchAll(/\[Rifftrax]|\[Riff]/)? '[Riff]' : ''} {fn.matchAll(/Documentary|\[Doc\]/)? '[Doc]' : ''}/{n.upperInitial()} ({y}) {' CD'+pi} {fn.matchAll(/Unrated|\[UR\]/)? '[UR]' : ''} {fn.matchAll(/Directors Cut|Director's Cut|\[DC]/)? '[DC]' : ''} {fn.matchAll(/Theatre Cut|Theatrical Cut|Theatre Edition|Theatrical Edition|\[TC]/)? '[TC]' : ''} {fn.matchAll(/Extended Edition|\[Ext]|\[EE]/)? '[EE]' : ''} {fn.matchAll(/Special Edition|\[SE]/)? '[SE]' : ''} {fn.matchAll(/\[(ENG|JPN|SPA|GER|RUS|CHI|ENG,JPN)\]/).toString().upper()} {fn.matchAll(/Commentary|\[Comm\]/)? '[Comm]' : ''} {fn.matchAll(/\[Rifftrax]|\[Riff]/)? '[Riff]' : ''} {fn.matchAll(/Documentary|\[Doc\]/)? '[Doc]' : ''} {'.'+lang}
I know there is a way to handle the "Directors Cut" and "Director's Cut" I didn't notice it until just now.

TV:

Code: Select all

.\{n.replaceAll(/[?:.]+$/).replaceAll(/[`´???]/, "'") .upperInitial()} {fn.matchAll(/\[(ENG|JPN|SPA|GER|RUS|CHI|ENG,JPN)\]/).toString().upper()} {fn.matchAll(/Commentary|\[Comm\]/)? '[Comm]' : ''} {fn.matchAll(/\[Rifftrax]|\[Riff]/)? '[Riff]' : ''} {fn.matchAll(/Documentary|\[Doc\]/)? '[Doc]' : ''}\{n.replaceAll(/[?:.]+$/).replaceAll(/[`´???]/, "'").upperInitial()} {episode.special ? '00x'+special.pad(2) : s.pad(2)+'x'+es*.pad(2).join('-')} {t.replaceAll(/[?:.]+$/).replaceAll(/[`´???]/, "'").upperInitial().replacePart(', Part $1')} {" "+fn.match(/\(Part \d+/)+")"} {fn.matchAll(/Unrated|\[UR\]/)? '[UR]' : ''} {fn.matchAll(/Extended Edition|\[Ext]|\[EE]/)? '[EE]' : ''} {fn.matchAll(/Directors Cut|Director's Cut|\[DC]/)? '[DC]' : ''} {fn.matchAll(/Special Edition|\[SE]/)? '[SE]' : ''} {fn.matchAll(/\[(ENG|JPN|SPA|GER|RUS|CHI|ENG,JPN)\]/).toString().upper()} {fn.matchAll(/Commentary|\[Comm\]/)? '[Comm]' : ''} {fn.matchAll(/\[Rifftrax]|\[Riff]/)? '[Riff]' : ''} {fn.matchAll(/Documentary|\[Doc\]/)? '[Doc]' : ''} {'.'+lang}
I'm very happy with my TV one being able to handle multipart episodes as well as special episodes at the same time.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest