Skip to content

Commit

Permalink
Update generation, add new FPS settings (#21)
Browse files Browse the repository at this point in the history
* Update api generator version, whitespace fixes.
* First pass generator check.
* Second pass generator check.
* Update FPS notes.
* Remove default FPS.
* Turn off language deprecation warnings.
* Note PHP and Guzzle versions.
  • Loading branch information
Dean Fogarty authored Mar 12, 2022
1 parent aa6cfb4 commit 47c00c3
Show file tree
Hide file tree
Showing 45 changed files with 317 additions and 392 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For examples of how to use the SDK to create videos using code checkout the PHP

## Contents <!-- omit in toc -->
- [Using the PHP SDK](#using-the-php-sdk)
- [Requirements](#requirements)
- [Installation](#installation)
- [Video Editing](#video-editing)
- [Video Editing Example](#video-editing-example)
Expand Down Expand Up @@ -64,6 +65,10 @@ For examples of how to use the SDK to create videos using code checkout the PHP
- [API Documentation and Guides](#api-documentation-and-guides)

# Using the PHP SDK
### Requirements

Requires PHP7.3+ and uses Guzzle7.3+.

### Installation

The recommended way to use the SDK is as a composer package. Install using the command:
Expand Down Expand Up @@ -734,7 +739,7 @@ setFormat(string $format) | The output format and type of media file to generate
setResolution(string $resolution) | The output resolution of the video or image. <ul><li>`preview` - 512px x 288px @ 15fps</li><li>`mobile` - 640px x 360px @ 25fps</li><li>`sd` - 1024px x 576px @ 25fps</li><li>`hd` - 1280px x 720px @ 25fps</li><li>`1080` - 1920px x 1080px @ 25fps</li></ul> | -
setAspectRatio(string $aspectRatio) | The aspect ratio (shape) of the video or image. Useful for social media output formats. Options are: <ul><li>`16:9` - regular landscape/horizontal aspect ratio (default)</li><li>`9:16` - vertical/portrait aspect ratio</li><li>`1:1` - square aspect ratio</li><li>`4:5` - short vertical/portrait aspect ratio</li><li>`4:3` - legacy TV aspect ratio</li></ul> | -
setSize([\Shotstack\Client\Model\Size](#size) $size) | Set a custom size for a video or image. When using a custom size omit the `resolution` and `aspectRatio`. Custom sizes must be divisible by 2 based on the encoder specifications. | -
setFps(int $fps) | Override the default frames per second. Useful for when the source footage is recorded at 30fps, i.e. on mobile devices. Lower frame rates can be used to add cinematic quality (24fps) or to create smaller file size/faster render times or animated gifs (12 or 15fps). Default is 25fps. <ul><li>`12` - 12fps</li><li>`15` - 15fps</li><li>`24` - 24fps</li><li>`25` - 25fps</li><li>`30` - 30fps</li></ul> | -
setFps(float $fps) | Override the default frames per second. Useful for when the source footage is recorded at 30fps, i.e. on mobile devices. Lower frame rates can be used to add cinematic quality (24fps) or to create smaller file size/faster render times or animated gifs (12 or 15fps). Default is 25fps. <ul><li>`12` - 12fps</li><li>`15` - 15fps</li><li>`23.976` - 23.976fps</li><li>`24` - 24fps</li><li>`25` - 25fps</li><li>`29.97` - 29.97fps</li><li>`30` - 30fps</li></ul> | -
setScaleTo(string $scaleTo) | Override the resolution and scale the video or image to render at a different size. When using scaleTo the asset should be edited at the resolution dimensions, i.e. use font sizes that look best at HD, then use scaleTo to output the file at SD and the text will be scaled to the correct size. This is useful if you want to create multiple asset sizes. <ul><li>`preview` - 512px x 288px @ 15fps</li><li>`mobile` - 640px x 360px @ 25fps</li><li>`sd` - 1024px x 576px @25fps</li><li>`hd` - 1280px x 720px @25fps</li><li>`1080` - 1920px x 1080px @25fps</li></ul> | -
setQuality(string $quality) | Adjust the output quality of the video, image or audio. Adjusting quality affects render speed, download speeds and storage requirements due to file size. The default `medium` provides the most optimized choice for all three factors. <ul><li>`low` - slightly reduced quality, smaller file size</li><li>`medium` - optimized quality, render speeds and file size</li><li>`high` - slightly increased quality, larger file size</li></ul> | -
setRepeat(bool $repeat) | Loop settings for gif files. Set to `true` to loop, `false` to play only once. [default to `true`] | -
Expand Down Expand Up @@ -1104,4 +1109,4 @@ getUpdated(): string | The time the asset status was last updated. | -
- [Getting Started Guide](https://shotstack.io/docs/guide/getting-started/core-concepts/)
- [API Reference](https://shotstack.io/docs/api/)
- [Examples](https://github.com/shotstack/php-demos)
- [Shotstack Website](https://shotstack.io)
- [Shotstack Website](https://shotstack.io)
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
"minimum-stability": "dev",
"keywords": ["shotstack", "video", "video editing", "api"],
"require": {
"php": ">=7.2",
"php": "^7.3 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "7.2.0"
"guzzlehttp/guzzle": "^7.3",
"guzzlehttp/psr7": "^1.7 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^2.12"
},
"autoload": {
"psr-4": { "Shotstack\\Client\\" : "src/" }
Expand Down
112 changes: 63 additions & 49 deletions src/Api/EditApi.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* EditApi
* PHP version 7.2
* PHP version 7.3
*
* @category Class
* @package Shotstack\Client
Expand All @@ -15,9 +15,8 @@
* Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation. There are two main API's, one for editing and generating assets (Edit API) and one for managing hosted assets (Serve API). The Edit API base URL is: <b>https://api.shotstack.io/{version}</b> The Serve API base URL is: <b>https://api.shotstack.io/serve/{version}</b>
*
* The version of the OpenAPI document: v1
*
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 5.0.0
* OpenAPI Generator version: 5.4.0
*/

/**
Expand All @@ -28,9 +27,12 @@

namespace Shotstack\Client\Api;

error_reporting(E_ALL & ~E_DEPRECATED);

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
Expand Down Expand Up @@ -92,7 +94,7 @@ public function __construct(
*
* @param int $hostIndex Host index (required)
*/
public function setHostIndex($hostIndex)
public function setHostIndex($hostIndex): void
{
$this->hostIndex = $hostIndex;
}
Expand Down Expand Up @@ -158,10 +160,17 @@ public function getRenderWithHttpInfo($id, $data = null, $merged = null)
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
$e->getCode(),
(int) $e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
);
} catch (ConnectException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
null,
null
);
}

$statusCode = $response->getStatusCode();
Expand All @@ -171,21 +180,20 @@ public function getRenderWithHttpInfo($id, $data = null, $merged = null)
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$request->getUri()
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}

$responseBody = $response->getBody();
switch($statusCode) {
case 200:
if ('\Shotstack\Client\Model\RenderResponse' === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -196,11 +204,10 @@ public function getRenderWithHttpInfo($id, $data = null, $merged = null)
}

$returnType = '\Shotstack\Client\Model\RenderResponse';
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand Down Expand Up @@ -267,11 +274,10 @@ public function getRenderAsyncWithHttpInfo($id, $data = null, $merged = null)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -291,7 +297,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}
);
Expand Down Expand Up @@ -393,7 +399,7 @@ public function getRenderRequest($id, $data = null, $merged = null)

} else {
// for HTTP post (form)
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
$httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
}
}

Expand All @@ -414,7 +420,7 @@ public function getRenderRequest($id, $data = null, $merged = null)
$headers
);

$query = \GuzzleHttp\Psr7\build_query($queryParams);
$query = \GuzzleHttp\Psr7\Query::build($queryParams);
return new Request(
'GET',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
Expand Down Expand Up @@ -462,10 +468,17 @@ public function postRenderWithHttpInfo($edit)
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
$e->getCode(),
(int) $e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
);
} catch (ConnectException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
null,
null
);
}

$statusCode = $response->getStatusCode();
Expand All @@ -475,21 +488,20 @@ public function postRenderWithHttpInfo($edit)
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$request->getUri()
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}

$responseBody = $response->getBody();
switch($statusCode) {
case 201:
if ('\Shotstack\Client\Model\QueuedResponse' === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -500,11 +512,10 @@ public function postRenderWithHttpInfo($edit)
}

$returnType = '\Shotstack\Client\Model\QueuedResponse';
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand Down Expand Up @@ -567,11 +578,10 @@ public function postRenderAsyncWithHttpInfo($edit)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -591,7 +601,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}
);
Expand Down Expand Up @@ -663,7 +673,7 @@ public function postRenderRequest($edit)

} else {
// for HTTP post (form)
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
$httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
}
}

Expand All @@ -684,7 +694,7 @@ public function postRenderRequest($edit)
$headers
);

