mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
parent
84ed24e257
commit
4e9c514c2f
1 changed files with 38 additions and 37 deletions
|
@ -15,41 +15,41 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
Extension: "Extension"
|
||||
};
|
||||
|
||||
const RenameFiles = new Class({
|
||||
hash: "",
|
||||
selectedFiles: [],
|
||||
matchedFiles: [],
|
||||
class RenameFiles {
|
||||
hash = "";
|
||||
selectedFiles = [];
|
||||
matchedFiles = [];
|
||||
|
||||
// Search Options
|
||||
_inner_search: "",
|
||||
setSearch: function(val) {
|
||||
this._inner_search = val;
|
||||
this._inner_update();
|
||||
#inner_search = "";
|
||||
setSearch(val) {
|
||||
this.#inner_search = val;
|
||||
this.#inner_update();
|
||||
this.onChanged(this.matchedFiles);
|
||||
},
|
||||
useRegex: false,
|
||||
matchAllOccurrences: false,
|
||||
caseSensitive: false,
|
||||
}
|
||||
useRegex = false;
|
||||
matchAllOccurrences = false;
|
||||
caseSensitive = false;
|
||||
|
||||
// Replacement Options
|
||||
_inner_replacement: "",
|
||||
setReplacement: function(val) {
|
||||
this._inner_replacement = val;
|
||||
this._inner_update();
|
||||
#inner_replacement = "";
|
||||
setReplacement(val) {
|
||||
this.#inner_replacement = val;
|
||||
this.#inner_update();
|
||||
this.onChanged(this.matchedFiles);
|
||||
},
|
||||
appliesTo: AppliesTo.FilenameExtension,
|
||||
includeFiles: true,
|
||||
includeFolders: false,
|
||||
replaceAll: false,
|
||||
fileEnumerationStart: 0,
|
||||
}
|
||||
appliesTo = AppliesTo.FilenameExtension;
|
||||
includeFiles = true;
|
||||
includeFolders = false;
|
||||
replaceAll = false;
|
||||
fileEnumerationStart = 0;
|
||||
|
||||
onChanged: (rows) => {},
|
||||
onInvalidRegex: (err) => {},
|
||||
onRenamed: (rows) => {},
|
||||
onRenameError: (response) => {},
|
||||
onChanged(rows) {}
|
||||
onInvalidRegex(err) {}
|
||||
onRenamed(rows) {}
|
||||
onRenameError(response) {}
|
||||
|
||||
_inner_update: function() {
|
||||
#inner_update() {
|
||||
const findMatches = (regex, str) => {
|
||||
let result;
|
||||
let count = 0;
|
||||
|
@ -119,7 +119,7 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
this.matchedFiles = [];
|
||||
|
||||
// Ignore empty searches
|
||||
if (!this._inner_search)
|
||||
if (!this.#inner_search)
|
||||
return;
|
||||
|
||||
// Setup regex flags
|
||||
|
@ -131,10 +131,10 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
|
||||
// Setup regex search
|
||||
const regexEscapeExp = /[/\-\\^$*+?.()|[\]{}]/g;
|
||||
const standardSearch = new RegExp(this._inner_search.replace(regexEscapeExp, "\\$&"), regexFlags);
|
||||
const standardSearch = new RegExp(this.#inner_search.replace(regexEscapeExp, "\\$&"), regexFlags);
|
||||
let regexSearch;
|
||||
try {
|
||||
regexSearch = new RegExp(this._inner_search, regexFlags);
|
||||
regexSearch = new RegExp(this.#inner_search, regexFlags);
|
||||
}
|
||||
catch (err) {
|
||||
if (this.useRegex) {
|
||||
|
@ -185,7 +185,7 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
let renamed = row.original;
|
||||
for (let i = matches.length - 1; i >= 0; --i) {
|
||||
const match = matches[i];
|
||||
let replacement = this._inner_replacement;
|
||||
let replacement = this.#inner_replacement;
|
||||
// Replace numerical groups
|
||||
for (let g = 0; g < match.length; ++g) {
|
||||
const group = match[g];
|
||||
|
@ -215,9 +215,9 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
++fileEnumeration;
|
||||
this.matchedFiles.push(row);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
rename: async function() {
|
||||
async rename() {
|
||||
if (!this.matchedFiles || (this.matchedFiles.length === 0) || !this.hash) {
|
||||
this.onRenamed([]);
|
||||
return;
|
||||
|
@ -269,12 +269,13 @@ window.qBittorrent.MultiRename ??= (() => {
|
|||
await _inner_rename(0);
|
||||
}
|
||||
this.onRenamed(replaced);
|
||||
},
|
||||
update: function() {
|
||||
this._inner_update();
|
||||
}
|
||||
|
||||
update() {
|
||||
this.#inner_update();
|
||||
this.onChanged(this.matchedFiles);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return exports();
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue