JDownloader Community - Appwork GmbH
 

Notices

Reply
 
Thread Tools Display Modes
  #1781  
Old 19.07.2021, 20:15
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by Jiaz View Post
containerURL might be undefined/null, you should add some checks for it
Of course. The example was just to demonstrate how to extract the hostname from url.

Quote:
Originally Posted by Jiaz View Post
@mgpai: I think your duplicate scripts would be great template for this, don't you think?
Guess so.

@BJN01: Related thread
Reply With Quote
  #1782  
Old 19.07.2021, 22:48
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

thank you guys !!! I found some interesting things that I will try to adapt to my approach / starting idea.
Reply With Quote
  #1783  
Old 21.07.2021, 13:40
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

I tried to follow the scripts of the discussion linked above, but I do something wrong:

1)

--- Trigger required: A new link has been added -------------
test purpose = find the name of the site / host (x use it + forward).

wrong code
Code:
var link = crawledLink;
if (link.availableState == "ONLINE") {
var url = link.contentURL || link.pluginURL;
 var StartLink = link.getContainerURL();
 var Hostname = StartLink.match(/:\/\/([^/]+)/)[1];   // for Host name
     alert (Hostname);
}
error : <Cannot cal method "match" of null>

2) --- Trigger required: Linkgrabber Contextmenu button pressed ------------
test purpose = find the name of the site / host of the link Selected in LinkGRabber windows (x use it + forward).

wrong code
Code:
if (name == "Aggiungi Host Monitoring") {    
    
    getAllCrawledLinks().forEach(function(fileNameHost) {
        var links = lgSelection.getLinks()//getDownloadLinks();
    var urls = [];

    for (i = 0; i < links.length; i++) {
        var link = links[i];
                var downloadURL = link.getContentURL();
               var HostName = downloadURL.match(/:\/\/([^/]+)/)[1];
                alert(HostName);
       }}  )}
error = I selec 1 (one) link for test the script , and i get a "thousand" windows alerts...


what did I do wrong?
[I guess that I was wrong in indicating how to locate the links, but after many attempts I could not figure it out ]



3) with the command like :

<< writeFile(SaveLinkFile, daaata.join("\r\n") + "\r\n", true); >>

you add a "date" to the txt, but is there a way to delete that "date" (if it exists) from the txt?

ex :
txt -->
Quote:
A00
A01
A02
A03
...
AXX
var date0 = "A02"

read txt
If date0 find --> delete it from txt
else date0 notfind --> Do nothing.

opening the txt manually and editing it is + easy but I was wondering if there is a scripted way?
Reply With Quote
  #1784  
Old 21.07.2021, 14:17
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,341
Default

@BJN01:

Quote:
Originally Posted by BJN01 View Post
var StartLink = link.getContainerURL();
var Hostname = StartLink.match(/:\/\/([^/]+)/)[1]; // for Host name
error : <Cannot cal method "match" of null>
link.getContainerURL may return null, you have to check for it



You can use existing methods for this
link.getHost(), returns host name of the plugin
link.getDownloadHost(), returns actual host name of the internal download url
__________________
JD-Dev & Server-Admin
Reply With Quote
  #1785  
Old 21.07.2021, 14:45
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
error : <Cannot cal method "match" of null>
Add error handling for links which do not have container url.

Code:
var link = crawledLink;

if (link.availableState == "ONLINE") {
    var StartLink = link.getContainerURL();
    
    try {
        var Hostname = StartLink.match(/:\/\/([^/]+)/)[1]; // for Host name
        alert(Hostname);
    } catch (e) {};
}

Quote:
Originally Posted by BJN01 View Post
error = I selec 1 (one) link for test the script , and i get a "thousand" windows alerts...
Use only lgSelection links. Also, the alert should be placed outside the loop. Store/append the hostnames in a variable and use alert at the end to display them.

Code:
if (name == "Aggiungi Host Monitoring") {
    var HostNames = [];

    lgSelection.getLinks().forEach(function(link) {
        try {
            var HostName = link.contentURL.match(/:\/\/([^/]+)/)[1];
            HostNames.push(HostName);
        } catch (e) {};
    })

    alert(HostNames.join("\n"));
}

Quote:
Originally Posted by BJN01 View Post
.. opening the txt manually and editing it is + easy but I was wondering if there is a scripted way?
Code:
var file = getPath("path/to/file");
var text = readFile(file, true);
var update = false;
var str = "A02";

