Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebUI: add multi-file renaming #18287

Merged
merged 1 commit into from
Feb 19, 2023
Merged

WebUI: add multi-file renaming #18287

merged 1 commit into from
Feb 19, 2023

Conversation

loligans
Copy link
Contributor

@loligans loligans commented Dec 25, 2022

Closes #16239.
(Partially addresses #6961.)

The purpose of the PR is to enable users to bulk rename files on the WebUI.

Renaming 200 config files
Image Description: Renaming 200 config files using a named variable and the file enumeration variable

Search Options

Search Field: The text criteria to search for as either a plain text string or a regular expression.

Use Regular Expressions: When checked, the search field will be interpreted as an ECMAScript regular expression. If not then the search field will be interpreted as a plain text string.

Match all occurrences: When checked, all matches of text in the search field will be replaced with the replacement text. Otherwise, only the first instance will be replaced.

Case Sensitive: When checked, the text specified in the search field will be treated as case sensitive.

Replace Options

Replacement Field: The replacement field is what you want to replace any matches with.

Applies To:

  • Filename + Extension: The search string will be applied to the Filename and the Extension
  • Filename: The search string will only be applied to the Filename
  • Extension: The search string will only be applied to the Extension

Include Files: When checked, the search will apply to files regardless of any files that are checked

Include Folders: When checked, the search will apply to folders regardless of any folders are checked

Enumerate Files: Specifies the starting point for enumerating files. Files can be enumerated by specifying $d in the replacement field.

Additional Capabilities

Right clicking a folder will allow you to toggle all items underneath that folder. Check vs. Unchecked is determined by the row you right clicked. i.e. if the row you right clicked is unchecked then it will be marked checked and all child items will be marked checked as well.

The Replacement Field has some special variables that can be used in the replacement field.

  • $0: The whole match
  • $N: Every capture group (Where N is an integer, i.e. $1 $2 $3 $4 ... etc)
  • $NamedGroup: The value of named capture groups (Where NamedGroup is the actual name of your capture group)
    • Named groups can be specified by enabling RegEx and specifying a capture group i.e. (?<mynamedgroup>myfilename)
    • Named groups can be used as variables for replacement. In the above example the variable is: $mynamedgroup
  • $d: Enumerate every match (passing additional d's will pad the output up to a maximum of 8 digits)
  • $dddddddd: Example of appending the maximum padding for enumerating files

Variables can be escaped by passing \ such as \$0

Specifying a $ alone without escaping it will not have any effect on the output

Discoverability and Convenience

A new context menu item was added to the Torrents Table to make the Multi-Rename feature more discoverable and convenient to access:
image

By default the Multi-Rename user interface will remember the settings of the last rename operation. The following fields will be remembered: Search, Use Regex, Match All Occurrences, Case Sensitive, Replace, Applies To, Include Files, Include Folders, Enumerate File Count, and Replacement Operation. This setting can be turned off by unchecking the Remember Multi-Rename settings checkbox:
image

@glassez glassez requested review from a team December 25, 2022 06:06
@glassez glassez added the WebUI WebUI-related issues/changes label Dec 25, 2022
@glassez glassez added this to the 4.6.0 milestone Dec 25, 2022
@ArcticGems
Copy link

I dont know what the developers think of this, but I think this is bloat that add unnecessary maintenance for the developers.

@loligans
Copy link
Contributor Author

I dont know what the developers think of this, but I think this is bloat that add unnecessary maintenance for the developers.

I understand your concern, however I could use this feature and I'm sure many others could too. In addition, I planned on maintaining this feature.

@NotTsunami
Copy link
Contributor

I dont know what the developers think of this, but I think this is bloat that add unnecessary maintenance for the developers.

Can you define bloat for me? You voiced the same concern in the past for a larger featureset targeting the main GUI, but I truly wonder where the line is drawn for a new feature to be considered bloat or not. This is a significantly smaller patch that I think is worth looking into.

Realistically, this will take some time to be reviewed. 5.0.0 is probably a better milestone for this PR.

@thalieht
Copy link
Contributor

thalieht commented Dec 25, 2022

  • Select folder + file in it
  • include files + folders + repalce all
  • rename a common part
  • Rename failed: file or folder already exists 'renamed_file_name' (folder succeeded)

Do note that when i was testing the above, i somehow managed to make it create a new folder with the new name and the selected file was moved in it. Unfortunately i wanted to finish with the above and i thought i'd reproduce it later with more details but now i have no idea how i did it and what settings were related.

An enhancement would be to create the window width with options on the left + longest filename x2 (so there is space for original and renamed columns).

I didn't test regex and i went in blind (didn't read OP description). I had no idea what "Enumerate Files" does and i don't see how users will figure it out without some explanation.

Include Files: When checked, the search will apply to files regardless of any files that are checked
Include Folders: When checked, the search will apply to folders regardless of any folders are checked

Maybe i misunderstood what "the search will apply" means but i can only rename checked items.

@loligans
Copy link
Contributor Author

loligans commented Dec 25, 2022

i somehow managed to make it create a new folder with the new name and the selected file was moved in it.

This is something I intentionally left in because the single file rename actually allows you to specify a folder path and the file will be moved into the folder path. i.e.

MyRootFolder
  - ChildFolder1/
  - TestFile

TestFile can be renamed to be under a subfolder by specifying TestFolder/TestFile for the replacement


MyRootFolder
  - ChildFolder1/
  - TestFolder/
    - TestFile

That said, I could intentionally block this behavior if it isn't what we'd like to see. I left it in because the existing single file rename allows that behavior.

An enhancement would be to create the window width with options on the left + longest filename x2 (so there is space for original and renamed columns).

I'm not opposed to this, however the window is already resizable, so I'd consider this as something that would be a good candidate for a next version

I didn't test regex and i went in blind (didn't read OP description). I had no idea what "Enumerate Files" does and i don't see how users will figure it out without some explanation.

