JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1121  
Old 28.02.2020, 12:24
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
a) Is there a function to get filename or link on selected file in Downloads/LinkGrabber tab
Use context menu button triggers and their respective (dlSelection/lgSelection) methods

Quote:
b) and function that return all subfolders and a function return files in dir
Use 'filePath' methods.

Quote:
Originally Posted by zreenmkr View Post
Is it possible to check file exist via regex?
You can use the regex to only match file name string. To check if file exists, you have to use 'flilePath.exists()' method.

Get the contents of the folder using 'filePath.getChildren()' method and filter them using your pattern. This will eliminate the need for file exists check, since it will return only the contents which exist on the disk.
Reply With Quote
  #1122  
Old 28.02.2020, 12:44
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

thanks master!

Is there a way to move selected file or package from Downloads back to LinkGrabber?

Also would like to move finished files from the selected package to (original packageName + 'DONE')
Reply With Quote
  #1123  
Old 28.02.2020, 13:06
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Code:
//@mgpai
//Packagizer Alt Filters
// Trigger: Packagizer Hook

var fn = link.getName();
var pn;

if (!pn && /birds|elephant/.test(fn)) pn = "animals";
if (!pn && /bmw|honda|tesla/.test(fn)) pn = "cars";
if (!pn && /.*\.(pdf|epub|mobi)$/.test(fn)) pn = "ebooks";

if (pn) link.setPackageName(pn);

When you brought up there is a possibility to exit out once a matched found. I thought a script that catches Packagizer rules return true then exit out.

So, what is really happening behind the scene? Are all normal rules in Packagizer get executed first then finish up with this script? I'm not complaining, just trying to understand (:
Reply With Quote
  #1124  
Old 28.02.2020, 13:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
Is there a way to move selected file or package from Downloads back to LinkGrabber?
Cannot move as such. You can use a script to add them again to linkgrabber (will trigger crawling/linkchecking etc, just like when new links are added) and then delete them from download list using the same script. Can also break mirror detection and extraction, so you have to check the status of links before moving them.

Quote:
Also would like to move finished files from the selected package to (original packageName + 'DONE')
While possible, moving can break mirror detection, extraction etc. Also, mirrors which are marked as 'finished' do not trigger "download stopped" event, and hence will have to be moved manually.

It is better to rename the package after it is finished. Just use the rename method and append your custom string to it.

Quote:
Are all normal rules in Packagizer get executed first then finish up with this script?
Packagizer hook has a 'state' property, which will allow it run before or after packagizer rules are applied.

Code:
if(state == "BEFORE"){
    //run this code before packagizer rules are applied
}

if(state = "AFTER"){
    //run this code before packagizer rules are applied
}

Without the condition, the script will be executed twice. Once before packagizer rules are applied and once more after that.

While the script can do a lot of things which the packagizer extension cannot, I use both. For simple tasks I use the extension and for features missing from the extension, I use a script.
Reply With Quote
  #1125  
Old 28.02.2020, 17:00
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

thanks again for the insight.

do you have the reference of all the jd functions glossary or is it documented? I looked up on wiki but couldn't find it.
Reply With Quote
  #1126  
Old 28.02.2020, 17:24
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
do you have the reference of all the jd functions glossary or is it documented? I looked up on wiki but couldn't find it.
Click 'Show/Hide Help' in the script editor window main menu to list all the available methods. In some cases some context specific methods will be listed only after you have set/selected the event trigger for the script.
Reply With Quote
  #1127  
Old 28.02.2020, 23:27
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Talking

just learned I do have a blind spot!
Reply With Quote
  #1128  
Old 29.02.2020, 06:31
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
(dlSelection/lgSelection) methods
Can't get name of the Select File in LinkGrabber.

Code:
var getDlSel = lgSelection.getDownloadLink.getName();
alert(getDlSel);

//return error: ReferenceError: 'lgSelection' is not defined
Reply With Quote
  #1129  
Old 29.02.2020, 06:52
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
Can't get name of the Select File in LinkGrabber
Code:
// Linkgrabber context menu button pressed demo

if (name == "LG context menu demo") {
    var myLinkgrabberSelection = lgSelection;
    var myCrawledLink = myLinkgrabberSelection.getContextLink();

    if (myCrawledLink) alert(myCrawledLink.getName());
}
Reply With Quote
  #1130  
Old 29.02.2020, 07:27
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Code:
var myCrawledLink = myLinkgrabberSelection.getContextLink();
cool, how to send myCrawledLink.getName() to clipboard?

