Skip to content

Commit 1480f97

Browse files
author
Joe Cabrera
committed
merging #31
2 parents b5995de + a2b4769 commit 1480f97

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ If you are developing a web application and would like to have the users upload
8181
6. When the user comes back to the redirect_url, you will have an additional query param (to any you may have included) called `video_uri`. This can be used to load and edit the newly created clip via the standard API methods.
8282
7.
8383

84+
#### Replacing video source file
85+
86+
If you want to replace the video source file of an existing video, you should follow these steps:
87+
88+
1. Initialize a `Vimeo` class to interact with the server with the proper credentials. \*
89+
2. With the path to your file and video uri, call `$vimeo->replace($video_uri, $file_name);`.
90+
3. The response from that function will contain a `Location` header with the URI to the newly created resource. You can call that to set metadata such as the title or check on the transcode status.
91+
92+
8493
#### Uploading an image
8594
Uploading an image can only occur by PUTing the file to the Vimeo servers
8695

vimeo.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Vimeo
2525
const AUTH_ENDPOINT = 'https://api.vimeo.com/oauth/authorize';
2626
const ACCESS_TOKEN_ENDPOINT = '/oauth/access_token';
2727
const CLIENT_CREDENTIALS_TOKEN_ENDPOINT = '/oauth/authorize/client';
28+
const REPLACE_ENDPOINT = '/files';
2829
const VERSION_STRING = 'application/vnd.vimeo.*+json; version=3.2';
2930
const USER_AGENT = 'vimeo.php 1.0; (http://developer.vimeo.com/api/docs)';
3031

@@ -269,20 +270,62 @@ public function buildAuthorizationEndpoint ($redirect_uri, $scope = 'public', $s
269270
* This should be used to upload a local file. If you want a form for your site to upload direct to Vimeo, you should look at the POST /me/videos endpoint.
270271
*
271272
* @param string $file_path Path to the video file to upload.
273+
* @param boolean $upgrade_to_1080 Should we automatically upgrade the video file to 1080p
272274
* @return array Status
273275
*/
274-
public function upload ($file_path, $machine_id = null) {
276+
public function upload ($file_path, $upgrade_to_1080 = false, $machine_id = null)
277+
{
275278
// Validate that our file is real.
276279
if (!is_file($file_path)) {
277280
throw new VimeoUploadException('Unable to locate file to upload.');
278281
}
279282

280283
// Begin the upload request by getting a ticket
281-
$ticket_args = array('type' => 'streaming');
284+
$ticket_args = array('type' => 'streaming', 'upgrade_to_1080' => $upgrade_to_1080);
282285
if ($machine_id !== null) {
283286
$ticket_args['machine_id'] = $machine_id;
284287
}
285288
$ticket = $this->request('/me/videos', $ticket_args, 'POST');
289+
290+
return $this->perform_upload($file_path, $ticket);
291+
}
292+
293+
/**
294+
* Replace the source of a single Vimeo video
295+
*
296+
* @param string $video_uri Video uri of the video file to replace.
297+
* @param string $file_path Path to the video file to upload.
298+
* @param boolean $upgrade_to_1080 Should we automatically upgrade the video file to 1080p
299+
* @return array Status
300+
*/
301+
public function replace ($video_uri, $file_path, $upgrade_to_1080 = false, $machine_id = null)
302+
{
303+
// Validate that our file is real.
304+
if (!is_file($file_path)) {
305+
throw new VimeoUploadException('Unable to locate file to upload.');
306+
}
307+
308+
$uri = $video_uri . self::REPLACE_ENDPOINT;
309+
310+
// Begin the upload request by getting a ticket
311+
$ticket_args = array('type' => 'streaming', 'upgrade_to_1080' => $upgrade_to_1080);
312+
if ($machine_id !== null) {
313+
$ticket_args['machine_id'] = $machine_id;
314+
}
315+
$ticket = $this->request($uri, $ticket_args, 'PUT');
316+
317+
return $this->perform_upload($file_path, $ticket);
318+
}
319+
320+
/**
321+
* Take an upload ticket and perform the actual upload
322+
*
323+
* @param string $filename Path to the video file to upload.
324+
* @param Ticket $ticket Upload ticket data.
325+
* @return array Status
326+
*/
327+
private function perform_upload($file_path, $ticket)
328+
{
286329
if ($ticket['status'] != 201) {
287330
throw new VimeoUploadException('Unable to get an upload ticket.');
288331
}

0 commit comments

Comments
 (0)