PHPackages                             mrmysql/youtube-transcript - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mrmysql/youtube-transcript

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mrmysql/youtube-transcript
==========================

Retrieving transcripts for youtube videos.

v0.0.6(1mo ago)20234.9k↓37.9%4[4 issues](https://github.com/MrMySQL/youtube-transcript/issues)[1 PRs](https://github.com/MrMySQL/youtube-transcript/pulls)3WTFPLPHPPHP ^8.2CI passing

Since Aug 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/MrMySQL/youtube-transcript)[ Packagist](https://packagist.org/packages/mrmysql/youtube-transcript)[ GitHub Sponsors](https://github.com/MrMySQL)[ RSS](/packages/mrmysql-youtube-transcript/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (6)Dependencies (10)Versions (10)Used By (3)

YouTube Transcript
==================

[](#youtube-transcript)

YouTube Transcript is a PHP library designed to fetch transcripts for YouTube videos. It allows you to retrieve captions in multiple languages, including auto-generated captions, and provides functionality to translate transcripts into other available languages. Inspired by [jdepoix/youtube-transcript-api](https://github.com/jdepoix/youtube-transcript-api). I've generated this readme using one of these fancy \[A\]utocompletion \[I\]nstruments, so it might be incorrect somewhere, but overall looks good.

[![codecov](https://camo.githubusercontent.com/24d3900dfce6b231ad7fd1a03349863db52a3fb60f41ad32fccb8d41d12d1b94/68747470733a2f2f636f6465636f762e696f2f67682f4d724d7953514c2f796f75747562652d7472616e7363726970742f67726170682f62616467652e7376673f746f6b656e3d324c505a3842314d5248)](https://codecov.io/gh/MrMySQL/youtube-transcript)

Features
--------

[](#features)

- Retrieve both manually created and auto-generated transcripts.
- Fetch transcripts in various languages.
- Translate transcripts to other available languages.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher (including support for PHP 8.2)
- PSR-18 HTTP Client (`psr/http-client`) and HTTP Factory (`psr/http-factory`)

Installation
------------

[](#installation)

To include this library in your project, use Composer:

```
composer require mrmysql/youtube-transcript
```

Usage
-----

[](#usage)

### 1. Initialize the Transcript Fetcher

[](#1-initialize-the-transcript-fetcher)

To begin, you need to set up an HTTP client and a request factory that implements the PSR-18 and PSR-17 interfaces, respectively. These dependencies are required by the `TranscriptListFetcher` class.

```
use MrMySQL\YoutubeTranscript\TranscriptListFetcher;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;

$http_client = new Client();
$request_factory = new HttpFactory();
$stream_factory = new HttpFactory(); // GuzzleHttp\Psr7\HttpFactory implements StreamFactoryInterface

$fetcher = new TranscriptListFetcher($http_client, $request_factory, $stream_factory);
```

### 2. Fetch the Transcript List

[](#2-fetch-the-transcript-list)

You can fetch the transcript list for a given YouTube video ID:

```
$video_id = 'YOUR_YOUTUBE_VIDEO_ID';
$transcript_list = $fetcher->fetch($video_id);
```

### 3. Retrieve and Display Transcripts

[](#3-retrieve-and-display-transcripts)

You can iterate over the available transcripts and display them:

```
foreach ($transcript_list as $transcript) {
    echo $transcript . "\n";
}
```

### 4. Fetch a Specific Transcript

[](#4-fetch-a-specific-transcript)

To fetch a transcript in a specific language:

```
$language_codes = ['en', 'es']; // Prioritized language codes
$transcript = $transcript_list->findTranscript($language_codes);
$transcript_text = $transcript->fetch();
print_r($transcript_text);
```

You can also take all available locale codes directly from the list:

```
$language_codes = $transcript_list->getAvailableLanguageCodes();
$transcript = $transcript_list->findTranscript($language_codes);
$transcript_text = $transcript->fetch();
print_r($transcript_text);
```

### 5. Translate a Transcript

[](#5-translate-a-transcript)

If translation is available, you can translate the transcript to another language:

```
$translated_transcript = $transcript->translate('fr');
$translated_text = $translated_transcript->fetch();
print_r($translated_text);
```

**Note:** Cookie-based authentication is currently not supported due to recent changes in the YouTube API. Age-restricted videos and some protected content cannot be accessed until a new authentication method is implemented.

Exception Handling
------------------

[](#exception-handling)

This library comes with a set of custom exceptions to handle different scenarios:

- `YouTubeRequestFailedException`: Thrown when the YouTube request fails.
- `NoTranscriptFoundException`: Thrown when no transcript is found for the given language codes.
- `NotTranslatableException`: Thrown when attempting to translate a transcript that is not translatable.
- `TranscriptsDisabledException`: Thrown when transcripts are disabled for the video.
- `TooManyRequestsException`: Thrown when YouTube imposes a rate limit.
- `PoTokenRequiredException`: Thrown when a PO Token is required to retrieve the transcript (please open a GitHub issue if you see this).

### Example:

[](#example)

```
try {
    $transcript = $transcript_list->findGeneratedTranscript(['en']);
    print_r($transcript->fetch());
} catch (YouTubeRequestFailedException $e) {
    echo "Failed to fetch the transcript: " . $e->getMessage();
}
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity44

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~129 days

Recently: every ~157 days

Total

6

Last Release

34d ago

PHP version history (2 changes)v0.0.1PHP ^7.4 || ^8.2

v0.0.3PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/727942bd0dbdd4f4a632be9f297d9eee71d8ca756e1ffb96bc7996ed1c8dc72f?d=identicon)[MrMySQL](/maintainers/MrMySQL)

---

Top Contributors

[![MrMySQL](https://avatars.githubusercontent.com/u/1144613?v=4)](https://github.com/MrMySQL "MrMySQL (28 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mrmysql-youtube-transcript/health.svg)

```
[![Health](https://phpackages.com/badges/mrmysql-youtube-transcript/health.svg)](https://phpackages.com/packages/mrmysql-youtube-transcript)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M420](/packages/drupal-core-recommended)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[chargebee/chargebee-php

ChargeBee API client implementation for PHP

758.5M9](/packages/chargebee-chargebee-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