tried w/o luck: myCrawledLink.getName().execCommand("copy")

ref: hxxps://www.w3schools.com/howto/howto_js_copy_clipboard.asp
Reply With Quote
  #1131  
Old 29.02.2020, 07:41
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
how to send myCrawledLink.getName() to clipboard?

tried w/o luck: myCrawledLink.getName().execCommand("copy")
The 'execCommand' is a browser environment method. There are no eventscripter enviroment methods which can be used to copy content to the clipboard.

You can customize your context menu and add/configure "Copy Information" item and format the variables which you want to be copied to the clipboard when you click it.
Reply With Quote
  #1132  
Old 29.02.2020, 07:52
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

oh ok, that's too bad.

as far as debugging goes. alert() is the only other method other than writeFile()
Reply With Quote
  #1133  
Old 29.02.2020, 08:12
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
as far as debugging goes. alert() is the only other method other than writeFile()
You can also use the 'log' method. Unlike 'writeFile' you do not have to specify the output file. It will be logged to the default file in 'JD\logs' folder.
Code:
log(myObject[]);/*Log to stderr and to JDownloader Log Files*/

In lieu of console in eventscripter, you can load the log file or your custom file in notepad++ and enable its auto-update/scroll to end on update feature.
Reply With Quote
  #1134  
Old 29.02.2020, 15:14
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

thanks.

Why 'i' is global var in this scenario? Shouldn't 'i' is local in _getLists()? notice 'i' got overwrites each time it returns from func being called.

Code:
//init
var pkgs = getAllFilePackages();
var count = 0;
for (i = 0; i < pkgs.length; i++) {
      var pkg = pkgs[i];
      _getLists(pkg);
      count +=1;
      if (count > 5) break;
}
 alert('pkg count:'+i+'/'+pkgs.length); //THIS i increment got reassigned to the i in _getLists()

//function
function _getLists(pkg) {
   var lists = pkg.getDownloadLinks();
   var kount = 0;
   for (i = 0; i < lists.length; i++) {
      var list = lists[i];
      kount +=1;
      if (kount > 2) break;
   }
      alert('list count:'+i+'/'+lists.length);
}

Last edited by zreenmkr; 29.02.2020 at 21:46.
Reply With Quote
  #1135  
Old 01.03.2020, 06:01
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
Why 'i' is global var in this scenario? Shouldn't 'i' is local in _getLists()? notice 'i' got overwrites each time it returns from func being called.
Assigning a value to a variable which has not been declared will automatically make it 'global'. (Use "var i = 0" instead of "i = 0").

Nested functions have access to 'local' variables declared in their outer scope. So, in nested functions, it is better to use variable names which have not already been used in the outer scope.
Reply With Quote
  #1136  
Old 01.03.2020, 10:04
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Assigning a value to a variable which has not been declared will automatically make it 'global'
That explained it. The only other thing i did try was declaring var in outer scope ONLY which also failed.
Reply With Quote
  #1137  
Old 01.03.2020, 10:07
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Is it a good common practice to use non-constant global var between functions instead of passing it?
Reply With Quote
  #1138  
Old 02.03.2020, 04:08
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Click 'Show/Hide Help' in the script editor window main menu to list all the available methods. In some cases some context specific methods will be listed only after you have set/selected the event trigger for the script.
I'm unable to find reference in help for dlSelection/lgSelection nor getContextLink() mentioned. name, link, package and among other are also documented.
Reply With Quote
  #1139  
Old 02.03.2020, 05:21
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
I'm unable to find reference in help for dlSelection/lgSelection nor getContextLink() mentioned
Once you select a trigger, properties returned by that trigger will be listed at the bottom of the page and their corresponding methods will be listed separately further up on the same page.
Reply With Quote
  #1140  
Old 02.03.2020, 05:54
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

got it.


Code:
// Get Selected packageName
// Trigger : "DownloadList Contextmenu Button Pressed"

if (name == "Get Selected packageName") {
    try {
        var selected = dlSelection.getContextLink();
        var package = selected.getPackage();

        if (selected) alert(selectedPackage + ': ' + package );

    } catch (e) {
        alert('error: Right-Click on <fileName> & try again.');
    }
}

Only able to get package name by right click on file name but can't seem to find a function that get package name on selected package.
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 09:47.
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 - 2023, Jelsoft Enterprises Ltd.