$query = \GuzzleHttp\Psr7\build_query($queryParams);
$query = \GuzzleHttp\Psr7\Query::build($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
Expand Down Expand Up @@ -732,10 +742,17 @@ public function probeWithHttpInfo($url)
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
$e->getCode(),
(int) $e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
);
} catch (ConnectException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
null,
null
);
}

$statusCode = $response->getStatusCode();
Expand All @@ -745,21 +762,20 @@ public function probeWithHttpInfo($url)
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$request->getUri()
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}

$responseBody = $response->getBody();
switch($statusCode) {
case 200:
if ('\Shotstack\Client\Model\ProbeResponse' === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -770,11 +786,10 @@ public function probeWithHttpInfo($url)
}

$returnType = '\Shotstack\Client\Model\ProbeResponse';
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand Down Expand Up @@ -837,11 +852,10 @@ public function probeAsyncWithHttpInfo($url)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $responseBody;
$content = (string) $response->getBody();
}

return [
Expand All @@ -861,7 +875,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()
(string) $response->getBody()
);
}
);
Expand Down Expand Up @@ -935,7 +949,7 @@ public function probeRequest($url)

} else {
// for HTTP post (form)
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
$httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
}
}

Expand All @@ -956,7 +970,7 @@ public function probeRequest($url)
$headers
);

$query = \GuzzleHttp\Psr7\build_query($queryParams);
$query = \GuzzleHttp\Psr7\Query::build($queryParams);
return new Request(
'GET',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
Expand Down
Loading

0 comments on commit 47c00c3

Please sign in to comment.