Video files are sorted by length in wrong order

Things you’d like to miss in the future...
Post Reply
luoruiming
Posts: 1
Joined: 08 Oct 2021 08:36

Video files are sorted by length in wrong order

Post by luoruiming »

Video files are sorted by length in wrong order. For example, when sorted by length, a 2-hour video display is shorter than a 3-minute video display.
Attachments
Snipaste_2021-10-08_14-59-40.png
Snipaste_2021-10-08_14-59-40.png (9.32 KiB) Viewed 263 times

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

Re: Video files are sorted by length in wrong order

Post by highend »

XY is not aware of what kind of data is returned by that video length property and doesn't know how to sort it correctly

Use a custom column with a script instead. That should be sortable (at least for videos not larger than 24 hours)

Code: Select all

    $nsecs = property("System.Media.Duration", <cc_item>);

    // To get real seconds from nanoseconds
    $secs = round($nsecs * 0.0000001);

    $hours = $secs / 3600;
    if ($hours >= 1) {
        $hours = format(regexmatches($hours, "^\d+"), "00");
        $secs  = $secs - $hours * 3600;
    } else { $hours = "00"; }

    $mins = $secs / 60;
    if ($mins >= 1) {
        $mins = format(regexmatches($mins, "^\d+"), "00");
        $secs = $secs - $mins * 60;
    } else { $mins = "00"; }

    return $hours . ":" . $mins . ":" . format($secs, "00");
One of my scripts helped you out? Please donate via Paypal

Post Reply