Skip to content

Commit

Permalink
Added html to video
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabzIt committed Feb 10, 2024
1 parent f7535ec commit 922f64c
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 4 deletions.
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "grabzit/grabzit",
"type": "library",
"keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","JPG","BMP","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","URL to PDF","URL to DOCX","URL to Image", "Rendered HTML"],
"keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","JPG","BMP","mp4","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","HTML to Video","URL to PDF","URL to DOCX","URL to Image","URL to Video", "Rendered HTML"],
"homepage": "https://grabz.it/",
"description": "Use our API to allow your app to create images, DOCX documents, rendered HTML and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.",
"description": "Use our API to allow your app to create images, DOCX documents, videos, rendered HTML and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.",
"license": "MIT",
"version":"3.5.2",
"version":"3.5.3",
"autoload": {
"psr-4": {
"GrabzIt\\": "lib/"
}
},
"classmap": [
"vendor/"
]
},
"support": {
"issues": "https://grabz.it/support/"
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "^11"
}
}
49 changes: 49 additions & 0 deletions lib/GrabzItClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GrabzItClient
{
const WebServicesBaseURL = "://api.grabz.it/services/";
const TakePicture = "takepicture";
const TakeVideo = "takevideo";
const TakeTable = "taketable";
const TakePDF = "takepdf";
const TakeDOCX = "takedocx";
Expand Down Expand Up @@ -217,6 +218,54 @@ public function FileToImage($path, GrabzItImageOptions $options = null)
$this->HTMLToImage(file_get_contents($path), $options);
}

/*
This method specifies the URL that should be converted into a video.
url - The URL to capture as a video.
options - A instance of the GrabzItVideoOptions class that defines any special options to use when creating the video.
*/
public function URLToVideo($url, GrabzItVideoOptions $options = null)
{
if ($options == null)
{
$options = new GrabzItVideoOptions();
}

$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeVideo, false, $options, $url);
}

/*
This method specifies the HTML that should be converted into a video.
html - The HTML to convert into a video.
options - A instance of the GrabzItVideoOptions class that defines any special options to use when creating the video.
*/
public function HTMLToVideo($html, GrabzItVideoOptions $options = null)
{
if ($options == null)
{
$options = new GrabzItVideoOptions();
}

$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeVideo, true, $options, $html);
}

/*
This method specifies a HTML file that should be converted into a video.
path - The file path of a HTML file to convert into a video.
options - A instance of the GrabzItVideoOptions class that defines any special options to use when creating the video.
*/
public function FileToVideo($path, GrabzItVideoOptions $options = null)
{
if (!file_exists($path))
{
throw new GrabzItException("File: " . $path . " does not exist", GrabzItException::FILE_NON_EXISTANT_PATH);
}

$this->HTMLToVideo(file_get_contents($path), $options);
}

/*
This method specifies the URL that should be converted into rendered HTML.
Expand Down
254 changes: 254 additions & 0 deletions lib/GrabzItVideoOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
<?php
namespace GrabzIt;

class GrabzItVideoOptions extends GrabzItBaseOptions
{
private $customWaterMarkId = null;
private $browserWidth = null;
private $browserHeight = null;
private $start = null;
private $duration = null;
private $framesPerSecond = null;
private $waitForElement = null;
private $requestAs = 0;
private $clickElement = null;
private $noAds = false;
private $noCookieNotifications = false;
private $address = null;

/*
Set the number of frames per second that should be used to create the video. From a minimum of 0.2 to a maximum of 10.
*/
public function setFramesPerSecond($value)
{
$this->framesPerSecond = $value;
}

/*
Get the number of frames per second that should be used to create the video.
*/
public function getFramesPerSecond()
{
return $this->framesPerSecond;
}

/*
Set the length in seconds of the web page that should be converted into a video.
*/
public function setDuration($value)
{
$this->duration = $value;
}

/*
Get the length in seconds of the web page that should be converted into a video.
*/
public function getDuration()
{
return $this->duration;
}

/*
Set the starting time of the web page that should be converted into a video.
*/
public function setStart($value)
{
$this->start = $value;
}

/*
Get starting time of the web page that should be converted into a video.
*/
public function getStart()
{
return $this->start;
}

/*
Set the width of the browser in pixels.
*/
public function setBrowserWidth($value)
{
$this->browserWidth = $value;
}

