Match name and add language suffix for subtitle

Discuss and share scripts and script files...
Post Reply
yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Match name and add language suffix for subtitle

Post by yusef88 »

I'd like to share a script helped me a lot

Code: Select all

"<get curitemprev base>"
    $base = RegExReplace("<get curitemprev base>", "(.ar|.en)$", "");
    $ext = get("curitem", "ext");
    $lang = (quicksearch("/contents=[أ-ي] /contflags=r /u", <curitem>)) ? "Arabic" : "English";
    if ("|srt|ass|ssa|sub|smi|sup|idx|" LikeI "*|$ext|*" AND <curitem> != "" AND <curitemprev> != "" AND $lang == Arabic)
    { rename b, "$base.ar"; }
    elseif ("|srt|ass|ssa|sub|smi|sup|idx|" LikeI "*|$ext|*" AND <curitem> != "" AND <curitemprev> != "" AND $lang == English)
    { rename b, "$base.en"; }
    elseif (<curitem> != "" AND <curitemprev> != "") { rename b, "$base"; }
    else { status "Missing selection", "FF0000", "alert"; }

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Match name and add language suffix for subtitle

Post by highend »

Why do you use all these duplicated conditions?
A ternary helps to remove complexity here...
Don't do string comparisons like this:

Code: Select all

$lang == English
Quote them (single or double)!

Your regex pattern is probably not what it seems to be (it matches e.g. "rar"...)

Code: Select all

"<get curitemprev base>"
    $base = regexreplace("<get curitemprev base>", "\.(ar|en)$");
    $ext = get("curitem", "ext");
    $lang = (quicksearch("/contents=[أ-ي] /contflags=r /u", <curitem>)) ? "Arabic" : "English";
    if !(<curitem> AND <curitemprev>) { status "Missing selection", "FF0000", "alert"; end 1==1; }
    if ("|srt|ass|ssa|sub|smi|sup|idx|" LikeI "*|$ext|*") {
        $newExt = ($lang == "English" ? ".en" : ($lang == "Arabic" ? ".ar" : ""));
    }
    rename b, "$base$newExt";
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Match name and add language suffix for subtitle

Post by yusef88 »

Thanks highend
here's an another approach (taken into consideration your modification) to change the name of movie and subtitles by clipboard

Code: Select all

"<clipboard>"
    $clp = regexreplace("<clipboard>", "\s+$", "");
    foreach($Token, get(SelectedItemsPathNames, "|")) {
        $ext = getpathcomponent($Token, "ext");
        $lang = (quicksearch("/contents=[ا-ي] /contflags=r /u", $Token)) ? "Arabic" : "English";
        if ("|srt|ass|ssa|sub|smi|sup|idx|" LikeI "*|$ext|*") {
        $newExt = ($lang == "English" ? ".en" : ($lang == "Arabic" ? ".ar" : "")); rename b, "$clp$newExt", , "$Token", "16"
        }
       elseif (<curitem> != "") { rename b, "$clp", , "$Token", "16" }
    }
Attachments
name.png
name.png (2.51 KiB) Viewed 874 times

Post Reply