JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 03.07.2016, 10:44
ds1508's Avatar
ds1508 ds1508 is offline
DSL User
 
Join Date: Jul 2016
Location: Germany, NRW
Posts: 38
Question [Eventscripter] How to remove package from Downloadlist?

Hello.

ENG:
I'm trying to write a script that cleans up my downloadlist. When I click a button the script creates a batch file for every package, that calls my virus scanner, renames the folder and moves it to my network file server.
My problem is, when this is done I want the eventscripter to remove the package from the download list. But I can't find the command to do this.
Any1 able to help me out, please?

DEU:
Ich möchte einen Script, der meine Downloadlist aufräumt. Wenn ich den Knopf drücke erstellt der Script eine Batch Datei für jedes Paket die dann meinen Virusscanner startet, den Ordner umbenennt, und auf meinen Netzwerk Fileserver verschiebt.
Mein Problem ist, wenn das durch ist soll der Script das Paket von der Downloadlist entfernen. Ich hab nur keine Ahnung wie der Befehl lautet.
Kann mit da jmd. helfen?

Thx!
Reply With Quote
  #2  
Old 04.07.2016, 10:21
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

Why not use the eventscripter that calls your antivirus and waits for the scan to return and then rename/delete the package. Why not delete the package after the batch is created and started?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 04.07.2016, 18:39
ds1508's Avatar
ds1508 ds1508 is offline
DSL User
 
Join Date: Jul 2016
Location: Germany, NRW
Posts: 38
Default

I wanted it to use my existing batches.
And at least it's still the problem: How to remove/delete the package????? What is the js command????
Reply With Quote
  #4  
Old 04.07.2016, 22:00
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

The eventscripter is using Javascript as language/syntax. The window will provide all available methods. I will add script methods to remove package/link tomorrow morning
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 05.07.2016, 11:17
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

with next core update you can use
FilePackage.remove
DownloadLink.remove
or
removeDownloadLinkByUUID and removeFilePackageByUUID
__________________
JD-Dev & Server-Admin
Reply With Quote
  #6  
Old 05.07.2016, 11:26
ds1508's Avatar
ds1508 ds1508 is offline
DSL User
 
Join Date: Jul 2016
Location: Germany, NRW
Posts: 38
Default

THX ALOT!
Good job!
Reply With Quote
  #7  
Old 05.07.2016, 11:37
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

Sorry that I did not understand your request at first
__________________
JD-Dev & Server-Admin
Reply With Quote
  #8  
Old 05.07.2016, 14:13
ds1508's Avatar
ds1508 ds1508 is offline
DSL User
 
Join Date: Jul 2016
Location: Germany, NRW
Posts: 38
Thumbs up

Here's my fist try with it. This will remove only those packages that have finished downloading AND extracting.

Code:
////////////////////////////////////////////////////////////////////////////////
// CleanupDownloads
////////////////////////////////////////////////////////////////////////////////

require("C:\\Users\\Admin\\Documents\\Visual Studio 2015\\Projects\\JDownloader-EventScripter\\!My_JS-Functions.js");

////////////////////////////////////////////////////////////////////////////////

var showAlertInfo = true;

var dt = new Date();
var datumZeit = dt.toUTCString();
var t = "";
var pKeep = pRemoved = pError = 0;

