JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 02.10.2022, 22:02
verheiratet1952 verheiratet1952 is offline
JD VIP
 
Join Date: Jan 2016
Posts: 326
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, 09:48
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,554
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 09:54.
Reply With Quote
  #3  
Old 03.10.2022, 14:07
verheiratet1952 verheiratet1952 is offline
JD VIP
 
Join Date: Jan 2016
Posts: 326
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, 14:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,554
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, 14:47
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,554
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 14: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 04:25.
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 - 2024, Jelsoft Enterprises Ltd.