![](https://snipboard.io/Zwsmk6.jpg)
#1
|
|||
|
|||
![]()
What's the 'right way' to remove multiple #hashtags from a filename?
Some sites are using #this #that #another #whatever and all kinds of other #hashtags as part of a download filename. This often results in excessively long filenames, which can cause problems with a resulting path that's too long for the filesystem. I'd like to rename the file being grabbed to omit all of those #hashtags. I believe this regex would do it? /#[a-zA-Z0-9_]+/g But I'm unclear on how to use to get all #hashtags removed from a filename. And if not as a rule, any tips on how an Event Script would approach this? |
#2
|
||||
|
||||
![]()
@wkearney99: Please provide example links as it is important if those hashtags are already part of filename when they are in list or set before download.
Also helps us to provide better help on this when we can actual test it by ourselves.
__________________
JD-Dev & Server-Admin |
#3
|
|||
|
|||
![]()
I don't know if this is the "best way" to do it, but I'm using this script on a packagizer hook event script:
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 thought using a 'new link has been added' hook would be better, but I wasn't sure how to get to the necessary variables. That is, the code didn't do anything when called from a new link hook. I'd welcome feedback on whether this is the right place to have it run, or any code improvement suggestions. I'd love to do this in just a packagizer rule, but just could not figure out the magic incantations to make it work. Last edited by wkearney99; 26.11.2024 at 02:24. Reason: added a check for the filename including a # character |
#4
|
|||
|
|||
![]()
It is REALLY opaque trying to figure out where/how scripts/rules run and what variables/contexts they have available.
|
#5
|
||||
|
||||
![]()
@wkearney99:
You can see all available commands/objects/method in help section above the editor. You can code and then run script in test mode which will have dummy objects. You can fill those dummy objects and then use logging/alert to show results. You can also make use of Settings->Advanced Settings->GeneralSettings.filenamereplacemap and define replace/matcher pattern that will be applied to filenames. That way you should be easily able to do what you want.
__________________
JD-Dev & Server-Admin |
#6
|
|||
|
|||
![]()
Does filenamereplacemap handle Regexes? I have already edited my filenamereplacemap to handle some apostrophe variations.
Code:
{ ":" : "", "\\|" : "¦", "<" : "[", ">" : "]", "/" : "\u2044", "\\\\" : "∖", "\\*" : "#", "\\?" : "¿", "\"" : "'", "‘" : "'", "’" : "'", "‘" : "'", "\u2013" : "-", "\u2018" : "'" } Which logging? Which alerts? You get how finding the log and alert commands is a hassle in that long list, right? Yes, "it's in there" but that's it for documentation? I know, it's free software, and it's GREAT software, but going beyond the basics of using it is like making an appointment to get your teeth pulled. You know it's going to take ALL DAY and be painful. I swear, having an idea about adding something to how I use JD and carving out the time necessary to slog through forums to figure it out is nearly as bad as a root canal. Oh, and toss in a few "go use the search" or "read through the Event Scripter thread" posts from others do generally not speed the process. Side rant: it would be GREAT to have the Event Scripter thread broken out into it's own sub-forum. I've suggested it here. But hey, like I said, it's great software! I'm glad to have it, just a little annoyed by it sometimes. |
#7
|
||||
|
||||
![]()
Yes, those are regex and matcher
Quote:
![]() Quote:
Here it is, https://board.jdownloader.org/forumdisplay.php?f=52 Quote:
hence the recommendation to use replacemap feature. replacements are processed from top to bottom
__________________
JD-Dev & Server-Admin Last edited by Jiaz; 26.11.2024 at 11:30. |
#8
|
||||
|
||||
![]()
Yes. The settings' description also says that.
Screenshot:
Spoiler:
![]() Feel free to provide feedback for us to improve usability/settings/documentation.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#9
|
|||
|
|||
![]()
That wasn't my take-away from seeing the helper text. That and the default example only has single character matches presented.
I have since tried it with a regex and it does indeed work. Nice. Though I think I'm going to stick with using an Event Script as it's easier to turn it on/off with a checkbox. |
![]() |
Thread Tools | |
Display Modes | |
|
|