JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 26.11.2024, 19:56
wkearney99 wkearney99 is offline
DSL Light User
 
Join Date: May 2024
Posts: 33
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
  #2  
Old 26.11.2024, 20:22
wkearney99 wkearney99 is offline
DSL Light User
 
Join Date: May 2024
Posts: 33
Default

And from additional comments, I learn it's possible to do this same thing by going into Advanced Settings and adding the Regex to the Filename Replace Map.

I have mine set to:
Code:
{
 ":"    : "",
 "\\|"  : "¦",
 "<"    : "[",
 ">"    : "]",	
 "/"    : "\u2044",
 "\\\\" : "∖",
 "\\*"  : "#",
 "\\?"  : "¿",
 "\""   : "'",
 "‘"    : "'",
 "’"    : "'",
 "‘"    : "'",
 "\u2013" : "-",
 "\u2018" : "'",
 "#[a-zA-Z0-9_]+" : ""
}
I suppose the only reason to keep using it as an Event Script would be to make it easier to turn on/off. The checkbox on a script is simpler than going into this text field and editing the value.

Gotta love JD... there's always more than one way to 'skin the cat', eh?
Reply With Quote
  #3  
Old 26.11.2024, 20:26
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 73,753
Default

Quote:
Originally Posted by wkearney99 View Post
The checkbox on a script is simpler than going into this text field and editing the value.
Yes and no.

You can also add buttons to scripts which then modify values of advanced settings so there you have another way
__________________
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
  #4  
Old 27.11.2024, 10:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,648
Default

Quote:
Originally Posted by wkearney99 View Post
I suppose the only reason to keep using it as an Event Script would be to make it easier to turn on/off.
+that you have move flexibility and can do way more, eg parsing name and search for information and rewrite stuff or check additional information, eg parse size/width/codec....from properties and add them to name
__________________
JD-Dev & Server-Admin
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 17:33.
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.