aludvigsson/youtube-caption-fetcher

A PHP package to fetch captions from YouTube videos

dev-main 2024-08-17 11:35 UTC

This package is not auto-updated.

Last update: 2025-06-08 14:01:41 UTC


README

A PHP package to fetch captions from YouTube videos.

Installation

You can install the package via composer:

composer require aludvigsson/youtube-caption-fetcher

Usage

use Aludvigsson\YouTubeCaptionFetcher\YouTubeCaptionFetcher;
use Aludvigsson\YouTubeCaptionFetcher\CaptionFetcherException;
use Aludvigsson\YouTubeCaptionFetcher\InvalidUrlException;

$fetcher = new YouTubeCaptionFetcher();
try {
    $transcript = $fetcher->getTranscript('https://www.youtube.com/watch?v=VIDEO_ID');
    $title = $fetcher->getVideoTitle('https://www.youtube.com/watch?v=VIDEO_ID');
    echo $title;
    print_r($transcript);
} catch (CaptionFetcherException $e) {
    echo "An error occurred: " . $e->getMessage();
}