JDownloader Community - Appwork GmbH
 

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 26.11.2024, 19:56
wkearney99 wkearney99 is offline
Wind Gust
 
Join Date: May 2024
Posts: 40
Default Removing hashtags from download filenames

I've come across a number of sites that now include #hashtag text in the filenames. I don't want those, as they tend to make the pathname excessively long.

I raised the question on this thread.

I wrote this script to strip them out. It's called via Event Scripter using a Packagizer Hook:

Code:
if (linkcheckDone) {

    var myPackagizerLink = link;
    var fileName = myPackagizerLink.getName();
    var re, ext, newName;

    if (fileName !== null && fileName.includes("#")) {

        ext = fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2);
        if (ext !== "") {
            ext = "." + ext.toLowerCase();
        }

        fileName = fileName.substr(0, (fileName.length - ext.length));

        rgx = new RegExp("#[a-zA-Z0-9_]+", "gi");
        newName = fileName.replace(rgx, "");

        rgx = new RegExp("\\s\\s+", "gi");
        newName = newName.replace(rgx, " ");

        newName = newName.trim();

        myPackagizerLink.setName(newName + ext);
    }
}
I'd welcome suggestions on improving it, or accomplishing the goal in another manner.
Reply With Quote
 

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 12:45.
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 - 2025, Jelsoft Enterprises Ltd.