This is a really good point and if there is a hint icon (?) that users can hover over with a brief description I think that might help. I tried to make the interface as intuitive as possible but multi-file renaming is a little complicated

Maybe i misunderstood what "the search will apply" means but i can only rename checked items.

We can change the verbiage to be more concise. Correct you can only rename checked files. However, with Include Files checked and Include Folders unchecked, folders that have been checked will be ignored. If you want to rename folders you would need to check Include Folders

@loligans
Copy link
Contributor Author

Updated #18287 (comment) to include:

Right clicking a folder will allow you to toggle all items underneath that folder. Check vs. Unchecked is determined by the row you right clicked. i.e. if the row you right clicked is unchecked then it will be marked checked and all child items will be marked checked as well.

@Roardom
Copy link

Roardom commented Dec 26, 2022

That said, I could intentionally block this behavior if it isn't what we'd like to see. I left it in because the existing single file rename allows that behavior.

Please do not block this behavior. I use it frequently when cross seeding and know others who do as well. Also linking #16906 #16834 #17049

@Mika3578
Copy link

Is there a way to use with a Filebot script to auto rename files in desired format ?

@thalieht
Copy link
Contributor

TestFile can be renamed to be under a subfolder by specifying TestFolder/TestFile for the replacement

Of course that's fine by me. The thing is, there was no slash involved when i did it. In fact it happened again now that i was re-testing the PR and although this time i payed attention i can't reproduce it again. What i did:

  1. Select root folder + a file in it.
  2. Open rename dialog
  3. Fill the fields for search and replace
  4. Tick Include folders
  5. Select Replace all and click it

Ranamed milo and file1.rar (root folder and file) to for example replace "il" with "on" (there was no folder1 last time, every file was in the root folder)

milo <----root folder
    folder1
        file1.rar
    file2
    file3

It became:

milo
    folder1
        fone1.rar
mono <---  (milo -> mono)
    file2
    file3

You didn't comment on the problem i described with bullet points at the beginning of #18287 (comment) which still happen by the way. It seems to be related with the unwanted folder creation described above because when that happened there was no error,

Another problem that i just noticed is that the Renamed column header does not appear when horizontal scrolling and it's out of view. It appears when window is resized so there is space for it.

One last thing: any existing error from previous rename isn't cleared after a successful rename (in the same dialog).

@loligans
Copy link
Contributor Author

loligans commented Jan 3, 2023

In fact it happened again now that i was re-testing the PR and although this time i payed attention i can't reproduce it again.

Interesting, would you mind uploading a video/gif of the behavior you're experiencing? One potential thing to test for reproducibility is refreshing the page before each test.

Ranamed milo and file1.rar (root folder and file) to for example replace "il" with "on" (there was no folder1 last time, every file was in the root folder)

This suggests that order of operations matter's here. i.e. milo was renamed to mono however, file1.rar still contained the old path and as a result the rename operation put it under a new milo folder. I'll see how I can fix this.

You didn't comment on the problem i described with bullet points at the beginning of #18287 (comment) which still happen by the way. It seems to be related with the unwanted folder creation described above because when that happened there was no error,

I think you're correct about it being related. Essentially the rename all operation changes files one by one and if it encounters an error it will fire an event and continue renaming.

Another problem that i just noticed is that the Renamed column header does not appear when horizontal scrolling and it's out of view. It appears when window is resized so there is space for it.

The columns remember their original position by default, I think this can be changed. such that both share an equal amount of horizontal space.

One last thing: any existing error from previous rename isn't cleared after a successful rename (in the same dialog).

good catch haha I'll fix this.

@thalieht
Copy link
Contributor

thalieht commented Jan 8, 2023

Interesting, would you mind uploading a video/gif of the behavior you're experiencing?

Unfortunately i can't reproduce it again.

Another problem that i just noticed is that the Renamed column header does not appear when horizontal scrolling and it's out of view. It appears when window is resized so there is space for it.

The columns remember their original position by default, I think this can be changed. such that both share an equal amount of horizontal space.

header

@loligans loligans force-pushed the master branch 3 times, most recently from 87c8eef to 60d8e50 Compare January 21, 2023 20:29
@loligans
Copy link
Contributor Author

