2017 © Pedro Peláez
 

library youtube-downloader

PHP powered alternative for youtube-dl

image

athlon1600/youtube-downloader

PHP powered alternative for youtube-dl

  • Saturday, June 2, 2018
  • by Athlon1600
  • Repository
  • 11 Watchers
  • 50 Stars
  • 8,509 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 30 Forks
  • 7 Open issues
  • 3 Versions
  • 16 % Grown

The README.md

, (*1)

, (*2)

, (*3)

youtube-downloader

This project was inspired by a very popular youtube-dl python package:
https://github.com/rg3/youtube-dl, (*4)

Yes, there are multiple other PHP-based youtube downloaders on the Internet, but most of them haven't been updated in years, or they depend on youtube-dl itself., (*5)

Pure PHP-based youtube downloaders that work, and are kept-up-to date just do not exist., (*6)

This script uses no Javascript interpreters, no calls to shell... nothing but pure PHP with no heavy dependencies either., (*7)

, (*8)

That's all there is to it!, (*9)

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., (*10)

Demo App

This may not work at all times, because YouTube puts a short ban on the server if it receives too many requests from it., (*11)

  • https://youtube-downloader-v3.herokuapp.com/

, (*12)

Deploy your own App

on Heroku:, (*13)

Deploy, (*14)

Create a FREE account first if you do not yet have one:
https://signup.heroku.com/, (*15)

Installation

Recommended way of installing this is via Composer:, (*16)

composer require athlon1600/youtube-downloader "^3.0"

Run locally:, (*17)

php -S localhost:8000 -t vendor/athlon1600/youtube-downloader/public

Previous versions

Instructions for installing & using Version 2 can be found here:
https://github.com/Athlon1600/youtube-downloader/tree/2.x, (*18)

Usage

use YouTube\YouTubeDownloader;
use YouTube\Exception\YouTubeException;

$youtube = new YouTubeDownloader();

try {
    $downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=aqz-KE-bpKQ");

    if ($downloadOptions->getAllFormats()) {
        echo $downloadOptions->getFirstCombinedFormat()->url;
    } else {
        echo 'No links found';
    }

} catch (YouTubeException $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}

getDownloadLinks method returns a DownloadOptions type object, which holds an array of stream links - some that are audio-only, and some that are both audio and video combined into one., (*19)

For typical usage, you are probably interested in dealing with combined streams, for that case, there is the getCombinedFormats method., (*20)

Other Features

  • Stream YouTube videos directly from your server:
$youtube = new \YouTube\YouTubeStreamer();
$youtube->stream('https://r4---sn-n4v7knll.googlevideo.com/videoplayback?...');
  • Pass in your own cookies/user-agent

If you try downloading age-restricted videos, YouTube will ask you to login. The only way to make this work, is to login to your YouTube account in your own web-browser, export those newly set cookies from your browser into a file, and then pass it all to youtube-downloader for use., (*21)

$youtube = new YouTubeDownloader();
$youtube->getBrowser()->setCookieFile('./your_cookies.txt');
$youtube->getBrowser()->setUserAgent('Opera 7.6');

See also:
https://github.com/ytdl-org/youtube-dl/blob/master/README.md#how-do-i-pass-cookies-to-youtube-dl, (*22)

  • Before you continue to YouTube...

Depending on your region, you might be force redirected to a page that asks you to agree to Google's cookie policy. You can programmatically agree to those terms, and bypass that warning permanently via consentCookies method on your Browser instance. Example:, (*23)

$youtube = new YouTubeDownloader();
$youtube->getBrowser()->consentCookies();

How does it work

A more detailed explanation on how to download videos from YouTube will be written soon. For now, there is this:, (*24)

https://github.com/Athlon1600/youtube-downloader/pull/25#issuecomment-439373506, (*25)

  • https://github.com/Athlon1600/php-curl-file-downloader
  • https://github.com/TeamNewPipe/NewPipeExtractor/blob/d83787a5ca308c4ca4e86e63a8b63c5e7c4708d6/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java
  • https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py

To-do list

  • Add ability to solve YouTube Captcha and avoid HTTP 429 Too Many Requests errors.
  • Add ability to download video and audio streams separately, and merge the two together using ffmpeg. Just like youtube-dl does!
  • Optional command that finds ALL video formats.
  • ~~Fetch additional metadata about the video without using YouTube API.~~

The Versions

02/06 2018

dev-master

9999999-dev

PHP powered alternative for youtube-dl

  Sources   Download

MIT

The Requires

  • ext-curl *

 

youtube downloader download youtube download youtube videos

26/02 2017

v1.0.1

1.0.1.0

PHP powered alternative for youtube-dl

  Sources   Download

MIT

The Requires

  • ext-curl *

 

youtube downloader download youtube download youtube videos

27/12 2016

v1.0.0

1.0.0.0

PHP powered alternative for youtube-dl

  Sources   Download

MIT

The Requires

  • ext-curl *

 

youtube downloader download youtube download youtube videos