Exporting the project directory from Premier Pro using Extendscript

By Christopher Talke Buscaino at

Premier Pro & Extendscript

Adobe Premier Pro is a powerful video editing tool used by professionals around the world. It has many features that allow users to create stunning videos, but one limitation is the inability to easily export the project directory. This is where Extendscript comes in.

Extendscript is a scripting language that allows users to automate tasks and add functionality to Adobe applications. With Extendscript, you can create scripts that can export the project directory from Premier Pro into JSON or CSV formats. This can be incredibly useful for organizing your project and making it easier to work with.

Getting Started

To get started, you will need to have Adobe Premier Pro installed on your computer. You will also need to have some basic knowledge of JavaScript, as Extendscript is based on this language.

First, open Adobe Premier Pro and create a new project. Then, open VS Code and install the Extendscript plugin. Start by creating a new script file and saving it with a descriptive name (e.g. project-export.tsx).

Next, you will need to write the script that will export the project directory.

The Script

This script will loop through all the project items recursively and store their name, type, and file path in an object. It will then convert the object to a JSON string and save it to a file.

// Instantiate the project
var project = app.project

// Setups for the CSV Export, and also a fileType map to convert the Adobe values into human-friendly language.
var csvOutput = ['id,"parent","name",type'];
var fileType = ["", "File", "Bin", "Sequence"];

// Setup variables for a progress percentage
var totalChildren = 0;
var childrenProcessed = 0;
var currentPercentage = 0;

function exportDir(parentname, children) {
    
    // Updates the global variables for the progress percentage
    totalChildren = totalChildren + children.length 

    // We instantiate an array which will be populated into a tree like json structure
    var newChildren = [];

    // We iterate over the projects children
    for (var i = 0, len = children.length; i < len; i++) {
        childrenProcessed = childrenProcessed + 1

        // Get all teh values from the childfile being processed
        var child = children[i];
        var newParent = {};
        newParent.id = child.nodeId;
        newParent.parent = parentname;
        newParent.name = child.name;
        newParent.type = fileType[child.type];

        // Sequences arn't included in the '.type' value, so this will ensure we can parse it in the export.
        if (child.isSequence()) {
            newParent.type = fileType[3];
        }

        // Update the progress percentage, and write this to the console
        var newPercentage = (childrenProcessed / totalChildren) * 100
        if (newPercentage > currentPercentage) {
            currentPercentage = newPercentage;
            $.writeln("Processing: " + currentPercentage.toFixed(2) + "%")
        }
    
        // If the child we are processing has children (i.e. its a folder) 
        // Do some recursion, and process those children too...
        if (child.children !== undefined && child.children.length) {
            newParent.children = exportDir(child.name, child.children)
        } 

        // Add values to both the CSV Export and the JSON Export.
        csvOutput.push(newParent.id + ',"' + newParent.parent + '","' + newParent.name + '",' + newParent.type)
        newChildren.push(newParent);
    };

    return newChildren;
}

// Starts the export
var JSONresults = exportDir(project.name, project.rootItem.children);

var scriptFolderPath = File($.fileName).path; // the URI of the folder that contains the script file    
var exportFolderPath = scriptFolderPath + encodeURI("/output"); // the URI of the folder for your script resources    
var jsonFile = new File(exportFolderPath + encodeURI("/output.json"));
var content = JSON.stringify(JSONresults, null, 2);
writeFile(jsonFile, content);
    
var CSVresults = csvOutput.join('\r\n');
var csvFile = new File(exportFolderPath + encodeURI("/output.csv"));
writeFile(csvFile, CSVresults);

// A function to write the file to the file system.
function writeFile(fileObj, fileContent, encoding) {
    encoding = encoding || "utf-8";
    fileObj = (fileObj instanceof File) ? fileObj : new File(fileObj);
    var parentFolder = fileObj.parent;

    if (!parentFolder.exists && !parentFolder.create()) {
        throw new Error("Cannot create file in path " + fileObj.fsName);
    }

    fileObj.encoding = encoding;
    fileObj.open("w");
    fileObj.write(fileContent);
    fileObj.close();

    return fileObj;
}

Summary

In summary, ExtendScript is a powerful scripting language that can be used to automate and extend the functionality of Adobe applications, including Premiere Pro.

By using ExtendScript, you now know how to easily export a project directory from Premiere Pro, which can be useful for backing up or sharing your project with others. Whether you are a professional video editor or a beginner, ExtendScript can help you streamline your workflows and save time and effort. By learning how to use ExtendScript, you can unlock the full potential of Premiere Pro and take your video editing skills to the next level.