DurationAV (Duration columns for folders)

This add-in creates three custom columns: DurationAV, DurationAudio, and DurationVideo.

Like the built-in column duration, they display the length of audio and video files.

Unlike the built-in column, they also work for folders and display the sum of the duration of all files found inside the folder (non-recursively).

DurationAV is the sum of DurationAudio and DurationVideo.

To toggle the columns, use

Set COLUMNSTOGGLE="duration(!,a,0)"
Set COLUMNSTOGGLE="scp:DurationAV/DurationAV(!,a,0)"
Set COLUMNSTOGGLE="scp:DurationAV/DurationAudio(!,a,0)"
Set COLUMNSTOGGLE="scp:DurationAV/DurationVideo(!,a,0)"
function OnInit(initData) {
    initData.name = 'DurationAV';
    initData.version = '2022-11-05';
    initData.copyright = '';
    initData.url = 'https://resource.dopus.com/t/durationav-duration-columns-for-folders/42701';
    initData.desc = 'Display duration for folders.';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.name = 'DurationAV';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.multicol = true;

    var col = addColData.AddColumn();
    col.name = 'DurationAudio';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.multicol = true;

    var col = addColData.AddColumn();
    col.name = 'DurationVideo';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.multicol = true;
}

function OnColumn(scriptColData) {
    var item = scriptColData.item;

    var itemDurationAudio = 0;
    var itemDurationVideo = 0;

    if (item.is_dir) {
        var folderEnum = DOpus.FSUtil().ReadDir(item);
        while (!folderEnum.complete) {
            var folderItem = folderEnum.Next();
            var meta = folderItem.metadata;
            if (meta == 'audio') {
                var folderItemDuration = meta.audio.duration;
                if (typeof folderItemDuration == 'number') itemDurationAudio += folderItemDuration;
            } else if (meta == 'video') {
                var folderItemDuration = meta.video.duration;
                if (typeof folderItemDuration == 'number') itemDurationVideo += folderItemDuration;
            }
        }
        folderEnum.Close();
    } else {
        var meta = item.metadata;
        if (meta == 'audio') {
            itemDurationAudio = meta.audio.duration;
            if (typeof itemDurationAudio != 'number') itemDurationAudio = 0;
        } else if (meta == 'video') {
            itemDurationVideo = meta.video.duration;
            if (typeof itemDurationVideo != 'number') itemDurationVideo = 0;
        }
    }

    var itemDurationAV = itemDurationAudio + itemDurationVideo;

    var itemDurationDateAV = DOpus.Create().Date(0);
    itemDurationDateAV.Add(itemDurationAV, 's');
    scriptColData.columns('DurationAV').value = itemDurationDateAV.Format('T#HH:mm:ss');

    var itemDurationDateAudio = DOpus.Create().Date(0);
    itemDurationDateAudio.Add(itemDurationAudio, 's');
    scriptColData.columns('DurationAudio').value = itemDurationDateAudio.Format('T#HH:mm:ss');

    var itemDurationDateVideo = DOpus.Create().Date(0);
    itemDurationDateVideo.Add(itemDurationVideo, 's');
    scriptColData.columns('DurationVideo').value = itemDurationDateVideo.Format('T#HH:mm:ss');
}

ColumnDurationAV.js.txt (2.7 KB)


6 Likes