View Single Post
  #196  
Old 07.10.2022, 17:45
georgegalily georgegalily is offline
Super Loader
 
Join Date: Oct 2018
Posts: 29
Default

This is the targeted script mentioned above:
Code:
//Add your script here. Feel free to use the available api properties and methods
// If download link is present in history file, mark it as duplicae (add "#duplicatelink" to comment)
// Trigger required: Packagizer Hook

if (state == "AFTER") {
    var url = link.getURL();
    var historyFile = getPath(JD_HOME + "/cfg/history.txt");
    var history = historyFile.exists() ? readFile(historyFile) : "";

    if (history.indexOf(url) > -1) {
        var text = "#duplicatelink";
        var comment = link.getComment();
        comment = comment ? text + " " + comment : text;
        link.setComment(comment);
      //  link.enabled = false;
      sleep(1000)
      link.remove();
    }
}
This the even script export

Code:
[
 {
  "eventTrigger"         : "ON_ARCHIVE_EXTRACTED",
  "eventTriggerSettings" : {},
  "id"                   : 1636093853265,
  "name"                 : "",
  "script"               : null,
  "enabled"              : false
 },
 {
  "eventTrigger"         : "ON_NEW_LINK",
  "eventTriggerSettings" : {
                            "isSynchronous" : false
                           },
  "id"                   : 1665130121066,
  "name"                 : "Disable duplicate link in Lingrabber",
  "script"               : "/* \n    Disable duplicate link in Lingrabber list\n    Trigger required: A new link has been added\n*/\n\nvar link = crawledLink;\n\nif (link.availableState == \"ONLINE\") {\n    var file = getPath(JD_HOME + \"/cfg/history.txt\");\n\n    var lock = getModifyLock(file.name);\n    lock.writeLock();\n\n    var urls = getProperty(file.name, true);\n\n    if (urls == null) {\n        urls = file.exists() && readFile(file) || \"\";\n        setProperty(file.name, urls, true);\n    }\n\n    lock.writeUnlock();\n\n    if (urls) {\n        var url = link.contentURL || link.pluginURL;\n\n        if (link.host == \"youtube.com\") {\n            url = link.containerURL;\n        }\n\n        if (urls.indexOf(url) > -1) {\n            var text = \"#duplicatelink\";\n            var comment = link.comment;\n\n            if (comment) {\n                text = text + \" \" + comment;\n            }\n\n            link.comment = text;\n            link.enabled = false;\n        }\n    }\n}\n",
  "enabled"              : false
 },
 {
  "eventTrigger"         : "ON_PACKAGIZER",
  "eventTriggerSettings" : {
                            "isSynchronous" : false
                           },
  "id"                   : 1665128070287,
  "name"                 : "mark it as duplicae",
  "script"               : "//Add your script here. Feel free to use the available api properties and methods\n// If download link is present in history file, mark it as duplicae (add \"#duplicatelink\" to comment)\n// Trigger required: Packagizer Hook\n\nif (state == \"AFTER\") {\n    var url = link.getURL();\n    var historyFile = getPath(JD_HOME + \"/cfg/history.txt\");\n    var history = historyFile.exists() ? readFile(historyFile) : \"\";\n\n    if (history.indexOf(url) > -1) {\n        var text = \"#duplicatelink\";\n        var comment = link.getComment();\n        comment = comment ? text + \" \" + comment : text;\n        link.setComment(comment);\n      //  link.enabled = false;\n      sleep(1000)\n      link.remove();\n    }\n}",
  "enabled"              : false
 },
 {
  "eventTrigger"         : "DOWNLOAD_TABLE_CONTEXT_MENU_BUTTON",
  "eventTriggerSettings" : {},
  "id"                   : 1665128070283,
  "name"                 : "Move to history",
  "script"               : "// Add finished download links from selection to history, and remove them from the list\n// Tirgger required: Downloadlist Contextmenu Button Pressed\n// Customize downloadlist context menu > Add new \"Eventscripter Trigger\" button > Rename it to \"Move to history\" (without quotes) > Change Icon (optional)\n\nif (name == \"Move to history\") {\n    var file = getPath(JD_HOME + \"/cfg/history.txt\"),\n        urls = file.exists() ? readFile(file) : \"\",\n        newUrls = \"\",\n        url, data, text, comment;\n\n    dlSelection.links.forEach(function(link) {\n        if (link.finished) {\n            url = link.contentURL || link.pluginURL;\n\n            if (urls.indexOf(url) == -1) {\n                newUrls += url + \"\\r\\n\";\n                link.remove();\n            }\n        }\n    });\n\n    if (newUrls.length) {\n        data = \"Added from the downloadlist list on \" + Date().toString().substring(4, 24) + \"\\r\\n\";\n        data += newUrls + \"\\r\\n\";\n        writeFile(file, data, true);\n\n        getAllCrawledLinks().forEach(function(link) {\n            if (link.availableState == \"ONLINE\") {\n                url = link.contentURL || link.pluginURL;\n                text = \"#duplicatelink\";\n                comment = link.comment || \"\";\n                \n                if (comment.indexOf(text) == -1 && (urls + newUrls).indexOf(url) > -1) {\n                    link.comment = comment ? text + \" \" + comment : text;\n                }\n            }\n        });\n    }\n}\n",
  "enabled"              : true
 },
 {
  "eventTrigger"         : "ON_DOWNLOAD_CONTROLLER_START",
  "eventTriggerSettings" : {
                            "isSynchronous" : false
                           },
  "id"                   : 1665128070289,
  "name"                 : "duplicatelinkch",
  "script"               : "//Add your script here. Feel free to use the available api properties and methods\n// Skip link if it present in download history (has \"#duplicatelink\" in comment)\n// To download the file (prevent skipping), remove \"#duplicatelink\" from comment\n// Trigger required: A Download Started\n\nvar comment = link.getComment() || \"\";\n\nif (comment.indexOf(\"#duplicatelink\") > -1) {\n    var url = link.getContentURL() || link.getPluginURL();\n    link.setSkipped(true);\n  //  alert(\"Download Skipped: \\\"\" + url + \"\\\" is present in history file.\");\n}",
  "enabled"              : true
 },
 {
  "eventTrigger"         : "LINKGRABBER_TABLE_CONTEXT_MENU_BUTTON",
  "eventTriggerSettings" : {},
  "id"                   : 1665128070285,
  "name"                 : "Move to historyLG",
  "script"               : "// Add selected linkgrabber links to history, and remove them from the list\n// Tirgger required: Linkgrabber Contextmenu Button Pressed\n// Customize linkgrabber context menu > Add new \"Eventscripter Trigger\" button > Rename it to \"Move to history\" (without \nquotes) > Change Icon (optional)\n\nif (name == \"Move to history\") {\n    var historyFile = getPath(JD_HOME + \"/cfg/history.txt\");\n    if (!historyFile.exists()) writeFile(historyFile, \"\", true);\n    var history = readFile(historyFile);\n\n    var linkUrls = [];\n    var linkIds = [];\n\n    var removeLinks = function(linkIds) {\n        callAPI(\"linkgrabberv2\", \"removeLinks\", linkIds, []);\n    }\n\n    lgSelection.getLinks().forEach(function(link) {\n        var url = link.getUrl();\n        var id = link.getUUID();\n\n        if (history.indexOf(url) == -1) linkUrls.push(url);\n        linkIds.push(id);\n    })\n\n    if (linkUrls.length) {\n        data = \"Added from the lingkrabber list on \" + Date().toString().substring(4, 24) + \"\\r\\n\";\n        data += linkUrls.join(\"\\r\\n\") + \"\\r\\n\\r\\n\";\n        writeFile(historyFile, data, true);\n    }\n\n    if (linkIds.length) removeLinks(linkIds);\n}",
  "enabled"              : true
 }
]

Last edited by georgegalily; 07.10.2022 at 17:54.
Reply With Quote