Skip to content

Instantly share code, notes, and snippets.

@MrWeb
Created March 21, 2024 19:05
Show Gist options
  • Save MrWeb/2d49bb38188aaec6f3c5c5a3357355ef to your computer and use it in GitHub Desktop.
Save MrWeb/2d49bb38188aaec6f3c5c5a3357355ef to your computer and use it in GitHub Desktop.
Extract text and captions from a Youtube Video with PHP and Laravel
<?php
use Illuminate\Support\Facades\Http;
$videoId = "AuEv942wOZs";
$transcriptUrl = Http::post(
"https://youtubei.googleapis.com/youtubei/v1/player",
[
"videoId" => $videoId,
"context" => [
"client" => [
"hl" => "en",
"clientName" => "WEB",
"clientVersion" => "2.20210721.00.00"
]
]
]
)->json("captions.playerCaptionsTracklistRenderer.captionTracks.0.baseUrl");
$transcriptXml = Http::post($transcriptUrl, [
"videold" => $videoId
])->body();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment