Thread: [See Bugtracker] Tumblr
View Single Post
  #61  
Old 25.04.2016, 12:06
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 611
Default

Define maximum length for file (and package) name using event scripter.
Code:
/*
Script: Tumblr workaround
Trigger:"Packagizer Hook"
*/

var tumblr = /.*\.tumblr.com\/post\/.*/.test(link.getSourceUrls().join());

if (tumblr) {
    var fileName = link.name.replace(/(.+)\..+$/, "$1");
    var fileType = link.name.replace(/.+(\..+$)/, "$1");
    var packageName = link.packageName !== null ? link.packageName : "Unknown";
    var maxLength = 65; // set maximum allowed length for file name (maxLength - 20 will be used for package name)
    var newFileName = fileName.substring(0, maxLength).substr(0, Math.min(fileName.substring(0, maxLength).length, fileName.substring(0, maxLength).lastIndexOf(" ")));
    var newPackageName = packageName.substring(0, maxLength - 20).substr(0, Math.min(packageName.substring(0, maxLength - 20).length, packageName.substring(0, maxLength - 20).lastIndexOf(" ")));
    var user = link.getSourceUrls().join().replace(/.*http:\/\/([^.]+)[^/]+\/post\/.*/, "$1");
    var description = link.name.replace(/\d+\s+-\s+\d+\s+\-\s(.+)\..+$/, "$1");

    link.setName(user + " - " + newFileName + fileType); // filename with prefix (Easier to identify single files in "Various Files" package)
    link.setPackageName(user + " - " + newPackageName); // packageName with prefix

    //link.setName(newFileName + fileType); // filename without prefix
    //link.setPackageName(newPackageName); // packageName without prefix
    //link.setComment(description); // Set the original filename as comment
}
Reply With Quote