aludvigsson/youtube-caption-fetcher

一个用于从YouTube视频中获取字幕的PHP包

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

This package is not auto-updated.

Last update: 2024-09-29 10:27:50 UTC


README

一个用于从YouTube视频中获取字幕的PHP包。

安装

您可以通过composer安装此包

composer require aludvigsson/youtube-caption-fetcher

使用方法

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