Page 1 of 1

trimleft() trimright() functions

Posted: 05 Sep 2015, 20:36
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

Re: trimleft() trimright() functions

Posted: 06 Sep 2015, 08:33
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)}

Re: trimleft() trimright() functions

Posted: 17 Oct 2016, 14:55
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}

Re: trimleft() trimright() functions

Posted: 17 Oct 2016, 18:26
by rednoah
If the filename ends with .english.srt then FileBot will detect the language {lang} based on that, hence:

Code: Select all

{'.'+lang}

Re: trimleft() trimright() functions

Posted: 18 Oct 2016, 13:47
by stephen147
Thanks. 10x better!! ;)

Re: trimleft() trimright() functions

Posted: 13 Apr 2017, 12:39
by stephen147
Can Filebot recognise.

.eng
.es


etc.

{lang} is coming up undefined

Re: trimleft() trimright() functions

Posted: 13 Apr 2017, 13:25
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.