View Single Post
  #1021  
Old 06.12.2019, 13:47
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,553
Default

Quote:
Originally Posted by SMS View Post
How can I rename files? I want to download domain.com/foo/bar.zip as bar_foo.zip rather than as bar.zip. The renaming should happen early. For example as a Packagizer Hook, or within the following call in a script I have:

Code:
myObject = callAPI("linkgrabberv2", "addLinks", {
    "links": theLink
});
Code:
// Rename files by matching download url pattern
// Trigger: Packagizer Hook

if (state == "BEFORE") {
    var patt = /.+\/domain\.com\/(foo)\/(bar)(\.zip)/i;
    var name = link.getURL().match(patt);
    if (name) link.setName(name[2] + "_" + name[1] + name[3]);
}

Packagizer rules not suitable for this?
Reply With Quote