smoqadam/youtube-video-info

There is no license information available for the latest version (dev-master) of this package.

dev-master 2019-12-19 03:26 UTC

This package is auto-updated.

Last update: 2024-09-19 14:24:12 UTC


README

Get the information about a youtube video

Installation

$ composer require smoqadam/youtube-video-info:dev-master

Usage

it's so easy to get the information about a youtueb's video. Let's say we need to fetch the caption for a spicific video:

<?php

use Smoqadam;
use Smoqadam\Response\Entity\Subtitle;

ini_set('display_errors', 'On');
require_once 'vendor/autoload.php';

$videoId = 'VVx6ntr5OqI';
$video = new Video($videoId);

$captions = $video->getCaptions('en');

/** @var Subtitle $caption */
foreach ($captions as $caption) {
    echo $caption->getText();
    echo '<br>';
    echo $caption->getStart();
    echo '<br>';
    echo $caption->getDuration();
    echo '<br>';
    echo '<hr>'
}

Let's get the formats for that video:

$formats = $video->getFormats();
/** @var Format $format */
foreach ($formats as $format) {
    echo $format->getUrl();
    echo $format->getMimeType();
    echo $format->getWidth();
    echo $format->getHeight();
    echo $format->getSize(); // in bytes
    echo $format->getQuality();
    echo $format->getFps();
    echo '<br>';
}

And finally, let's get some details about the video:

$details = $video->getDetails();
echo $details->getVideoId();
echo $details->getTitle();
echo $details->getThumbnails();
echo $details->getViewCount();
echo $details->getRating();