on 1 comment

Get Video Information PHP | Embed/Embed Package

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.

<?php

include "../Embed/src/autoloader.php";

use Embed\Embed;

$vidDetail =  getVideoDetail("<your video url>"); //it can be embed link also

function 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);
}

?>


1 comment:

  1. https://www.wisdommaterials.com
    https://globalcompaniesinfo.com/
    https://wisdomallcodes.com/

    ReplyDelete