trimleft() trimright() functions

All about user-defined episode / movie / file name format expressions
Post Reply
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

trimleft() trimright() functions

Post by stephen147 »

Nearly complete my code for processing folders, movies and srt files all in one go :)

Just need a trim right or left in my case fn. Can't see any examples on here.

Code: Select all

{n.replace(':','-').replaceAll(/[\/:*?"<>|]/,' - ')}    ({y})    { if (self.ext =~ /srt|sub|sbv|idx|ssa|ass|stl/) "" else {any{' Part '+pi.pad(2)}{""}}}    {any{fn.match(/\([^\()+?[^\d]+?\)\s*/)} {""}{''}}   {self.vf ? self.vf + "" : self.hpi}    {"${self.source ?: 'WEB-DL'}"}    {ac}    {af.replaceAll(/2ch/, "2ch").replaceAll(/6ch/, "5.1ch")}    {vc}{any{"_$group"}{fn.match(/_[^\.]$/)}{'_NA'}}{any{file.name.match(/((?i)(\.|_|-)(en|en.{1,15}?foreign.{1,20}?|es|sw|sp)([a-z]*?))\.(srt|sub|sbv|idx|ssa|ass|stl)$/)}{""}{"."}.lower()}{"."+ext}  
So the code I'm needing assistance on is:

Code: Select all

{any{file.name.match(/((?i)(\.|_|-)(en|en.{1,15}?foreign.{1,20}?|es|sw|sp)([a-z]*?))\.(srt|sub|sbv|idx|ssa|ass|stl)$/)}{""}{"."}.lower()}
Is appending .trimleft(3) to .lower() possible to achieve subtitle files with:

newfilename.eng.srt instead of:
newfilename.english.srt
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: trimleft() trimright() functions

Post by rednoah »

My way:

Code: Select all

{'english'.replace('english', 'eng')}
Your way, Groovy style:

Code: Select all

{'english'[0..2]}
Your way, Java style:

Code: Select all

{'english'.substring(0,3)}
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: trimleft() trimright() functions

Post by stephen147 »

This code works using a regular expression:

Changing:
.english.srt >>>> .eng.srt

Code: Select all

{any{file.name.match(/((?i)(\.|_|-)(en|en.{1,15}?foreign.{1,20}?|es|sw|sp)([a-z]*?))\.(srt|sub|sbv|idx|ssa|ass|stl)$/)}{""}{"."}.lower().replaceAll("(^.[a-zA-Z]{3}).+",'$1')}{"."+ext}
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: trimleft() trimright() functions

Post by rednoah »

If the filename ends with .english.srt then FileBot will detect the language {lang} based on that, hence:

Code: Select all

{'.'+lang}
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: trimleft() trimright() functions

Post by stephen147 »

Thanks. 10x better!! ;)
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: trimleft() trimright() functions

Post by stephen147 »

Can Filebot recognise.

.eng
.es


etc.

{lang} is coming up undefined
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: trimleft() trimright() functions

Post by rednoah »

1.
Yes, FileBot can recognize ISO 639-1, ISO 639-2/B and ISO 639-2/T language codes.


2.
Please post a screenshot of the format dialog that shows the filename {fn} and subtitle language {lang} being undefined.
:idea: Please read the FAQ and How to Request Help.
Post Reply