<commit_before>/*
    @author <NAME>
    @component CmdFiles
*/

screens.cmd.files = function CmdFiles(me, packages) {
    const { core } = packages;
    me.cmd = async function (terminal, args) {
        if (args.length === 1) {
            args.push(...["/Kab/concepts/private/american", "cache"]);
        }
        if (args.length <= 2) {
            core.property.set(terminal, "print", "files source target");
            core.cmd.exit(terminal);
            return;
        }
        var source = args[1];
        var target = args[2];
        core.property.set(terminal, "print", "converting files in " + source);
        try {
            var children = await me.storage.dropbox.getChildren(source);
            var audioList = children.filter(child => core.path.extension(child.name) === "m4a");
            var videoList = children.filter(child => core.path.extension(child.name) === "mp4");
            for (let videoChild of videoList) {
                try {
                    var name = core.path.fileName(videoChild.name);
                    var matching = audioList.find(child => core.path.fileName(child.name) === name);
                    if (matching) {
                        continue;
                    }
                    var targetVideoPath = target + "/" + videoChild.name;
                    var targetAudioPath = core.path.replaceExtension(target + "/" + videoChild.name, "m4a");
                    core.property.set(terminal, "print", videoChild.path_display);
                    core.property.set(terminal, "print", "Downloading...");
                    await me.manager.file.download(videoChild.path_lower, targetVideoPath);
                    if (!await core.file.exists(targetAudioPath)) {
                        core.property.set(terminal, "print", "Converting...");
                        await me.media.ffmpeg.convert(targetVideoPath, targetAudioPath, {
                            noVideo: null,
                            audioCodec: "copy"
                        });
                        var fileSize = await core.file.size(targetAudioPath);
                        core.property.set(terminal, "print", "converted from: " + core.string.formatBytes(videoChild.size) + " to: " + core.string.formatBytes(fileSize));
                    }
                    var uploadAudioPath = core.path.replaceExtension(videoChild.path_display, "m4a");
                    core.property.set(terminal, "print", "Uploading...");
                    await me.manager.file.upload(targetAudioPath, uploadAudioPath);
                    await core.file.delete(targetVideoPath);
                }
                catch (err) {
                    core.property.set(terminal, "print", "failed to convert file: " + err);
                }
            }
            core.property.set(terminal, "print", "successfully converted files");
        }
        catch (err) {
            core.property.set(terminal, "print", "failed to convert files: " + err);
        }
        core.cmd.exit(terminal);
    };
};<commit_msg>bug fixes<commit_after>/*
    @author <NAME>
    @component CmdFiles
*/

screens.cmd.files = function CmdFiles(me, packages) {
    const { core, media, storage } = packages;
    me.cmd = async function (terminal, args) {
        if (args.length <= 1) {
            core.property.set(terminal, "print", "files resolution");
            core.cmd.exit(terminal);
            return;
        }
        var resolution = args[1];
        core.property.set(terminal, "print", "converting video files to resolution:" + resolution);
        try {
            var groups = await media.file.groups();
            for (let group of groups) {
                var list = group.sessions.filter(session => session.extension === "mp4");
                for (let item of list) {
                    var remote = "screens/" + group.name + "/" + item.session + ".mp4";
                    var local = "cache/" + item.session + ".mp4";
                    var local_convert = "cache/" + item.session + "_" + resolution + ".mp4";
                    var remote_convert = "screens/" + group.name + "/" + item.session + "_" + resolution + ".mp4";
                    var exists = await storage.aws.exists(remote_convert);
                    if (exists) {
                        continue;
                    }
                    core.property.set(terminal, "print", "downloading: " + remote + " to: " + local);
                    await storage.aws.downloadFile(remote, local);
                    core.property.set(terminal, "print", "converting: " + local + " to: " + local_convert);
                    await media.ffmpeg.convert(local, local_convert, {
                        size: resolution
                    });
                    core.property.set(terminal, "print", "uploading: " + local_convert + " to: " + remote_convert);
                    await storage.aws.uploadFile(local_convert, remote_convert);
                    core.property.set(terminal, "print", "deleting: " + local_convert);
                    await core.file.delete(local_convert);
                    core.property.set(terminal, "print", "finished: " + item.name);
                }
            }
            core.property.set(terminal, "print", "successfully converted and uploaded files");
        }
        catch (err) {
            core.property.set(terminal, "print", "failed to convert files: " + err);
        }
        core.cmd.exit(terminal);
    };
};
{'fraction_non_alphanumeric': 0.12986301369863013, 'fraction_numerical': 0.0027397260273972603, 'mean_word_length': 1.655674102812803, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2542158', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1407, 'n_words': 301}