if (this.name == "[CleanupDownloads]") {
	var myPackages = callAPI("downloadsV2", "queryPackages", { "name": true });
	if (myPackages.length > 0) {
		for (var i = 0; i < myPackages.length; i++) {
			var myFilePackage = getDownloadPackageByUUID(myPackages[i].uuid);
			var myDownloadLinks = myFilePackage.getDownloadLinks();
			var isExtracted = true;
			for (var o = 0; o < myDownloadLinks.length; o++) {
				if (myDownloadLinks[o].getArchive() != null && myDownloadLinks[o].getExtractionStatus() != "SUCCESSFUL") {
					isExtracted = false;
					break;
				}
			}
			t += (i + 1) + "="" + myPackages[i].name + "" (" + myFilePackage.isFinished() + "/" + isExtracted + ")";
			if (myFilePackage.isFinished() && isExtracted) {
				t += " DONE->";
				if (myFilePackage.remove()) {
					pRemoved++;
					t += "Removed\r\n";
				} else {
					pError++;
					t += "RemoveError\r\n";
				}
			} else {
				t += " Keep\r\n";
				pKeep++;
			}
		}
		t += "\r\nRemoved: " + pRemoved + "     RemoveErrors: " + pError + "     Kept: " + pKeep;
		if (showAlertInfo) alert("Cleanup Downloads   (isDownloaded/isExtracted)\r\n" + datumZeit + "\r\n\r\n" + t);
	} else {
		if (showAlertInfo) alert("Cleanup Downloads\r\n" + datumZeit + "\r\n\r\nNo Packages in Downloadlist!");
	}
}
Reply With Quote
  #9  
Old 05.07.2016, 14:22
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

Thanks for the script! is the require needed? What does My_JS-Functions.js provide?
Btw, you can also use getAllFilePackages() instead of callAPI
__________________
JD-Dev & Server-Admin
Reply With Quote
  #10  
Old 05.07.2016, 15:38
ds1508's Avatar
ds1508 ds1508 is offline
DSL User
 
Join Date: Jul 2016
Location: Germany, NRW
Posts: 38
Arrow

Well the require contains some functions I often use in my scripts:
Spoiler:
Code:
/**************************************************************************************************
	Number.prototype.format(n, x)
		Format a number with . and ,: 1,123.45
	@param integer n: length of decimal
	@param integer x: length of sections
**************************************************************************************************/
Number.prototype.format = function ( n, x ) {
	var re = '\\d(?=(\\d{' + ( x || 3 ) + '})+' + ( n > 0 ? '\\.' : '$' ) + ')';
	return this.toFixed( Math.max( 0, ~~n ) ).replace( new RegExp( re, 'g' ), '$&,' );
};
/**************************************************************************************************
	Number.prototype.byteFormat(n, x, t)
		Convert Bytes to KB/MB/GB/TB and format with . and ,: 1,123.45
	@param integer n: length of decimal
	@param integer x: length of sections
	@param string  t: [kb|mb|gb|tb] to convert numer to
**************************************************************************************************/
Number.prototype.byteFormat = function ( n, x, t ) {
	var v = this;
	switch ( t.toLowerCase() ) {
		case "kb":
			v = v / 1024;
			break;
		case "mb":
			v = v / 1024 / 1024;
			break;
		case "gb":
			v = v / 1024 / 1024 / 1024;
			break;
		case "tb":
			v = v / 1024 / 1024 / 1024 / 1024;
			break;
		default:
	}
	return v.format( n, x );
}
/**************************************************************************************************
	String.prototype.FillStr(rightLeft, fillWith, length, rightStr)
		Fill a string.
	@param string rightLeft: string: "l"=left | "r"=right
	@param string  fillWith: string to use to fill
	@param integer length  : Final string length
	@param string  rightStr: right string
**************************************************************************************************/
String.prototype.FillStr = function ( rightLeft, fillWith, length, rightStr ) {
	var str = this;
	if ( rightStr == null ) rightStr = "";
	while ( str.length < ( length - rightStr.length ) )
		if ( rightLeft.toLowerCase() == "l" )
			str = fillWith + str;
		else
			str = str + fillWith;

	return str + rightStr;
}
/**************************************************************************************************
	String.prototype.CenterStr(length, fillWith)
		Center a string.
	@param integer length  : Final string length
	@param string  fillWith: string to use to fill
**************************************************************************************************/
String.prototype.CenterStr = function ( length, fillWith ) {
	var str = this;
	while ( str.length < length ) {
		str = fillWith + str;
		if ( str.length < length )
			str += fillWith;
	}
	return str;
}


And thanks for the info, will try getAllFilePackages() next time.

If some1 wants to use my scripts, feel free to copy them.
Reply With Quote
  #11  
Old 05.07.2016, 15:57
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

Thanks for the feedback
__________________
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 09:32.
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 - 2020, Jelsoft Enterprises Ltd.