YouStraw
This experiment is not supported anymore and will probably not received any update in the future
Important : Since the data we need is not provided by Google's official API, this library does not require you to
provide an API key or any other credentials. However, the the library heavily relies on undocumented APIs and DOM
parsing. For these reason, I do not recommend the use of this library in mission critical environment since it can
break at any moment from a change in YouTube's code, (*1)
Installation
Install the latest version via Composer, (*2)
composer require flatbits/youstraw
Include Composer's autoload file, and don't forget to add the use
statements, (*3)
require_once('./vendor/autoload.php');
use FlatBits\YouStraw\Straw;
Optional Requirement
-
FFmpeg - Some formats are not directly delivered from YouTube, this library requires
FFmpeg for those Converted formats
Usage
Download a single video
<?php
require_once('./vendor/autoload.php');
use FlatBits\YouStraw\Format;
use FlatBits\YouStraw\Format\Mp4;
use FlatBits\YouStraw\Straw;
$videoId = 'xEoMC7czIxA';
// Create a Straw, the handle to our video
$straw = new Straw($videoId);
// Download a high quality (720p) mp4 to the video dir.
$straw->download('../cache/video', new Mp4(Format::QUALITY_HIGH));
// Make sure the script has write access to the specified directory.
Download music from a playlist
<?php
require_once('../vendor/autoload.php');
use FlatBits\YouStraw\Format;
use FlatBits\YouStraw\Format\Mp3;
use FlatBits\YouStraw\StrawCollection;
$playlistId = 'PLDoXbhQs-J6TMo69UeDvlxmDf7nkR8OSm';
// Create the StrawCollection, a helper for batch downloads and playlist parsing
$strawCollection = StrawCollection::fromPlaylist($playlistId);
// Download the collection mp3 files to the music dir.
$strawCollection->downloadAll('../cache/music', new Mp3());
Please look in the examples folder or through the source code for further usage., (*4)
Natives
Format |
Available qualities |
Mp4 |
High, Medium |
WebM |
Medium |
Flv |
Low |
ThreeGP (3gp) |
Low |
Converted
Audio
Format |
Available qualities |
Mp3 |
High, Medium |
Flac |
High, Medium |