PHP code example of flatbits / youstraw

1. Go to this page and download the library: Download flatbits/youstraw library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flatbits / youstraw example snippets



use FlatBits\YouStraw\Straw;


latBits\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.


latBits\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());