From 922f64c16fcc807866c53103ecaf789909fd55d1 Mon Sep 17 00:00:00 2001 From: GrabzIt Date: Sat, 10 Feb 2024 15:34:26 +0000 Subject: [PATCH] Added html to video --- composer.json | 14 +- lib/GrabzItClient.php | 49 +++++++ lib/GrabzItVideoOptions.php | 254 ++++++++++++++++++++++++++++++++++++ 3 files changed, 313 insertions(+), 4 deletions(-) create mode 100644 lib/GrabzItVideoOptions.php diff --git a/composer.json b/composer.json index 3804329..92762e2 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/lib/GrabzItClient.php b/lib/GrabzItClient.php index 765171c..95443f7 100644 --- a/lib/GrabzItClient.php +++ b/lib/GrabzItClient.php @@ -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"; @@ -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. diff --git a/lib/GrabzItVideoOptions.php b/lib/GrabzItVideoOptions.php new file mode 100644 index 0000000..ee142a3 --- /dev/null +++ b/lib/GrabzItVideoOptions.php @@ -0,0 +1,254 @@ +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; + } +} +?> \ No newline at end of file