Skip to main content
Participant
December 7, 2020
Answered

CEP ExtendScript Download from url

  • December 7, 2020
  • 1 reply
  • 2550 views

Is there an easy way in ExtendScript for Adobe Premiere 2020 to download a file from an https url?

 

Basically, doing:

 

function importFile(filePath) {
    app.project.importFiles([filePath],
        false, // suppress warnings 
        app.project.getInsertionBin(),
        false); // import as numbered stills
}

 

where `filePath` is a url (like https://example.com/video.mp4) instead of a local file.

 

Any help appreciated!

Cheers,

Damien

This topic has been closed for replies.
Correct answer Damien5E4D

Thanks @Bruce Bullis ; with your help I was able to achieve my goal!

There were a couple of gotchas, like remembering to enable Node.js in the manifest:

          <CEFCommandLine>
            <Parameter>--enable-nodejs</Parameter>
            <Parameter>--mixed-context</Parameter>
          </CEFCommandLine>

or using

const fs = cep_node.require('fs')

 instead of just

const fs = require('fs')

 

In the end, here is what I came up with, in case it helps anyone in the future:

export const importInPremiere = async ({ url, name }) => {
  /**
   * Initialize CSInterface
   */
  const { CSInterface } = require('@cep/csinterface')

  const csInterface = new CSInterface()

  /**
   * Create temporary directory
   */
  const tempFolder = '/tmp/adobe_cep_panel'

  window.cep.fs.makedir(tempFolder)

  const filePath = `${tempFolder}/${name}`

  /**
   * Open file
   */
  const fs = window.cep_node.require('fs')

  const file = fs.createWriteStream(filePath)

  /**
   * Fetch ressource as stream
   */
  const response = await fetch(url)

  const reader = response.body.getReader()

  while (true) {
    /**
     * Read stream chunks
     */
    const { value, done } = await reader.read()

    if (done) {
      /**
       * Close file
       */
      file.end()

      /**
       * Send file path to JSX for import into Premiere
       */
      csInterface.evalScript(`importFile("${filePath}")`)

      break
    }

    /**
     * Write stream chunks to file
     */
    file.write(value)
  }
}

1 reply

Bruce Bullis
Community Manager
Community Manager
December 8, 2020
Damien5E4DAuthorCorrect answer
Participant
December 10, 2020

Thanks @Bruce Bullis ; with your help I was able to achieve my goal!

There were a couple of gotchas, like remembering to enable Node.js in the manifest:

          <CEFCommandLine>
            <Parameter>--enable-nodejs</Parameter>
            <Parameter>--mixed-context</Parameter>
          </CEFCommandLine>

or using

const fs = cep_node.require('fs')

 instead of just

const fs = require('fs')

 

In the end, here is what I came up with, in case it helps anyone in the future:

export const importInPremiere = async ({ url, name }) => {
  /**
   * Initialize CSInterface
   */
  const { CSInterface } = require('@cep/csinterface')

  const csInterface = new CSInterface()

  /**
   * Create temporary directory
   */
  const tempFolder = '/tmp/adobe_cep_panel'

  window.cep.fs.makedir(tempFolder)

  const filePath = `${tempFolder}/${name}`

  /**
   * Open file
   */
  const fs = window.cep_node.require('fs')

  const file = fs.createWriteStream(filePath)

  /**
   * Fetch ressource as stream
   */
  const response = await fetch(url)

  const reader = response.body.getReader()

  while (true) {
    /**
     * Read stream chunks
     */
    const { value, done } = await reader.read()

    if (done) {
      /**
       * Close file
       */
      file.end()

      /**
       * Send file path to JSX for import into Premiere
       */
      csInterface.evalScript(`importFile("${filePath}")`)

      break
    }

    /**
     * Write stream chunks to file
     */
    file.write(value)
  }
}