PHP Classes

PHP YouTube Video Downloader: Download files of given YouTube videos

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum (6)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 72%Total: 2,706 All time: 1,402 This week: 120Up
Version License PHP version Categories
youtube-downloader 1.12GNU General Publi...5.4PHP 5, Files and Folders, Web services, V...
Description 

Author

This class can download files of given YouTube videos.

It takes a given YouTube video identifier and sends a request to YouTube to get the video details. The class works as a parser of YouTube video metadata.

The class can get the YouTube video source URL and generates a link to download the video data in a given format, usually MP4, or can download it directly to a file using the Curl extension or the wget program.

Picture of Nitesh Apte
  Performance   Level  
Name: Nitesh Apte is available for providing paid consulting. Contact Nitesh Apte .
Classes: 17 packages by
Country: India India
Age: 40
All time rank: 1337 in India India
Week rank: 45 Up6 in India India Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Recommendations

What is the best PHP youtube video downloader class?
Download videos from YouTube

What is the best PHP video convert to mp4 class?
Need a online video convertor like youtube , and play all videos

Example

<?php
require_once 'errorhandler.php';
require
'class.YouTubeBean.php';
require
'class.YouTubeVideoDownloader.php';

$videoList = array();

if(
PHP_SAPI === 'cli') { // via command mode
   
array_shift($argv);
   
$videoList = $argv;
} else if(isset(
$_GET['video'])) { // via browser
   
$videos = @trim($_GET['video']);
    if(!empty(
$videos)):
       
$videoList = explode(",", $videos);
    endif;
} else {
   
$videoList = array(); // add video id manually
}

try {
   
header('Content-Type: text/html; charset=utf-8');
   
    for(
$i = 0; $i < sizeof($videoList); $i++):
   
       
$bean = new YouTubeBean();
       
$bean->setVideoId($videoList[$i]);
       
$bean->setVideoFormat("22");
       
$bean->setMethod("curl");
       
$bean->setDestination("/root/Videos/"); // Make sure this folder is writable
       
       
$downloader = new YouTubeVideoDownloader();
       
$downloader->startDownload($bean);
       
    endfor;
} catch (
YouTubeInvalidVideoIdException $e) {
    die(
"<strong>YouTubeInvalidVideoIdException</strong> : ".$e->getMessage());
} catch (
YouTubeUnsupportedVideoFormatException $e) {
    die(
"<strong>YouTubeUnsupportedVideoFormatException</strong> : ".$e->getMessage());
} catch (
YouTubeUnsupportedDownloadMethodException $e) {
    die(
"<strong>YouTubeUnsupportedDownloadMethodException</strong> : ".$e->getMessage());
} catch (
YouTubeCurlNotAvailableException $e) {
    die(
"<strong>YouTubeCurlNotAvailableException</strong> : ".$e->getMessage());
} catch (
YouTubeEmptyDownloadDestinationException $e) {
    die(
"<strong>YouTubeEmptyDownloadDestinationException</strong> : ".$e->getMessage());
} catch (
YouTubeVideoNotFoundException $e) {
    die(
"<strong>YouTubeVideoNotFoundException</strong> : ".$e->getMessage());
} catch(
YouTubeVideoNotAvailableForGivenFormatException $e) {
    die(
"<strong>YouTubeVideoNotAvailableForGivenFormatException</strong> : ".$e->getMessage());
} catch (
YouTubeException $e) {
    die(
"<strong>YouTubeException</strong> : Something went wrong. Message : ".$e->getMessage());
}
?>


Details

Hi, In order to make this class support more number of video formats, add the values in $supportedVideoFormat array. Command line: php example.php GvQJbF2CXLQ cYqw0YytUxw Browser: http://localhost/youtube-downloader/example.php?video=GvQJbF2CXLQ,cYqw0YytUxw Thanks

  Files folder image Files  
File Role Description
Plain text file class.ErrorHandler.php Class Handles and logs the error
Plain text file class.YouTubeBean.php Class Set configuration for download
Plain text file class.YouTubeException.php Class YouTube exception class.
Plain text file class.YouTubeVideoDownloader.php Class Download videos from YouTube using WGET or cURL
Accessible without login Plain text file errorhandler.php Conf. Instantiate Error Handler class
Accessible without login Plain text file example.php Example How to use the YouTubeVideoDownloader class
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file LICENSE.TXT Lic. License
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file README.TXT Doc. INFO

 Version Control Unique User Downloads Download Rankings  
 80%
Total:2,706
This week:0
All time:1,402
This week:120Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:72%StarStarStarStar
Rank:181