PHP embed/embed package can used used for fetching video information such as duration , thumbnail and many other useful information.
First install the package via composer
composer require embed/embed
Then, include autoloader.php in source file and fetch video information as follows.
<?phpinclude "../Embed/src/autoloader.php";use Embed\Embed;$vidDetail = getVideoDetail("<your video url>"); //it can be embed link alsofunction getVideoDetail($url){//Load any url:$info = Embed::create($url);$duration = "";foreach ($info->getProviders() as $providerName => $provider){foreach($provider->getBag()->getAll() as $prKey=>$prVal){if($prKey == duration){$duration = $prVal;continue;}}if($duration) continue;}if(strpos($url, "youtube.com")){$duration = str_replace("PT", "", $duration);$duration = str_replace("S", "", $duration);$durationArr = explode("M", $duration);$duration = $durationArr[0] * 60 + $durationArr[1] - 1;}$thumbnail = $info->image;return array("thumbnail" => $thumbnail, "duration" => $duration);}?>
https://www.wisdommaterials.com
ReplyDeletehttps://globalcompaniesinfo.com/
https://wisdomallcodes.com/