We're using a modified version of the Brightcove Video Cloud WordPress plug-in to use a new post type in our WordPress site called Video (the post type tag is bc-video). Our workflow is pretty simple - we ask that our video production staff upload new video content into Brightcove at https://studio.brightcove.com/ , and set the video's title, description and tags (more on that in a minute) before marking the video as active.
Once a video is active, it's eligible for the PHP script we have running on one of our webservers to see and create a Video post in WordPress out of. We have a tiny Bash script called cron_brightcove.sh that simply contains these lines:
#!/bin/sh
cd /app/cflca/public/wp-content/plugins/brightcove-video-cloud/cmd/
php brightcove_import.php www.cfl.ca lang=en 0
The file cron_brightcove.sh, which is scheduled to be run every 2 minutes by the cron scheduler, simply changes directory to where the file brightcove_import.php is found, and then executes it as a PHP script at the command line. The three parameters passed are there because we have a multi-site setup, but I'll explain them quickly:
- www.cfl.ca is the site we're executing the video import on. We also pass www.lcf.ca, www.argonauts.ca, and so on separately.
- lang=en is to make sure the importer script only creates Video posts on www.cfl.ca from English videos (using tags to determine this)
- 0 is the page number to look for videos at; we can retrieve a maximum of 20 videos at a time, so occasionally we use the page number if something has screwed up and we need to catch up on older videos
Let's take a look at brightcove_import.php itself now. A lot of its code is simply to ensure that multiple simultaneous executions of this import script don't occur, so I'll skip over that. Line 46 through 228 are the core of the importer. Some notes on those lines:
Line 47: We retrieve the value of the Brightcove API key saved in WordPress so we can authenticate ourselves to get data from our account.
Line 64 - 71: The parameters we pass to the API, which boil down to asking for the 20 most recent active ("playable") videos from the last time we did an import (if it's the first time, it'll pass 0, which works).
Line 77 - 86: You should probably delete these; we have editors tagging videos as lang=en or lang=fr for the various languages video content can be found in our accounts, but you won't need that.
Line 89 - 90: Retrieve the comma delimited list of fields to retrieve about each video found. Your list should be:
id,name,adKeys,shortDescription,longDescription,creationDate,publishedDate,lastModifiedDate,linkURL,linkText,tags,videoStillURL,thumbnailURL,referenceId,length,economics,playsTotal,playsTrailingWeek,FLVURL,renditions,FLVFullLength,videoFullLength
Line 93: Actually call the Brightcove "Search" API with our parameters.
Line 109 - 230: Loop through the list of videos, creating new videos where they don't exist and checking to see if updates need to be made on videos that already exist in WordPress.
Line 185 - 225: If the video has been tagged with a section=something tag in Brightcove, see if there is a Video Category in WordPress with that same value. If there is, categorize the Video in WordPress to that Video Category. (This way video producers basically never need to open/use WordPress.)