Search and Replace, a chain of commands

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Search and Replace, a chain of commands

Post 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

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Search and Replace, a chain of commands

Post by highend »

Only by scripting it
One of my scripts helped you out? Please donate via Paypal

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post by haaranoos »

would you please let me know how? :D

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Search and Replace, a chain of commands

Post by highend »

Post full original file names
One of my scripts helped you out? Please donate via Paypal

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post by haaranoos »

Aww thank you:

Deadstream_2022_1080p_WEB-DL_YIFY_30NAMA.mp4

I want it to be like :
Deadstream 2022.mp4

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Search and Replace, a chain of commands

Post 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?
One of my scripts helped you out? Please donate via Paypal

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post 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

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post by haaranoos »

|t is perfect :beer:
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

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Search and Replace, a chain of commands

Post 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); }
        }
    }
One of my scripts helped you out? Please donate via Paypal

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post by haaranoos »

Coooooooool :appl: :appl: :appl: :appl:
doing exactly what I wanted.
Thank youuuuuu

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: Search and Replace, a chain of commands

Post 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?

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post 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. :oops:

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Search and Replace, a chain of commands

Post by highend »

I don't get an error message with that file name and the original script?
One of my scripts helped you out? Please donate via Paypal

haaranoos
Posts: 13
Joined: 29 Apr 2017 11:53

Re: Search and Replace, a chain of commands

Post 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 :beer:

Post Reply