JavaScript Engine Language Version Support

Advanced Renamer forum
#1 : 11/01-18 19:38
Romel
Romel
Posts: 2
What is the JavaScript Version Supported by Advaced Renamer?

I made a Script which that use some String functions which looks like aren't implemented in the JS Engine that Advanced Renamer use.

How ever, it was possible implement it using the code that apparears in the Mozilla's JavaScript Reference.

The Script has been tested in web-browsers througth JS Online Testers (Google Chrome, Mozilla Firefox and Internet Explorer 11). Internet Explorer 11 also don't have implemented the Strings functions that I used but - also, implementing the Mozilla's JS code was possible use them.

The three Web Browsers gave me the results that I espected, but Advanced renamer don't (indeed, it fails in a specific case).

Having this entries:
Karakai Jouzu no (Moto) Takagi-san - Capítulo 20 - [NeoProject Scanlation]
Karakai Jouzu no (Moto) Takagi-san - Capítulo 20.5 - [NeoProject Scanlation]

The code modify the name and give me the following results using the web browsers + Online JS Testers (The ones that I want):
Karakai Jouzu no (Moto) Takagi-san - 020 [NeoProject Scanlation]
Karakai Jouzu no (Moto) Takagi-san - 020.5 [NeoProject Scanlation]

But Advanced Renamer gave me:
Karakai Jouzu no (Moto) Takagi-san - 020 [NeoProject Scanlation]
Karakai Jouzu no (Moto) Takagi-san - 020.5 [NeoProject Scanlation].5 - [NeoProject Scanlation]

The latest result is the problema, but only happend when the pseudonumbering have a "." in it.

WHAT AM I DOING WRONG?... I've checked the code a lot of times but only fails in Advanced Renamer!

this is the two functions implemented by code in Advanced Renamer (and Internet Explorer 11):
https://developer.mozilla.org/en-US/docs/Web/Jav aScript/Reference/Global_Objects/String/ padStart
https://developer.mozilla.org/en-US/docs/Web/Jav aScript/Reference/Global_Objects/String/ repeat

Used jsbin.com to test it (https://jsbin.com/culavojonu/1/edit?html,js,output)

The Code used in Advanced Renamer:
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Ensuring count is a 31-bit integer allows us to heavily optimize the
// main part. But anyway, most current (August 2014) browsers can't handle
// strings 1 << 28 chars or longer, so:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var rpt = '';
for (var i = 0; i < count; i++) {
rpt += str;
}
return rpt;
}
}

if (!String.prototype.padStart) {
String.prototype.padStart = function padStart(targetLength,padString) {
targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
padString = String((typeof padString !== 'undefined' ? padString : ' '));
if (this.length > targetLength) {
return String(this);
}
else {
targetLength = targetLength-this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
}
return padString.slice(0,targetLength) + String(this);
}
};
}

/*
Determino donde aparece la frase " Capítulo ".
Parto entonces la primera parte del Nombre - la Izq, desde el principio hasta donde aparece " Capítulo "
*/
var NombreDelArchivo = item.name;
var CadenaCapitulo = ' Capítulo ';
var DondeEstaCapitulo = NombreDelArchivo.indexOf(CadenaCapitulo);
var NombreDelArchivoIzquierda = NombreDelArchivo.slice(0,DondeEstaCapitulo);

/*
Corto el nombre con lo que está delante de la palabra " Capítulo " = Número del Capitulo así como el [FANSUB] que lo creó
Determino el lugar donde aparece la próximo juego "Separador" entre el número del Capítulo y el Nombre del Fansub = " - ["
Entonces Corto desde la Izq hasta donde aparece el separador para sacar la numeración del capítulo.
*/
NombreDelArchivo = NombreDelArchivo.slice(DondeEstaCapitulo+CadenaCapitulo.length);
CadenaCapitulo = ' - [';
DondeEstaCapitulo = NombreDelArchivo.indexOf(CadenaCapitulo);
var NumeroDelCapitulo = NombreDelArchivo.slice(0,DondeEstaCapitulo);

/*
Ahora voy a padear a 3 los dígitos del capítulo... PERO.
si tiene un caracter "." como los capítulos "extras" - lo de la izquierda no puedo padearlo sólo a 3
Sería los 3 más los caracteres extras después del punto...
Identifico donde está, y lo resto del ancho total para saber cuantos caracteres de más hay
Entonces padeo los 3 + los caracteres de más.
Sino, simplemente padeo a 3
*/
if (NumeroDelCapitulo.indexOf('.')!= -1)
NumeroDelCapitulo = NumeroDelCapitulo.padStart(3 + ( NumeroDelCapitulo.length - NumeroDelCapitulo.indexOf('.') ) ,'0');
else
NumeroDelCapitulo = NumeroDelCapitulo.padStart(3,'0');

/*
El resto del nombre sería desde donde aparece el " - [" + 3 (quitando el " - " = 3 caracteres, dejando desde el "[")
*/
var NombreDelArchivoDerecha = NombreDelArchivo.slice(DondeEstaCapitulo+3);
var NuevoNombreParaTMO = NombreDelArchivoIzquierda + ' ' + NumeroDelCapitulo + ' ' + NombreDelArchivoDerecha;

return NuevoNombreParaTMO;









11/01-18 19:38
#2 : 12/01-18 08:33
Stefan
Stefan
Posts: 264
Reply to #1:
All that code to just remove one word, 'Capítulo', ?



Me guess ARen has no full 'JS' support, just the basics as need to rename some files.




 

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


12/01-18 08:33
#3 : 16/01-18 16:25
Romel
Romel
Posts: 2
Reply to #2:
Now I know what had happend.
I've started to use regular expressions to commit the changes that I want...
The Script Works fine (tested in https://es6console.com/jch83rrr/ )
The Regular Expression it's fine (tested in https://www.regextester.com/ )

The issue happend because how "Script" function works: "Remember the new filename must contain the extension of the file."

So, because I was renaming - not files but folders... THEY DON'T HAVE "EXTENSIONS". then, the script must be applied to "Name And Extension" rather than "Name"; If don't, the software use the last occurence of a dot "." in the folder name as its extension, with the result - duplicate the last part of the folder name.

Original Name:
Rokudou no Onna-tachi - Vol.9 Ch.75 The Fastest Delivery Man [Cyan Steam]

Script applied to "Name And Extensión":
Rokudou no Onna-tachi - Vol.09 Ch.075 The Fastest Delivery Man [Cyan Steam]

Script applied to "Name":
Rokudou no Onna-tachi - Vol.09 Ch.075 The Fastest Delivery Man [Cyan Steam].75 The Fastest Delivery Man [Cyan Steam]


16/01-18 16:25
#4 : 16/01-18 18:16
Stefan
Stefan
Posts: 264
Reply to #3:
Good find, never had think on this.
Glade you solved this out yourself.
Thanks for sharing the solution!







 
 

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


16/01-18 18:16 - edited 16/01-18 21:15