/*
Get the width of the browser in pixels.
*/
public function getBrowserWidth()
{
return $this->browserWidth;
}

/*
Set the height of the browser in pixels.
*/
public function setBrowserHeight($value)
{
$this->browserHeight = $value;
}

/*
Get the height of the browser in pixels.
*/
public function getBrowserHeight()
{
return $this->browserHeight;
}

/*
Set a custom watermark to add to the video.
*/
public function setCustomWaterMarkId($value)
{
$this->customWaterMarkId = $value;
}

/*
Get the custom watermark id.
*/
public function getCustomWaterMarkId()
{
return $this->customWaterMarkId;
}

/*
Set the CSS selector of the HTML element in the web page that must be visible before the capture is performed.
*/
public function setWaitForElement($value)
{
$this->waitForElement = $value;
}

/*
Get the CSS selector of the HTML element in the web page that must be visible before the capture is performed.
*/
public function getWaitForElement()
{
return $this->waitForElement;
}

/*
Set which user agent type should be used: Standard Browser = 0, Mobile Browser = 1, Search Engine = 2 and Fallback Browser = 3.
*/
public function setRequestAs($value)
{
$this->requestAs = $value;
}

/*
Get which user agent type should be used.
*/
public function getRequestAs()
{
return $this->requestAs;
}

/*
Set to true if adverts should be automatically hidden.
*/
public function setNoAds($value)
{
$this->noAds = $value;
}

/*
Get if adverts should be automatically hidden.
*/
public function getNoAds()
{
return $this->noAds;
}

/*
Set to true if cookie notification should be automatically hidden.
*/
public function setNoCookieNotifications($value)
{
$this->noCookieNotifications = $value;
}

/*
Get if cookie notification should be automatically hidden.
*/
public function getNoCookieNotifications()
{
return $this->noCookieNotifications;
}

/*
Set the URL to execute the HTML code in.
*/
public function setAddress($value)
{
$this->address = $value;
}

/*
Get the URL to execute the HTML code in.
*/
public function getAddress()
{
return $this->address;
}

/*
Set the CSS selector of the HTML element in the web page to click.
*/
public function setClickElement($value)
{
$this->clickElement = $value;
}

/*
Get the CSS selector of the HTML element in the web page to click.
*/
public function getClickElement()
{
return $this->clickElement;
}

public function _getSignatureString($applicationSecret, $callBackURL, $url = null)
{
$urlParam = '';
if ($url != null)
{
$urlParam = $this->nullToEmpty($url)."|";
}

$callBackURLParam = '';
if ($callBackURL != null)
{
$callBackURLParam = $this->nullToEmpty($callBackURL);
}

return $this->nullToEmpty($applicationSecret)."|". $urlParam . $callBackURLParam .
"|".$this->nullToEmpty($this->browserHeight)."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getCustomId())."|".
$this->nullToEmpty($this->customWaterMarkId)."|".$this->nullToEmpty($this->start)."|".
$this->nullToEmpty(intval($this->requestAs))."|".$this->nullToEmpty($this->getCountry())."|".$this->nullToEmpty($this->getExportURL())."|".
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey()."|".
$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".
$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->framesPerSecond)."|".$this->nullToEmpty($this->duration));
}

public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
{
$params = $this->createParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue);
$params['bwidth'] = $this->nullToEmpty($this->browserWidth);
$params['bheight'] = $this->nullToEmpty($this->browserHeight);
$params['duration'] = $this->nullToEmpty($this->duration);
$params['waitfor'] = $this->nullToEmpty($this->waitForElement);
$params['customwatermarkid'] = $this->nullToEmpty($this->customWaterMarkId);
$params['start'] = $this->nullToEmpty($this->start);
$params['fps'] = $this->nullToEmpty($this->framesPerSecond);
$params['requestmobileversion'] = $this->nullToEmpty($this->requestAs);
$params['noads'] = $this->nullToEmpty(intval($this->noAds));
$params['post'] = $this->nullToEmpty($this->post);
$params['address'] = $this->nullToEmpty($this->address);
$params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications));
$params['click'] = $this->nullToEmpty($this->clickElement);

return $params;
}
}
?>

0 comments on commit 922f64c

Please sign in to comment.