📅  最后修改于: 2022-03-11 14:56:41.657000             🧑  作者: Mango
/**
* Vimeo video duration in seconds
*
* @param $video_url
* @return integer|null Duration in seconds or null on error
*/
public static function vimeoVideoDuration($url) {
$json_url = 'https://vimeo.com/api/oembed.json?url=' . $url;
$ch = curl_init($json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
try{
$data = json_decode($data, true);
}catch (\Exception $e){ $data = null; }
if (!isset($data["duration"])) {
return null;
}
// in seconds
return $data["duration"];
}