JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #2921  
Old 26.04.2024, 13:19
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by StefanM View Post
... script which marks all occurrences of duplicates.
Code:
/*
    disable dupes
    trigger : toolbar button pressed
*/

if (name == "disable dupes") {
    var original = [];

    getAllCrawledLinks().forEach(function(link) {
        var url = link.contentURL;
        
        if(url){
            if(original.indexOf(url) == -1){
                original.push(url);
                //link.comment = "original";
            } else {
                link.enabled = false;
                //link.comment = "dupe"
            }
        }
    })
}

Script also has an option to set comment which is disabled by default. If enabled, the comment on first link will be set as 'orginal' and subsequent links will be set to "dupes". This will be useful for creating view filters.
Reply With Quote
  #2922  
Old 26.04.2024, 17:54
StefanM's Avatar
StefanM StefanM is offline
JD Legend
 
Join Date: Oct 2020
Posts: 536
Default

Quote:
Originally Posted by mgpai View Post
Code:
/*
    disable dupes
    trigger : toolbar button pressed
*/

if (name == "disable dupes") {
    var original = [];
...
Script also has an option to set comment which is disabled by default. If enabled, the comment on first link will be set as 'orginal' and subsequent links will be set to "dupes". This will be useful for creating view filters.
First of all: Thank you very much.

EDIT
Problem: When I enable the Scripter-button in the toolbar, another script gets started. That way I can only enable or disable all my scripts.

Finally got it working, disabling dupes that is.
But I had to change the trigger to LinkGrabber Context Menu Button pressed.

With 25,000 links in LinkGrabber, it takes about 12 seconds until the dupes are disabled. But that's ok.


But I still don't know how to enable the comments, 'original' and 'dupes'.
Can you please explain how I can enable comments?




Thanks again and best regards,
Stefan

Last edited by StefanM; 26.04.2024 at 20:38.
Reply With Quote
  #2923  
Old 27.04.2024, 09:54
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by StefanM View Post
A toolbar button is more suitable since the objects used in the script are global. The name in the toolbar button should match the name used in the script. Change the toolbar button name from the default name to "disable dupes" (without quotes).

Since the script will overwite any custom comments set by the user, it is disabled by default (commented out). Uncomment the relevant code. For e.g, change:
Code:
//link.comment = "original";
to
Code:
link.comment = "original";
Reply With Quote
  #2924  
Old 27.04.2024, 11:04
StefanM's Avatar
StefanM StefanM is offline
JD Legend
 
Join Date: Oct 2020
Posts: 536
Default

Quote:
Originally Posted by mgpai View Post
A toolbar button is more suitable since the objects used in the script are global. The name in the toolbar button should match the name used in the script. Change the toolbar button name from the default name to "disable dupes" (without quotes).
Tried exactly this, but it only worked in the context menus. Tried it again today, and now it works. Could have been one of those updates, which were released several times yesterday (about every 30 minutes).


Quote:
Originally Posted by mgpai View Post
Since the script will overwite any custom comments set by the user, it is disabled by default (commented out). Uncomment the relevant code. For e.g, change:
Code:
//link.comment = "original";
to
Code:
link.comment = "original";
Should have noticed that, as well as the green color - stupid me!

Again, thank you so much for that macro! Whish I would be able to write such macros myself...
Reply With Quote
  #2925  
Old 27.04.2024, 12:33
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,056
Default

Quote:
Originally Posted by StefanM View Post
Could have been one of those updates, which were released several times yesterday (about every 30 minutes).
No changes from those updates only plugin updates
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2926  
Old 03.05.2024, 19:42
SacredDB SacredDB is offline
Junior Loader
 
Join Date: Oct 2013
Posts: 10
Question Delete empty folder (after files have been moved)?

Hello everyone,

I have written a script which moves downloaded files (which are not an archive) to another directory (the package name remains the same). The script also works. But after moving, the (now) empty folder remains in the original download directory.

That's the script:

Code:
/*
    Move finished non archive files
    Trigger: Download has stopped
*/    
if (link.finished && !link.archive) {
    var downloadFolder = link.package.downloadFolder;
    var newFolder = downloadFolder.split("C:\\Users\\Tom\\Downloads\\JD 2\\").join("C:\\Users\\Tom\\Downloads\\JD 2\\F\\"); // Modify path

    if (newFolder != downloadFolder) {
        getPath(link.downloadPath).moveTo(newFolder);
    }
}
I have tried to write a second script which then deletes the empty folder, but unfortunately not successfully, the script does not work.
Maybe it is possible to combine both functions in one script, but unfortunately I am at a loss here.
Can someone help me?

That's my attempt (not working):
Code:
/*
    Delete empty folder after files have been moved
    Trigger: Download has stopped
*/    
if (link.finished) {
    var downloadFolder = getPath(link.downloadPath); // 
    if (downloadFolder.exists() && downloadFolder.getChildren().length == 0) {
        downloadFolder.delete();
    }
}
Reply With Quote
  #2927  
Old 04.05.2024, 13:08
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,056
Default

@SacredDB: link.downloadpath is the path to the file, not the folder, you need get the parent(folder) of the file like following
Quote:
var downloadFile= getPath(link.downloadPath);
var downloadFolder=downloadFile.getParent();
....
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2928  
Old 05.05.2024, 19:13
SacredDB SacredDB is offline
Junior Loader
 
Join Date: Oct 2013
Posts: 10
Default

Quote:
Originally Posted by Jiaz View Post
@SacredDB: link.downloadpath is the path to the file, not the folder, you need get the parent(folder) of the file like following
Okay, I've missed that.
Got it, now it's working.

Thank you Jiaz!
Reply With Quote
  #2929  
Old 05.05.2024, 21:47
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,056
Default

@SacredDB: you're welcome and thanks for the feedback. maybe wanna share your final scripts and short descriptions, in case other want to achieve similiar thing
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2930  
Old 27.05.2024, 13:38
VanTuz VanTuz is offline
Giga Loader
 
Join Date: Oct 2018
Posts: 95
Default

I don't understand java script programming at all, but I need a script that would put all the files from one post from kemono.su in one folder, no matter what file sharing site they are on. Please help me if it's not difficult.
Reply With Quote
  #2931  
Old 27.05.2024, 14:27
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 71,498
Default

Context for VanTuz post:
https://board.jdownloader.org/showth...577#post534577
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #2932  
Old 27.05.2024, 21:42
zinillus zinillus is offline
Junior Loader
 
Join Date: Aug 2019
Posts: 11
Default

Hi. I wanted help making a script that is able to take postContentIndex, which returns an index for the order in which an image appears on a page, but zero pads it so the number is always 3 digits. e.g. 001, 002, ..., 011, etc. Instead of the current 1, 2, ..., 11, etc.

More context in this post. Jiaz mentions he's available to clarify details.
https://board.jdownloader.org/showth...712#post534712
Reply With Quote
  #2933  
Old 28.05.2024, 17:59
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by VanTuz View Post
I don't understand java script programming at all, but I need a script that would put all the files from one post from kemono.su in one folder, no matter what file sharing site they are on. Please help me if it's not difficult.
You can create a packagizer rule:
Code:
if > source url contains : kemono.su/*/user/*/post/*
then set > download directory : <jd:source:1> <jd:source:2> <jd:source:3>
then set > package name : <jd:source:1> <jd:source:2> <jd:source:3>
Reply With Quote
  #2934  
Old 28.05.2024, 19:48
VanTuz VanTuz is offline
Giga Loader
 
Join Date: Oct 2018
Posts: 95
Default

Quote:
Originally Posted by mgpai View Post
You can create a packagizer rule:
Code:
if > source url contains : kemono.su/*/user/*/post/*
then set > download directory : <jd:source:1> <jd:source:2> <jd:source:3>
then set > package name : <jd:source:1> <jd:source:2> <jd:source:3>
It didn't work. Or I did something wrong.
Reply With Quote
  #2935  
Old 29.05.2024, 09:30
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 71,498
Default

@mgpai
Context is missing here - he also wants to put all non-kemono results which are added originally via kemono to be put in one package e.g. also all mega.nz links.
Reference:
https://board.jdownloader.org/showth...577#post534577
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #2936  
Old 29.05.2024, 12:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by pspzockerscene View Post
@mgpai
Context is missing here - he also wants to put all non-kemono results which are added originally via kemono to be put in one package e.g. also all mega.nz links.
It does. It generates a package name from url and puts all files in same package/download folder.

Reply With Quote
  #2937  
Old 30.05.2024, 11:17
VanTuz VanTuz is offline
Giga Loader
 
Join Date: Oct 2018
Posts: 95
Default

So I'm doing something wrong and I don't understand how it should be.
Reply With Quote
  #2938  
Old 30.05.2024, 11:40
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by VanTuz View Post
So I'm doing something wrong and I don't understand how it should be.
Rule is applied only when adding links to JD. If it is still not working, post a screenshot of your packagizer rule.
Reply With Quote
  #2939  
Old 30.05.2024, 12:56
VanTuz VanTuz is offline
Giga Loader
 
Join Date: Oct 2018
Posts: 95
Default

Reply With Quote
  #2940  
Old 30.05.2024, 15:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by VanTuz View Post
...
The packagizer rule works only post url. The test url you have used is profile url. It also did not return any mega links. Email example links to me which return mega links as well for testing.
Reply With Quote
  #2941  
Old 30.05.2024, 16:20
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by zinillus View Post
a script to take postContentIndex ... zero pads it so the number is always 3 digits
Code:
/*
    pad postContentIndex
    trigger : packagizer hook
*/    

if (linkcheckDone && state == "BEFORE") {
    var current = link.getProperty("postContentIndex");

    if (current != null) {
        var padded = ("000" + current).slice(-3);
        link.setProperty("postContentIndex", padded);
    }
}
Reply With Quote
  #2942  
Old 30.05.2024, 23:45
VanTuz VanTuz is offline
Giga Loader
 
Join Date: Oct 2018
Posts: 95
Default

I checked with a link to a specific post and it worked, but the fact is that I need the name of the post to be in the folder name. Of course, you can make sure that files from the post that are not on the file sharing site fall into a subfolder, but then if there are a lot of folders, then it will be difficult to sort the files by folders. And if there are a lot of pages with posts on the author's page, then even if you use third-party browser add-ons to copy several links at once, it will take a lot of time to copy all the links, and I would like to do something faster, if it is possible in principle.
Reply With Quote
  #2943  
Old 31.05.2024, 08:43
ypp ypp is offline
DSL Light User
 
Join Date: Jan 2019
Posts: 32
Default

is it possible to run an external (python?) script to resolve link? as many sites use cloudflare to block jd now
Reply With Quote
  #2944  
Old 31.05.2024, 09:31
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by ypp View Post
is it possible to run an external (python?) script to resolve link? as many sites use cloudflare to block jd now
You can use callSync and callAsync methods (check built-in help for details) to call external programs from eventscripter.
Reply With Quote
  #2945  
Old 31.05.2024, 12:25
ypp ypp is offline
DSL Light User
 
Join Date: Jan 2019
Posts: 32
Default

yes but you can't change downloadlinks, can only add to linkgrabber and then the packages and filenames will be messed up.
Reply With Quote
  #2946  
Old 31.05.2024, 16:57
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,567
Default

Quote:
Originally Posted by ypp View Post
yes but you can't change downloadlinks, can only add to linkgrabber and then the packages and filenames will be messed up.
Only directhttp links can be modified in GUI. Presently there are no eventscripter methods to do it. You can use addLinksQuery to insert new links in the same package preserving the file name, comment etc., depending on the output returned by your script. You can also use folderwatch MYJD API and add links directly from python script.
Reply With Quote
  #2947  
Old 02.06.2024, 00:42
FBD's Avatar
FBD FBD is offline
JD Fan
 
Join Date: Nov 2018
Location: https://web.libera.chat/#jDownloader
Posts: 70
Post Script: Stop downloads during extraction

As the old script in this thread to stop downloads during extraction is not working anymore (producing a deadlock) here's a new one i put together on a user request:

Code:
/* 
    Stop downloads during extraction
    Trigger Required: Any Extraction Event
*/

if (isDownloadControllerRunning() && event == "EXTRACTING") {
    // Extraction starting and download runnning
    stopDownloads();

} else if (!isDownloadControllerRunning() && event == "CLEANUP") {
    // Restart downloads
    startDownloads();
}
__________________
irc.libera.chat #jDownloader web.libera.chat/#jDownloader
Reply With Quote
  #2948  
Old 06.06.2024, 14:19
DamonDragon DamonDragon is offline
DSL User
 
Join Date: Aug 2016
Posts: 36
Default

I wanted to share my script, that will automatically add YouTube thumbnails to the corresponding video File if they are downloaded in the same package. If the thumbnails don't show up in the link crawler, then you have to enable them in the plugin first.

Code:
// Adds Youtube thumbnail to video (requires you to download the video and thumbnail in the same package)
// Should work with pretty much anything else in the package and you can also use as many youtube videos as you like.
// Trigger Required: "Package Finished"
//
// This script uses ffmpeg (ffmpeg.org)
// If not already done set the path to your ffmpeg file under advanced settings(ffmpegSetup: binary path)
//
// Aditional Info:
// You can select which types you want the linkcrawler to grab under the youtube pluging. For example mp4 + jpg
//
// Detailed description:
// Looks for all mp4 files in a package; compares the ContainerURL with all images in the package (img/png);
// if the matching thumbnail is found copies the video and adds the thumbnail to the copy;
// deletes the video without thumbnail and the thumbnail itself; renames the copied video to the original name
//
// Author @DamonDragon
//
// More event scripts can be found here: https://board.jdownloader.org/showpost.php?p=453474
//
// For debugging you can use:
// writeFile(JD_HOME + "/log_script_youtube_thumbnail_adder.txt", variable + "random text\n", true /*bool append*/ );
//
var links = package.getDownloadLinks();
var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath");

// delete file without recursion
function deleteOriginalFile(filePath) {
    deleteFile(filePath, false);
}

// check all package links for youtube videos (MP4-Files)
for (var i = 0; i < links.length; i++) {
    var videoLink = links[i];
    var videoFile = videoLink.getDownloadPath();

    // only looks for mp4 files from youtube.com 
    // I only tried this script with mp4 files and I'm not sure if ffmpeg works for FLV or MKV,
    // but if it works or you want to try, you can repace "mp4" with "(mp4|flv|mkv)" for example.
    if (videoLink.getHost() == "youtube.com" && /\.mp4$/i.test(videoFile)) {
        var videoURL = videoLink.getContainerURL();
        var imageFile = null;
        var thumbnail = false;

        // search for fitting thumbnail that has the same download url as the MP4-File
        for (var j = 0; j < links.length; j++) {
            var imageLink = links[j];
            var tempImageFile = imageLink.getDownloadPath();
            var imageURL = imageLink.getContainerURL();

            // only looks for jpg and png files that are from youtube.com
            // compares the imageURL with the videoURL. If they match then this should be the thumbnail for the video.
            if (imageLink.getHost() == "youtube.com" && /\.(jpg|png)$/i.test(tempImageFile) && imageURL == videoURL) {

                thumbnail = true;
                imageFile = tempImageFile;

                // The additional if is needed in case you have multiple videos/images with
                // the same name and used "rename". This might execute the break on the first found thumbnail,
                // that had the same name instead of the renamed one.
                if (getPath(imageFile).exists() && getPath(videoFile).exists()) {
                    break;
                }
            }
        }

        // copy video and add thumbnail if there is a matching thumbnail
        // checks if the image and the video are localy saved and not only in the package
        // (prevents the video file from getting deleted if the image isn't locally saved)
        if (thumbnail && getPath(videoFile).exists() && getPath(imageFile).exists()) {

            // Get original file extension
            var originalExtension = videoFile.substring(videoFile.lastIndexOf('.'));

            // temp name for the new video that has the thumbnail (will be renamed later)
            var finalVideo = videoFile + ".tmp." + originalExtension;

            // creates a new video (finalVideo) that contains the thumbnail
            callSync(ffmpeg, "-i", videoFile, "-i", imageFile, "-map", "0", "-map", "1", "-c", "copy", "-c:v:1", "png",
                "-disposition:v:1", "attached_pic", finalVideo);

            // save orginal filepath (name)
            var videoPath = getPath(videoFile);

            // delete thumbnail and unedited video (video without thumbnail)
            deleteOriginalFile(videoFile);
            deleteOriginalFile(imageFile);

            // rename to orginal filepath (name)
            getPath(finalVideo).renameTo(videoPath);
        }
    }
}

Last edited by DamonDragon; 06.06.2024 at 14:22.
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 00: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 - 2024, Jelsoft Enterprises Ltd.