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.5(11mo ago)18203.9k↑11.2%2[4 issues](https://github.com/MrMySQL/youtube-transcript/issues)3WTFPLPHPPHP ^8.2CI passing

Since Aug 20Pushed 10mo 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 1mo ago

READMEChangelog (5)Dependencies (5)Versions (8)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

41

—

FairBetter than 89% of packages

Maintenance48

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity47

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 ~74 days

Total

5

Last Release

339d 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 (26 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

[embed/embed

PHP library to retrieve page info using oembed, opengraph, etc

2.1k11.0M97](/packages/embed-embed)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[csharpru/vault-php

Best Vault client for PHP that you can find

8410.3M4](/packages/csharpru-vault-php)[unleash/client

633.1M8](/packages/unleash-client)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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