PHP Classes

Zanfi PHP YouTube Downloader: Get information and download a video from YouTube

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 99 All time: 9,779 This week: 96Up
Version License PHP version Categories
zanfi-yt-downloader 1.0.0GNU General Publi...5PHP 5, Files and Folders, Web services, V...
Description 

Author

This package can get information and download a video from YouTube.

It can take the ID string or the URL of a video on YouTube and sends HTTP requests to YouTube API to retrieve information about that specific video, like the video title and audio and video format available for a video.

The package can also serve the video stream for download.

Picture of Gianluca Zanferrari
  Performance   Level  
Name: Gianluca Zanferrari <contact>
Classes: 19 packages by
Country: The Netherlands The Netherlands
Age: 57
All time rank: 1674 in The Netherlands The Netherlands
Week rank: 30 Up1 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php
require('ZanfiYouTube.php');

// initialize the class with a yotube video ID or a youtube video url
// $ZanfiYouTube = new ZanfiYouTube('WaEKXGlfYj8');
$ZanfiYouTube = new ZanfiYouTube('https://www.youtube.com/watch?v=WaEKXGlfYj8');

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~ Data section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// leave parameter emtpy to print all data
// or give a path like: playbackTracking.videostatsWatchtimeUrl
// $ZanfiYouTube->printVideoInfo('streamingData.adaptiveFormats');

// print array with vieo thumbnails
// $ZanfiYouTube->printFormatted($ZanfiYouTube->arr_Video_thumbnails);

// print the array with video adaptive formats
$ZanfiYouTube->printFormatted($ZanfiYouTube->arr_Video_adaptive_formats);

// print the array with the best video+audio data
// $ZanfiYouTube->printFormatted($ZanfiYouTube->get_best_both());

// print the array with the best audio data
$ZanfiYouTube->printFormatted($ZanfiYouTube->get_best_audio());

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~ Download section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// uncomment where needed

// Starts download of video+audio
// $ZanfiYouTube->download_best_both();

// Starts download of audio
// $ZanfiYouTube->download_best_audio();
// shows the elapsed time for download (use it only after a download...)
// echo('Downloaded ' . $ZanfiYouTube->downloaded_bytes . ' bytes in ' . $ZanfiYouTube->elapsed_time . ' seconds');


Details

youtube-downloader

A php only youtube parser and downloader

Zanfi Youtube downloader is a blazing fast Youtube parser and Audio+Video or Audio only downloader.

It uses only 1 php class without third party software. It makes no use of the Youtube API (so no api key is needed).

Inspired from the (php) Athlon1600/youtube-downloader and, of course, from the youtube-dl and yt-dlp which are built with Python.

I was annoyed by the throttling that Youtube uses when downloading from an adaptive stream. With this class I measured download speeds even better than yt-dlp.

Just before putting this class online, I got this result:

\- Downloaded 5148614 bytes in 0.56019806861877 seconds

How to use the class:

include the class in your php code.

require('ZanfiYouTube.php');

initialize the class with a yotube video ID or a youtube video url

$ZanfiYouTube = new ZanfiYouTube('WaEKXGlfYj8');

or

$ZanfiYouTube = new ZanfiYouTube('https://www.youtube.com/watch?v=WaEKXGlfYj8');

The most important data is stored in:

$ZanfiYouTube->arr_Video_info;
$ZanfiYouTube->arr_Video_formats;
$ZanfiYouTube->arr_Video_adaptive_formats;
$ZanfiYouTube->arr_Video_thumbnails;

just print what you need to see:

$ZanfiYouTube->printFormatted($ZanfiYouTube->arr_Video_adaptive_formats);

print the array with the best video+audio data

$ZanfiYouTube->printFormatted($ZanfiYouTube->get_best_both());

print the array with the best audio data

$ZanfiYouTube->printFormatted($ZanfiYouTube->get_best_audio());

Starts download of video+audio

$ZanfiYouTube->download_best_both();

Starts download of audio only

$ZanfiYouTube->download_best_audio();

shows the elapsed time for download (use it only after a download...)

echo('Downloaded ' . $ZanfiYouTube->downloaded_bytes . ' bytes in ' . $ZanfiYouTube->elapsed_time . ' seconds');

?? Legal Disclaimer

This is a proof of concept. This program is for personal use only. Downloading copyrighted material without permission is against YouTube's terms of services. By using this program, you are solely responsible for any copyright violations. We are not responsible for people who attempt to use this program in any way that breaks YouTube's terms of services.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


  Files folder image Files  
File Role Description
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Example Example script
Plain text file ZanfiYouTube.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:99
This week:0
All time:9,779
This week:96Up