loligans commented Jan 21, 2023

@thalieht Okay I've pushed up some changes to fix the issues you were running into. I'll cover the changes in this comment.

  1. Added a remove function to the LocalPreferencesClass so that I could remove localStorage keys.
  2. Prevented the BulkRename table from remembering the column widths by removing the key in localStorage that stores the columns previous width. The reason is because the window width is not remembered by default.
  3. Fixed Rename All by iterating in reverse, this is because the matchedFiles are in DFS order which should prevent unwanted file/folder creation. Note: Single File Renames still iterate linearly but since the table gets refreshed after every rename we don't run into the problem of unwanted files/folders.
  4. Fixed the header scrolling by binding the table body horizontal scroll location to the table header horizontal scroll location.
  5. Updated new defaults for the column headers. 50px for the checkbox column, 270px for the original column, and 220px for the renamed column. These numbers were decided based off the windows 800px default size.

Let me know if I missed anything or if my assumptions are incorrect and of course if you or anyone else run into a bug with the updated code.

thalieht
thalieht previously approved these changes Jan 22, 2023
Copy link
Contributor

@thalieht thalieht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (as a tester)

@loligans
Copy link
Contributor Author

loligans commented Jan 26, 2023

Pushed up changes to fix the WebUI linter errors generated from the linter workflow.
Edit: Updated code cause I missed a semicolon
Edit2: Fixed CSS linter errors generated by CI pipeline
Edit3: Fixed formatting errors generated by CI pipeline

thalieht
thalieht previously approved these changes Feb 16, 2023
@glassez
Copy link
Member

glassez commented Feb 17, 2023

This setting can be turned off in the Saving Management preferences menu:
image

"Saving management" is about torrent content and related things.
IMO, the best place for such checkbox is the "rename dialog" itself.

@Traineratwot
Copy link

@loligans I need this feature, I have a TV series with more than 1000 episodes and there is a jellyfin program that better recognizes files named in a certain way, and I would like to be able to rename from and still remain a torrent distributor. can I repeat your preview? it works?
p.s
I think everyone here underestimates this functionality

@loligans
Copy link
Contributor Author

"Saving management" is about torrent content and related things.

IMO, the best place for such checkbox is the "rename dialog" itself.

sounds good, i'm working on a change to move it into the rename dialog.

@loligans
Copy link
Contributor Author

loligans commented Feb 18, 2023

@glassez the latest change moves the preference to the renaming window:
image

i wanted to put the setting behind a cog-icon-button to avoid adding preferences directly to the main window, but for the sake of simplicity, i took the approach of displaying the preference and having an <hr> separate it from the rest of the functionality. if more options get added in the future then i will put it behind a button that'll display a list of preferences

@loligans
Copy link
Contributor Author

@loligans I need this feature, I have a TV series with more than 1000 episodes and there is a jellyfin program that better recognizes files named in a certain way, and I would like to be able to rename from and still remain a torrent distributor. can I repeat your preview? it works? p.s I think everyone here underestimates this functionality

the functionality outlined in this pr will allow you to rename multiple files of a torrent as a bulk operation and still be able to remain a torrent distributor. the preview i have been using confirms this behavior

@glassez glassez merged commit 4663146 into qbittorrent:master Feb 19, 2023
@glassez
Copy link
Member

glassez commented Feb 19, 2023

@loligans
Thank you!

Note that some flaws may remain hidden until it goes in the release so that many users will have access to it. I hope you'll still be here at that moment to fix them.

@loligans
Copy link
Contributor Author

yup, i plan to support this feature going forward!

@varad-kadam
Copy link

Hello,
I'm using qbittorrent-nox, and on v4.5.4 Web UI (64-bit).
From what I see, this feature being tested and set to be introduced in v5.0.0, however I really need it now.

Could someone please detail on how to build / get a custom version of qbittorrent-nox working that includes this patch?

@JDENredden
Copy link

Can this be automated to act on every torrent when added? Can I call it from the API?

@loligans
Copy link
Contributor Author

Can this be automated to act on every torrent when added? Can I call it from the API?

No this currently is implemented on the frontend using JavaScript. It cannot be invoked by any API on the qBittorrent backend.

@OrenRahat
Copy link

Being a complete novice, how do I add this great functionality?

@thalieht
Copy link
Contributor

Being a complete novice, how do I add this great functionality?

Select at least 2 items in the Content tab and Rename. Only available in WebUI if it's not clear.

@boydaihungst
Copy link

boydaihungst commented Jan 21, 2024

Being a complete novice, how do I add this great functionality?

Use version >= 4.6.0. Right-click torrent > rename files. Or select >= 2 files in the Content tab.
Tips: this can also be used to move files/folders to sub-folders: folder1/folder2/folder3/$0

@Anrock
Copy link

Anrock commented Mar 28, 2024

Would be nice to have help texts (the ones from description are good) as tooltips for input fields and checkboxes. I've found this PR via google when trying to understand how to use this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebUI: Bulk Rename Files