Page 1 of 1
Search and Replace, a chain of commands
Posted: 27 Oct 2022 20:30
by haaranoos
Hello
I have lots of movies, all containing 1080p, Web-dl, YIFY, etc... I want to remove them right?
this is my command to remove some unwanted Infos:
WEB-DL|YIFY|1080p|web-dl|WEB-Dl|WEB DL|BluRay|10bit x265|WEBRip 6CH PSA|WEBRip|BrRip| | >>
It works but the left-offs are like this:
Movie___2022__.mp4
I added a |_| too
WEB-DL|YIFY|1080p|web-dl|WEB-Dl|WEB DL|BluRay|10bit x265|WEBRip 6CH PSA|WEBRip|BrRip|_| | >>
but as long as all replacements occur simultaneously, It looks like this:
Movie2022.mp4 instead of Movie 2022.mp4!
is there a way to chain these commands to be executed one after another?
Thaaaank you
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 20:47
by highend
Only by scripting it
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 20:49
by haaranoos
would you please let me know how?

Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 21:14
by highend
Post full original file names
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 21:17
by haaranoos
Aww thank you:
Deadstream_2022_1080p_WEB-DL_YIFY_30NAMA.mp4
I want it to be like :
Deadstream 2022.mp4
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 21:20
by highend
And ALL of them follow this format?
<name of move>_<year>_<unnecessary stuff>.<extension>?
What if a movie name contains spaces, or are there only underscores in them?
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 21:31
by haaranoos
no not all of them,
I thought you might give me a template script with these words so I can give or take a few words to make it work for other movies.
my first post shows 80% of the info I don't want.
A Quiet Place Part II_2020_10bit__x265_BrRip_8CH_PSA.mkv
Re: Search and Replace, a chain of commands
Posted: 27 Oct 2022 22:51
by haaranoos
|t is perfect
Thank you
but with the script, the movie :
The_School_for_Good_and_Evil_2022_10bit_720p_x265_WEB-DL_6CH_PSA_30NAMA.mkv
becomes :
The.mkv
It think there's something wrong!
Thanks again
Re: Search and Replace, a chain of commands
Posted: 28 Oct 2022 00:01
by highend
Code: Select all
// Do not add the space here!
$remove = <<<>>>
_
6ch
8ch
720p
1080p
10bit
30nama
bluray
brrip
psa
web dl
web-dl
webrip
x264
x265
yify
>>>;
$remove = replace(regexreplace($remove, "^[ \t]+"), <crlf>, "|");
$items = <get SelectedItemsNames>;
$pattern = "([ ]|" . replace($remove, " ", "(_| )+") . ")";
foreach($item, $items, <crlf>, "e") {
if (regexmatches($items, $pattern)) {
$ext = gpc($item, "ext");
$base = gpc($item, "base");
$base = regexreplace($base, $pattern, " ");
$base = trim(regexreplace($base, "[ ]{2,}", " "));
// This could catch multiple dates, we'll only use the last found
$date = gettoken(regexmatches($base, "\b\d{4}\b"), -1, "|");
$new = $base . "." . $ext;
if ($date) { $new = gettoken($base, 1, $date, "t") . " " . $date . "." . $ext; }
if ($new UnLikeI $item) { renameitem($new, $item); }
}
}
Re: Search and Replace, a chain of commands
Posted: 28 Oct 2022 09:33
by haaranoos
Coooooooool
doing exactly what I wanted.
Thank youuuuuu
Re: Search and Replace, a chain of commands
Posted: 30 Oct 2022 18:35
by kotlmg
highend wrote: ↑28 Oct 2022 00:01
Code: Select all
// Do not add the space here!
$remove = <<<>>>
_
6ch
8ch
720p
1080p
10bit
30nama
bluray
brrip
psa
web dl
web-dl
webrip
x264
x265
yify
>>>;
$remove = replace(regexreplace($remove, "^[ \t]+"), <crlf>, "|");
$items = <get SelectedItemsNames>;
$pattern = "([ ]|" . replace($remove, " ", "(_| )+") . ")";
foreach($item, $items, <crlf>, "e") {
if (regexmatches($items, $pattern)) {
$ext = gpc($item, "ext");
$base = gpc($item, "base");
$base = regexreplace($base, $pattern, " ");
$base = trim(regexreplace($base, "[ ]{2,}", " "));
// This could catch multiple dates, we'll only use the last found
$date = gettoken(regexmatches($base, "\b\d{4}\b"), -1, "|");
$new = $base . "." . $ext;
if ($date) { $new = gettoken($base, 1, $date, "t") . " " . $date . "." . $ext; }
if ($new UnLikeI $item) { renameitem($new, $item); }
}
}
hello sir,
i want to remove (2022) , (202x+192kbps), any thing between (), ...,any thing between [],Tam, Mal,Kan,Hin etc with above code. can you plsease add these in your code?
Re: Search and Replace, a chain of commands
Posted: 26 Jan 2023 05:02
by haaranoos
I love this script.
I use it every day without a problem.
I just wanted to change the code a bit to serve to rename versioning movies like:
Ginger_Snaps_2_Unleashed_2004_1080p_BrRip_YIFY.mp4
I think "_2" after Ginger_Snaps makes the script malfunction!
and the error is :
The new name "Ginger Snaps 2 Unleaseashed 2004.mp4 2|2004.mp4" contains invalid characters.
and of course, I don't know how to fix it in the code.

Re: Search and Replace, a chain of commands
Posted: 26 Jan 2023 07:49
by highend
I don't get an error message with that file name and the original script?
Re: Search and Replace, a chain of commands
Posted: 26 Jan 2023 08:05
by haaranoos
highend wrote: ↑26 Jan 2023 07:49
I don't get an error message with that file name and the original script?
My bad, my bad.
Sorry, I think something was wrong with copying the whole script, I did it right this time and It works flawlessly.
Thaaaaaaaaaaank you cheers
