Skip to content

Commit

Permalink
Adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrooks committed Feb 16, 2017
1 parent a2a8f14 commit b844163
Show file tree
Hide file tree
Showing 4 changed files with 628 additions and 1 deletion.
49 changes: 48 additions & 1 deletion README.md
@@ -1 +1,48 @@
# Brightcove-Playback-API-Wrapper
# Brightcove Playback API Wrapper

This is a PHP wrapper for the [Brightcove Playback API](https://docs.brightcove.com/en/video-cloud/playback-api/)

## Getting Started

Add files to project folder.

In get-brighcove-media.php replace the policy token and account number when the class is instantiated

To obtain policy key see this doc: http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/policy-key.html
or use the web app to get one directly from the Policy API: http://docs.brightcove.com/en/video-cloud/policy-api/getting-started/quick-start.html#Set_policy_app

File caching layer is activated by adding require_once('bc-papi-cache.php') to get-brightcove-media.php

Access api as follows (e.g. files placed in folder named brightcove-playback-api):

```
require_once($_SERVER['DOCUMENT_ROOT'] . '/brightcove-playback-api/get-brightcove-media.php');
//find video by video id
$videoid = 12345;
$video = $bc->find('find_video_by_id', 'videos', $videoid);
// e.g. get video poster and display
echo '<img src="' . $video->poster . '" />';
//find video by reference id
$refid = ref123;
$video = $bc->find('find_video_by_reference_id', 'videos', $ref123);
//find playlist by video id
$videoid = 54321;
$playlist = $bc->find('find_playlist_by_id', 'playlists', $54321);
echo '<img src="' . $playlist->videos[0]->poster . '" />';
//find playlist by reference id
$refid = ref321;
$playlist = $bc->find('find_playlist_by_reference_id', 'playlists', $ref321);
```


## Authors

* **Theresa Newman** - *Initial work* - [Brightcove-Playback-API-Wrapper](https://github.com/theresaweb/Brightcove-Playback-API-Wrapper)

## Acknowledgments

* Based on the PHP Wrapper for the Media API which is being deprecated (https://github.com/BrightcoveOS/PHP-MAPI-Wrapper)
145 changes: 145 additions & 0 deletions bc-papi-cache.php
@@ -0,0 +1,145 @@
<?php

/**
* Brightcove PHP Playback API Caching Layer 1.0.0 (12 OCTOBER 2010)
*
* REFERENCES:
* derived from Deprecated PHP Media API wrapper
*
* AUTHORS:
* Matthew Congrove <mcongrove@brightcove.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the �Software�),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, alter, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, subject to the following conditions:
*
* 1. The permission granted herein does not extend to commercial use of
* the Software by entities primarily engaged in providing online video and
* related services.
*
* 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, SUITABILITY, TITLE,
* NONINFRINGEMENT, OR THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE, INABILITY TO USE, OR OTHER DEALINGS IN THE SOFTWARE.
*
* 3. NONE OF THE AUTHORS, CONTRIBUTORS, NOR BRIGHTCOVE SHALL BE RESPONSIBLE
* IN ANY MANNER FOR USE OF THE SOFTWARE. THE SOFTWARE IS PROVIDED FOR YOUR
* CONVENIENCE AND ANY USE IS SOLELY AT YOUR OWN RISK. NO MAINTENANCE AND/OR
* SUPPORT OF ANY KIND IS PROVIDED FOR THE SOFTWARE.
*/

class BCPAPICache
{
public static $extension = NULL;
public static $location = NULL;
public static $memcached = NULL;
public static $port = NULL;
public static $time = 0;
public static $type = NULL;

/**
* The constructor for the BCMAPICache class.
* @access Public
* @since 1.0.0
* @param string [$type] The type of caching method to use, either 'file' or 'memcached'
* @param int [$time] How many seconds until cache files are considered cold
* @param string [$location] The absolute path of the cache directory (file) or host (memcached)
* @param string [$extension] The file extension for cache items (file only)
* @param int [$port] The port to use (Memcached only)
*/
public function __construct($type = 'file', $time = 600, $location, $extension = '.c', $port = 11211)
{

if(strtolower($type) == 'file')
{
$type = 'file';
} else if(strtolower($type) == 'memcache' || strtolower($type) == 'memcached') {
$type = 'memcached';

$memcached = new Memcached();
$memcached->addServer($location, $port);

self::$memcached = $memcached;
} else {
$type = FALSE;
}

self::$extension = $extension;
self::$location = $location;
self::$port = $port;
self::$time = $time;
self::$type = $type;
if (!is_dir(self::$location)) {
mkdir(self::$location);
}
}

/**
* Retrieves any valid cached data.
* @access Public
* @since 1.0.1
* @param string [$key] The cache file key
* @return mixed The cached data if valid, otherwise FALSE
*/
public static function get($key)
{
if(self::$type == 'file')
{
$file = self::$location . md5($key) . self::$extension;

if(file_exists($file) && is_readable($file))
{
if((time() - filemtime($file)) <= self::$time)
{
return file_get_contents($file);
}
}

return FALSE;
} else if(self::$type == 'memcached') {
$data = self::$memcached->get($key);

if(self::$memcached->getResultCode() == Memcached::RES_SUCCESS)
{
return $data;
}
} else {
return FALSE;
}
}

/**
* Creates a cache of data.
* @access Public
* @since 1.0.0
* @param string [$key] The cache file key
* @param mixed [$data] The data to cache
*/
public static function set($key, $data)
{
if(self::$type == 'file')
{
$file = self::$location . md5($key) . self::$extension;

if(is_writable(self::$location))
{
$handle = fopen($file, 'w');
fwrite($handle, json_encode($data));
fclose($handle);
}
} else if(self::$type == 'memcached') {
self::$memcached->set($key, $data, time() + self::$time);
} else {
return FALSE;
}
}
}

?>

0 comments on commit b844163

Please sign in to comment.