Skip to content

Commit

Permalink
added protocol parameter to get_stream_url
Browse files Browse the repository at this point in the history
  • Loading branch information
jererc committed Jan 12, 2012
1 parent 3763e69 commit e57415a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CloudKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public function get_stream_url($args)
$version = '';
$download = false;
$filename = '';
$protocol = null;
extract($args);
if (!in_array($protocol, array(null, "hls", "rtmp", "hps", "http"))) {
throw new CloudKey_InvalidMethodException(sprintf('%s is not a valid streaming protocol', $protocol));
}
if ($extension == '')
{
$parts = explode('_', $asset_name);
Expand All @@ -96,7 +100,9 @@ public function get_stream_url($args)
}
else
{
$protocol = ($download or $filename) ? 'http' : null;
if ($download or $filename) {
$protocol = 'http';
}
$url = sprintf('%s/route%s/%s/%s/%s%s%s', $this->cdn_url, $protocol ? "/$protocol" : '', $this->user_id, $id, $asset_name, $version, $extension != '' ? ".$extension" : '');
if ($filename)
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Arguments:
- `filename`: the download url filename (overrides the `download` parameter if set).
- `version`: arbitrary integer inserted in the url for the cache flush.
Use this parameter only if needed, and change its value only when a cache flush is required.
- `protocol`: streaming protocol ('hls', 'rtmp', 'hps' or 'http'). Overrides the `download` parameter if 'http'.

The following arguments may be required if the `CLOUDKEY_SECLEVEL_DELEGATE` option is not specified in
the seclevel parameter, depending on the other options. This is not recommanded as it would probably
Expand Down
35 changes: 35 additions & 0 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,39 @@ public function testGetStreamUrl_no_filename_no_download()
$this->assertContains($res_test, $res);
}

/**
* @expectedException CloudKey_InvalidMethodException
*/
public function testGetStreamUrl_bad_protocol()
{
global $user_id, $api_key, $base_url;

$file = $this->cloudkey->file->upload_file('.fixtures/video.3gp');
$assets = array('mp4_h264_aac', 'jpeg_thumbnail_medium');
$media = $this->cloudkey->media->create(array('assets_names' => $assets, 'url' => $file->url));

$protocol = 'bad';

$res = $this->cloudkey->media->get_stream_url(array('id' => $media->id, 'asset_name' => 'mp4_h264_aac', 'protocol' => $protocol));
}

public function testGetStreamUrl_protocol_http()
{
global $user_id, $api_key, $base_url;

$file = $this->cloudkey->file->upload_file('.fixtures/video.3gp');
$assets = array('mp4_h264_aac', 'jpeg_thumbnail_medium');
$media = $this->cloudkey->media->create(array('assets_names' => $assets, 'url' => $file->url));

$protocol = 'http';

$res = $this->cloudkey->media->get_stream_url(array('id' => $media->id, 'asset_name' => 'jpeg_thumbnail_medium', 'protocol' => $protocol));
$res_test = sprintf('http://static.dmcloud.net/%s/%s/jpeg_thumbnail_medium.jpeg', $user_id, $media->id);
$this->assertEquals($res, $res_test);

$res = $this->cloudkey->media->get_stream_url(array('id' => $media->id, 'asset_name' => 'mp4_h264_aac', 'protocol' => $protocol));
$res_test = sprintf('/route/%s/%s/%s/mp4_h264_aac.mp4?', $protocol, $user_id, $media->id);
$this->assertContains($res_test, $res);
}

}

0 comments on commit e57415a

Please sign in to comment.