gyng / save-in

WebExtension for saving media, links, or selections into user-defined directories
MIT License
205 stars 25 forks source link

Remove certain part of the pagetitle #97

Closed Wombat2018 closed 5 years ago

Wombat2018 commented 5 years ago

Hi,

my new file name depends on the pagetitle. How can I delete certain parts or words? I would like to do this because the file extension and then some other characters are included. Then Save In writes the file extension again. I would like to avoid this by simply deleting a part of the pagetitle and not writing any new file extension, so that I can use the pagetitle without some words.

My rule:

pagedomain: xxx context: link into: :pagetitle:.mp3

What has to be changed in the last line?

Example file: abc.mp3 - xyz.mp3

gyng commented 5 years ago

You can use capture groups for this

pagedomain: xxx
context: link
pagetitle: (.*) - (.*)
capture: pagetitle
into: :$2:

That will rename downloads to xyz.mp3 when the page title is abc.mp3 - xyz.mp3. The options page might be a little bugged with page titles.

Wombat2018 commented 5 years ago

Sorry, your solution does not work because my choice of words was bad. The pagetitle is: x y z a b.mp3 - dog Are the spaces between "x y z a b" decisive for the regex groups? Anyway, I would now like to remove from this pagetitle everything behind the mp3, which is in this case: " - dog"

gyng commented 5 years ago

As long as it has a - in the regex it should work.

You can try using an online regex tester such as https://regex101.com/ or http://www.rubular.com/ to help. eg. https://regex101.com/r/tQFwdd/3

Wombat2018 commented 5 years ago

I discovered the problem. The pagetitle returns a dash and not a hyphen. That's why it does not work. If I want to insert in Save In a dash that I copied before, it will be displayed as a hyphen. How do you solve this?

Edit: It is displayed as hypen, but I used ALT+0150 to insert a dash an now it works! Besides, now I understand Regex. Thank you very much!