if (text.indexOf(str + "\r\n") > -1) {
    text.replace(str + "\r\n", "");
    update = true;
}

if (update) {
    file.delete();
    writeFile(file, text, true);
}

Quote:
Originally Posted by Jiaz View Post
@BJN01:
You can use existing methods for this
link.getHost(), returns host name of the plugin
link.getDownloadHost(), returns actual host name of the internal download url
Example in post #1777 was to get host name from container url.
Reply With Quote
  #1786  
Old 24.07.2021, 15:54
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

on some sites I find files with names like this:
Quote:
13-ba2646388a7dd350a8f252f79664f87f979bbe8182cc1576742f68af3cf307be.png

2-3578f8d84a541f5e536f56fefa2b6a0b4cd67d5ffe1e3322301e2f4c128a0aef.png

302-f8fc9e3f3fd7828767e87c55b0453e31d1780203e4d61041671acd00a6066144.jpg
I would like to make them things like:

13.png
02.png
302.jpg

but to use the < ..... replace ("old", "new") ..... >
I can't find a valid regex to use [ especially to eliminate the part between "-" and the file extension ] ,
how should the regex be?
Reply With Quote
  #1787  
Old 24.07.2021, 16:10
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
I can't find a valid regex to use [ especially to eliminate the part between "-" and the file extension ] , how should the regex be?
Code:
^(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$
Reply With Quote
  #1788  
Old 24.07.2021, 16:32
radix radix is offline
JD Alpha
 
Join Date: Apr 2009
Posts: 21
Default

Quote:
Originally Posted by Taobaibai View Post
To extract archives only after all downloads have finished, use this new script:
Code:
github.com/mgpai/resources/blob/master/jdownloader/eventscripter/scripts/Taobaibai_2.js


Thank you, that was what I was looking for!!!!
bei mir tut es nichts.
ich habe beim "archiventpacker" plugin den haken bei "Archive nach dem Download entpacken" entfernt. Und Trigger ist "Pakt fertiggestellt"

muss ich noch etwas ein- und/oder ausschalten?
Reply With Quote
  #1789  
Old 24.07.2021, 16:57
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by radix View Post
bei mir tut es nichts.
ich habe beim "archiventpacker" plugin den haken bei "Archive nach dem Download entpacken" entfernt. Und Trigger ist "Pakt fertiggestellt"

muss ich noch etwas ein- und/oder ausschalten?
It seems to be working fine. Please note, completed archives will be extracted only if all packages in the download list are finished.
Reply With Quote
  #1790  
Old 24.07.2021, 17:36
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

Quote:
Originally Posted by mgpai View Post
Code:
^(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$
sorry, but it doesn't work.
(I also checked through F2 on various files and inserting the string, but it does nothing [in the preview the name remains the same] )
Reply With Quote
  #1791  
Old 24.07.2021, 17:45
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
sorry, but it doesn't work.
(I also checked through F2 on various files and inserting the string, but it does nothing [in the preview the name remains the same] )
Works fine. Please post your script OR screenshot of your rename dialog.
Reply With Quote
  #1792  
Old 24.07.2021, 18:08
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

Quote:
Originally Posted by mgpai View Post
Works fine. Please post your script OR screenshot of your rename dialog.
screenshot of rename dialog here --> ht#ps://i.postimg.cc/D0sBCVxW/F2-And-Preview.jpg
[ maybe I was wrong to copy the string between one first and another, this time it does something (but does everything change?) ]


x the script
I did a test, and if I write the piece I want to remove in the script it works, that is:

ex file :
2-3578f8d84a541f5e536f56fefa2b6a0b4cd67d5ffe1e3322301e2f4c128a0aef.png

+ script with:

blabla ... replace ("-3578f8d84a541f5e536f56fefa2b6a0b4cd67d5ffe1e3322301e2f4c128a0aef",""); .....


the file it becomes ---> 2.png [ok]

Last edited by BJN01; 24.07.2021 at 18:12.
Reply With Quote
  #1793  
Old 24.07.2021, 18:16
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
("-3578f8d84a541f5e536f56fefa2b6a0b4cd67d5ffe1e3322301e2f4c128a0aef",""); .....
the file it becomes ---> 2.png [ok]
OK. But, how are you using the regex pattern? You need to use the correct capture groups to replace.

Code:
regex101.com/r/qbj3rm/1
Reply With Quote
  #1794  
Old 24.07.2021, 19:33
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

ok , with the F2 I did not put "$1$3" ... so , i'm an idi#t ...

but , the script doesn't want to do its job ... am I doing something wrong then?


Code:
//trigger = a new link has been added  

var link = crawledLink;
if (link.availableState == "ONLINE") {
    var StartLink = link.getContainerURL();
    
    try {
        var Hostname = StartLink.match(/:\/\/([^/]+)/)[1]; // for Host name
        //alert(Hostname);
    } catch (e) {};
    
     if (Hostname == "#Site#" ) {            
          getAllCrawledLinks().forEach(function(i) {
        var replace = function(a, b) {
            i.name = i.name.split(a).join(b);
        }
   
 replace("^(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$" , "$1$3"); // not work , do nothing , the file name dont change
 replace("-07145d3f75219e8fa82c4d2335addb98f2ec54d1de7478a3edea333ce5a22ac8",""); // ok , do is job 
    })
    }
}

Last edited by BJN01; 24.07.2021 at 19:35.
Reply With Quote
  #1795  
Old 24.07.2021, 19:44
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
but , the script doesn't want to do its job ... am I doing something wrong then?
Split/join can be used when find/replace parameters are both strings. Since you are using regex here, you will need to use it as find parameter and, str (static) or capture groups as replace parameter.

Code:
var replace = function(a, b) {
    i.name = i.name.replace(a, b);
}

replace(/(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$/, "$1$3");
Reply With Quote
  #1796  
Old 24.07.2021, 19:56
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

Quote:
replace(/(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$/, "$1$3");
now the files become something like this:

$1$32$1$3-31171572ee3982a2fb88bafee6bea0df33a55af07f6b95d442752a3dbb22147e$1$3.png$1$3

??? why ??
Reply With Quote
  #1797  
Old 24.07.2021, 20:12
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
now the files become something like this: ...
??? why ??
Should be working fine:
Code:
var i = {
    name: "3-31171572ee3982a2fb88bafee6bea0df33a55af07f6b95d442752a3dbb22147e.png"
}

var replace = function(a, b) {
    i.name = i.name.replace(a, b);
}

replace(/(\d+)(-[a-z0-9]{64})(\.(?:jpg|png))$/, "$1$3");

alert(i.name);

Find me in JD chat if you want me to take a look at your script.
Code:
kiwiirc.com/nextclient/irc.libera.chat/#jdownloader
Reply With Quote
  #1798  
Old 03.08.2021, 16:52
BJN01 BJN01 is offline
JD Adviser
 
Join Date: Jan 2020
Posts: 113
Default

hello ,

starting from the script I use to rename files and packages, I am creating one in which I change the name of the package and / or files only if they come from a given host / starting link.

that is, if the initial link is:
-from : vvvvv.siteAAA.A ---> change package name
-from : vvvvv.siteAAB.A ---> DO NOT change package name, leave it like this.

.... the problem is that I don't get any results.

trigger : hook packager
simplified version but not working

Code:
if (name = CuoPHv2 = "Cleanup packagenamesfromHost") {
    getAllCrawledPackages().forEach(function(i) {
        var replace = function(a, b) {
              link.name = link.name.replace(a, b);
             }
if (link.downloadHost == "SiteA.AAA"){// 
  replace ("[English]","[Eng]");// for test 
  replace (/(\[English])/,"[Eng]");// for test
  //... list of replace for that host.
}          

if (link.downloadHost == "SiteB.BBB"){// 
  replace ("ONE","[1]");// for test 
    //... list of replace for that host.
}          
// etc.


            }
//.....
 )
}
where am i wrong? what - how should I correct?

Last edited by BJN01; 03.08.2021 at 16:55.
Reply With Quote
  #1799  
Old 03.08.2021, 17:03
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by BJN01 View Post
where am i wrong? what - how should I correct?
Change:
Code:
function(i)
to:
Code:
function(link)
Reply With Quote
  #1800  
Old 03.08.2021, 17:20
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,341
Default

@BJN01: Just in case you are familiar with java coding language, you could also directly write extensions/code in java.
__________________
JD-Dev & Server-Admin
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 10:38.
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.