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:
- Ingest Videos from Google Drive - You can transfer all your videos from a folder in Google Drive to your api.video account with this CLI script.
- Ingest Videos from an FTP Server - Transfer all your videos from the FTP server of your choice to your api.video account.
- Export All Your Video Data to .csv - With this script you can grab details about each video in your api.video account and gather it in one .csv spreadsheet.
- Update Metadata for api.video Videos Using CSV - You can update your metadata in bulk with this script.
- Update Video Settings in Bulk Without a CSV File - Update videos to all be public or private or offer an mp4 download or disable an mp4 download.
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.
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)
- Navigate to the Helpful PHP Scripts repository.
- Click Code and from the ddrop-down click Download ZIP. (You can also install from the CLI if you prefer.)
- Put the contents of your new .zip file in a folder you want to work from.
- Navigate to the folder containing the contents of your zip file in the terminal.
- 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
- In the terminal, type
- You're asked what environment you want to use, prod or sandbox. For our walkthrough, choose prod.
- Provide your API key when prompted. You can get this by navigating to my.api.video and copying the appropriate key.
- You're asked to provide the name of the file you want to use. Provide the full name of the file, including the ending.
- You're asked if you're ready to have your file checked to make sure it has the right headings. Put y.
- 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!