JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 02.10.2022, 23:02
verheiratet1952 verheiratet1952 is offline
Black Hole
 
Join Date: Jan 2016
Posts: 285
Default special characters renaming with eventscripter

I have some eventscripter using as packagizer hook to rename special characters when crawling content to get clean package names...

it is::
if (state = "AFTER") {
var name = link.getPackageName();
if (name) {
var newName = name;
newName = newName.replace(//g, "");
newName = newName.replace("&", "and");
newName = newName.replace("@", "-");
newName = newName.replace("andamp;", "-");
newName = newName.replace("-r-", "-");
newName = newName.replace(" R-", "-");
newName = newName.replace(" r-", "-");
newName = newName.replace("xpost", "-");
newName = newName.replace("x-post", "-");
newName = newName.replace("https", "-");
newName = newName.replace("http", "-");
newName = newName.replace("-R-", "-");
newName = newName.replace("Xpost", "-");
newName = newName.replace("X-post", "-");
newName = newName.replace("XPost", "-");
newName = newName.replace("X-Post", "-");
newName = newName.replace("XPOST", "-");
newName = newName.replace("X-POST", "-");
newName = newName.replace(" IMG", "-");
newName = newName.replace("-IMG", "-");
newName = newName.replace(/'/g, "");
newName = newName.replace(//gi, "a");
newName = newName.replace(//gi, "e");
newName = newName.replace(//gi, "i");
newName = newName.replace(//gi, "o");
newName = newName.replace(//gi, "u");
newName = newName.replace(//gi, "ae");
newName = newName.replace(//gi, "oe");
newName = newName.replace(//gi, "ue");
newName = newName.replace(//gi, "a");
newName = newName.replace(//gi, "e");
newName = newName.replace(//gi, "i");
newName = newName.replace(//gi, "o");
newName = newName.replace(//gi, "u");
newName = newName.replace(//gi, "a");
newName = newName.replace(//gi, "e");
newName = newName.replace(//gi, "i");
newName = newName.replace(//gi, "o");
newName = newName.replace(//gi, "u");
newName = newName.replace(//gi, "a");
newName = newName.replace(//gi, "n");
newName = newName.replace(//gi, "c");
newName = newName.replace(//gi, "o");
newName = newName.replace(//gi, "o");
newName = newName.replace(//gi, "y");
newName = newName.replace(//gi, "a");
newName = newName.replace(//gi, "e");
newName = newName.replace(//gi, "i");
newName = newName.replace(//g, "ss");
newName = newName.replace(/ł/gi, "l");
newName = newName.replace(//gi, "ae");
newName = newName.replace(//gi, "d");
newName = newName.replace(//gi, "s");
newName = newName.replace(/č/gi, "c");
newName = newName.replace(//gi, "n");
newName = newName.replace(/ş/gi, "s");
newName = newName.replace(/ć/gi, "c");
newName = newName.replace(/ı/gi, "i");
newName = newName.replace(/ř/gi, "r");
newName = newName.replace(/ă/gi, "a");
newName = newName.replace(/İ/gi, "i");
newName = newName.replace(/č/gi, "c");
newName = newName.replace(/ş/gi, "s");
newName = newName.replace(/ć/gi, "c");
newName = newName.replace(/ı/gi, "i");
newName = newName.replace(/[^\x00-\x7F]/g, "-");
newName = newName.replace(/[!(\[)\]]/g, "-");
newName = newName.replace(/[,_{}|=~#%+]/g, "-");

if (name != newName) link.setPackageName(newName);
}
}

and it is:

if (state = "AFTER") {
var name = link.getName();
var newName = name;
var map = {};

if (name) {
map. = "a";
map. = "a";
map. = "e";
map. = "i";
map. = "o";
map. = "u";
map. = "a";
map. = "e";
map. = "i";
map. = "o";
map. = "u";
map. = "ae";
map. = "oe";
map. = "oe";
map. = "ue";
map. = "e";
map. = "i";
map. = "a";
map. = "n";
map. = "c";
map. = "o";
map. = "u";
map. = "o";
map. = "e";
map. = "o";
map. = "o";
map. = "y";
map.$ = "s";
map. = "a";
map. = "i";
map. = "a";
map. = "u";
map. = "ss";
map. = "ae";
map.ł = "l";
map. = "d";
map. = "s";
map.č = "c";
map.ş = "s";
map.ć = "c";
map.ı = "i";
map.ř = "r";
map.č = "c";
map.ă = "a";
map.â = "a";

for (x in map) {
newName = newName.replace(x, map[x]);
}

if (name != newName) link.setName(newName);
}
}


but there are still some special characters for package names !?

example links

**External links are only visible to Support Staff****External links are only visible to Support Staff**
**External links are only visible to Support Staff****External links are only visible to Support Staff**

please tell me, what I am doing wrong!?
Reply With Quote
  #2  
Old 03.10.2022, 10:48
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 78,420
Default

@verheiratet1952:
1.) why replace those chars in first place? your OS should not have problem with unicode chars
2.) a simple test with alert will show you that your way to replace the chars doesn't work
see mathiasbynens.be/notes/javascript-unicode

Easiest way to have the correct unicode character is to copy/paste the chars from the original string, then you would have seen that
Code:
 map.á= "1";
works fine because it's a different unicode character that you have in your script. script working fine with correct map
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 03.10.2022 at 10:54.
Reply With Quote
  #3  
Old 03.10.2022, 15:07
verheiratet1952 verheiratet1952 is offline
Black Hole
 
Join Date: Jan 2016
Posts: 285
Default

Quote:
Originally Posted by Jiaz View Post
@verheiratet1952:
1.) why replace those chars in first place? your OS should not have problem with unicode chars
2.) a simple test with alert will show you that your way to replace the chars doesn't work
see mathiasbynens.be/notes/javascript-unicode

Easiest way to have the correct unicode character is to copy/paste the chars from the original string, then you would have seen that
Code:
 map.á= "1";
works fine because it's a different unicode character that you have in your script. script working fine with correct map

I just dont want any special characters for packagenames that are created for downloading...

what do you mean with 'works fine' ... it works, but not for all special characters... sometimes same special character is renamed, sometimes not...

the eventscripter code was send from MGPAI 1 or 2 years ago thru chat (https://jdownloader.org/knowledge/chat)
Reply With Quote
  #4  
Old 03.10.2022, 15:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 78,420
Default

Quote:
Originally Posted by verheiratet1952 View Post
I just dont want any special characters for packagenames that are created for downloading...
Thanks for the feedback and explanation
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 03.10.2022, 15:47
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 78,420
Default

Quote:
Originally Posted by verheiratet1952 View Post
what do you mean with 'works fine' ... it works, but not for all special characters... sometimes same special character is renamed, sometimes not...
It works fine for me after manually adding the unicode character to the replacement map. see my previous response
Quote:
Originally Posted by Jiaz View Post
Easiest way to have the correct unicode character is to copy/paste the chars from the original string, then you would have seen that
Code:
 map.á= "1";
works fine because it's a different unicode character that you have in your script. script working fine with correct map
though the character looks identical, they are different, you can see for example by checking their UTF-8 encoding
mot hereff.in/utf-8 (remove spaces to open this link)
Code:
 á results in \x61\xCC\x81
while
Code:
  results in \xC3\xA1
if your script does not work, then your map does not contain replacement mapping for it. you will have to add it manually and update the script
__________________
JD-Dev & Server-Admin

Last edited by pspzockerscene; 04.10.2022 at 15:24. Reason: Made "mothereff.in/utf-8" link visible to user
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 01:45.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.