api.video

Features

Documentation

Tutorials

Helpful PHP Scripts Pt 4: Update Metadata for api.video Videos Using CSV

February 10, 2021 - Erikka Innes

This script is part of a collection of scripts from Hervé Pita that help with bulk video uploads. Everything is available in our Helpful PHP Scripts repository on Github. In each part of this series, we'll walk through how to set up one of the scripts. What you'll find includes:

Today we're going to learn how to use the script for updating custom you choose using a CSV file. This will allow you to make updates in bulk, so be careful! With great power comes great responsibility.

Prerequisities

For this project you'll need:

  • PHP 5.4 or greater with the command-line interface (CLI) and JSON extension installed
  • The Composer dependency management tool (or another way to manage your dependency management). See the Composer website for installation options.
  • A GitHub account
  • An api.video account
  • Your API key for either production or sandbox (the script will update video metadata based on your API key - if you choose production your production videos are updated, if you choose sandbox, your sandbox videos are updated)

Installation

  1. Navigate to the Helpful PHP Scripts repository.
  2. Click Code and from the ddrop-down click Download ZIP. (You can also install from the CLI if you prefer.)
  3. Put the contents of your new .zip file in a folder you want to work from.
  4. Navigate to the folder containing the contents of your zip file in the terminal.
  5. In the terminal, type: composer require api-video/php-sdk

Prepare Your .csv File

You're going to need a .csv file containing the information you want to update. The script is designed to be flexible, so you can include any three fields for the columns after the first column, which you must label id. In this column you place your videoId. The script can handle legacy video IDs beginning 'vi' or the new ones beginning 'video_'. The next three columns can be the parameters you decide on. In this walkthrough, I picked title, description, and public. I can use these to set the title of my video, provide a description of the video, and choose whether it will be public or private.

Make sure the top of your file has the field headings, and they correspond to exactly how they are presented in the api.video API. If you need a refresher, check out docs.api.video to make sure you're setting up your file correctly.

Set up all the files you want to edit, one row per video file. Then save your file as .csv or .tsv. Hervé's script will accept either ending, but be aware that you MUST set up your file so that the separator is a tab, or the script won't run. The easiest way to do this is to save it as .tsv.

After you set up your file, place it in the same folder that you run your script from. The script will expect to be able to retrieve your file from this location.

NOTE: Double and triple check your rows! You don't want to accidentally upload mistake updates if you don't have to.

Try the Script

  1. In the terminal, type php update_metadata.php
  2. You're asked what environment you want to use, prod or sandbox. For our walkthrough, choose prod.
  3. Provide your API key when prompted. You can get this by navigating to my.api.video and copying the appropriate key.
  4. You're asked to provide the name of the file you want to use. Provide the full name of the file, including the ending.
  5. You're asked if you're ready to have your file checked to make sure it has the right headings. Put y.
  6. If all goes well, the metadata you provided is added! Go check your videos to see if they list the information you wanted to provide.

Thanks for checking out the latest installment of helpful PHP scripts for bulk video uploads!

Erikka Innes

Developer Evangelist

Get started now

Connect your users with videos