Page 1 of 1

Match name and add language suffix for subtitle

Posted: 03 Apr 2017 16:43
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"; }

Re: Match name and add language suffix for subtitle

Posted: 03 Apr 2017 18:56
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";

Re: Match name and add language suffix for subtitle

Posted: 03 Apr 2017 22:39
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" }
    }