Created
October 27, 2018 11:51
-
-
Save mwordpress/d169e72e4e988b96b01b830460c157d2 to your computer and use it in GitHub Desktop.
Vimeo Video Download Links -- Work with wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Usage : | |
* $video = new VimeoController; | |
* $data = $video->getVideoDownloadLink('https://vimeo.com/276013718'); | |
* print_r($data); | |
* | |
*/ | |
class VimeoController { | |
/* | |
* Get the video information | |
* return string | |
*/ | |
private function getVideoInfo($url) { | |
return wp_remote_retrieve_body( wp_remote_get( $this->getRequestedUrl($url), array( 'timeout' => 15 ) ) ); | |
} | |
/* | |
* Scrap the url from the page | |
* return string | |
*/ | |
private function getRequestedUrl($url) | |
{ | |
$data = wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 15 ) ) ); | |
$data = stristr($data, 'config_url":"'); | |
$start = substr($data, strlen('config_url":"')); | |
$stop = stripos($start, ','); | |
$str = substr($start, 0, $stop); | |
return rtrim(str_replace("\\", "", $str), '"'); | |
} | |
/* | |
* Get the video download link | |
* return array | |
*/ | |
public function getVideoDownloadLink($url) { | |
$decode_to_arr = json_decode($this->getVideoInfo($url), true); | |
$this->video_title = $decode_to_arr["video"]["title"]; | |
$link_array = $decode_to_arr["request"]["files"]["progressive"]; | |
$final_link_arr = array(); | |
//Create array containing the detail of video | |
for($i = 0; $i < count($link_array); $i++) { $link_array[$i]["title"] = $this->video_title; | |
$mime = explode("/", $link_array[$i]["mime"]); | |
$link_array[$i]["format"] = $mime[1]; | |
} | |
return $link_array; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment