A much faster alternative to youtube-dl built for PHP applications.

Overview

youtube-downloader

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

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.

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

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

That's all there is to it!

⚠️ Legal Disclaimer

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.

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.

Deploy your own App

on Heroku:

Deploy

Create a FREE account first if you do not yet have one:
https://signup.heroku.com/

Installation

Recommended way of installing this is via Composer:

composer require athlon1600/youtube-downloader "^3.0"

Run locally:

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

Usage

getAllFormats()) { echo $downloadOptions->getFirstCombinedFormat()->url; } else { echo 'No links found'; } } catch (YouTubeException $e) { echo 'Something went wrong: ' . $e->getMessage(); } ">
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.

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

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.

$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

  • 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:

$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:

https://github.com/Athlon1600/youtube-downloader/pull/25#issuecomment-439373506

Other Links

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.
Comments
  • Not Working

    Not Working

    It's working fine just one month, but now it's not work for me,

    but you https://api.unblockvideos.com/youtube_downloader?id=nxmp6eb_QgI worked fine

    can you give an any update?

    opened by CShehan 13
  • some videos can't be downloaded

    some videos can't be downloaded

    some videos like vevo videos can't be downloaded it return 403.

    demo: https://api.unblockvideos.com/youtube_downloader?id=https://www.youtube.com/watch?v=fyaI4-5849w

    opened by chadul 13
  • Empty array

    Empty array

    Hello, My steps with clear Debian 10 apt update && apt -y upgrade apt -y install php php-common apt -y install php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath apt -y install libapache2-mod-php systemctl restart apache2 apt install curl php-cli php-mbstring git unzip cd ~ curl -sS https://getcomposer.org/installer -o composer-setup.php php composer-setup.php --install-dir=/usr/local/bin --filename=composer cd /var/www/html composer require athlon1600/youtube-downloader

    (/var/www/html/youtube.php):

    require 'var/www/html/vendor/autoload.php'; use YouTube\YouTubeDownloader; $yt = new YouTubeDownloader(); $links = $yt->getDownloadLinks("https://www.youtube.com/watch?v=QxsmWxxouIM"); var_dump($links);

    And it's show array(0) { }

    What did I do wrong?

    opened by sam9177 11
  • Signature Decoder broken. Error 403

    Signature Decoder broken. Error 403

    Encrypted Videos cant be downloaded since yesterday, got Error 403, so Signature Decoder is broken.

    Example Video: https://www.youtube.com/watch?v=lWA2pjMjpBs

    opened by rustynail1984 8
  • Signature Decoder broke again

    Signature Decoder broke again

    Hi, Signature Decoder broke again getting 403 error from videos on my local pc and on server..

    Example video: https://www.youtube.com/watch?v=GKSRyLdjsPA

    opened by rustynail1984 7
  • 403 Error for Encrypted Videos

    403 Error for Encrypted Videos

    Hi there,

    i think the Signature Decoder is broken, i got on all Encrypted Videos 403 error.

    Example Video: https://www.youtube.com/watch?v=2vjPBrBU-TM

    opened by rustynail1984 7
  • Empty list of links

    Empty list of links

    Hey, I tried updated version but on some videos it return empty array of links. It's missing "url_encoded_fmt_stream_map" is there any way to fix this?

    Thanks.

    opened by thiscodeworks 7
  • Help

    Help

    Hello, i just wanted to know if you can help me install that on my server, i have treid everything installing but it just wont show. can you please please tell me how i can install that on my vps. i have centos 6

    opened by azeekhan1 7
  • Not working in Laravel. Giving error of

    Not working in Laravel. Giving error of "HTTP/1.1 403 Forbidden"

    I am trying to integrate this in my fresh Laravel, but while trying to do file_put_contents(), it gives "HTTP/1.1 403 Forbidden" error. This happens only for some video like https://www.youtube.com/watch?v=xu-cwLqchc0

    opened by msyadav88 6
  • Demo video doesn't work :)

    Demo video doesn't work :)

    Hi, congrats to your fist issue.

    Demo video doesn't work https://www.youtube.com/watch?v=QxsmWxxouIM. I cannot open grabbed links.

    More about encrypted signatures

    https://www.quora.com/How-can-I-make-a-YouTube-video-downloader-web-application-from-scratch

    opened by cristalix 6
  • How to install without Composer

    How to install without Composer

    I copied the src directory, but when I run it I get this error:

    Fatal error: Uncaught Error: Class 'Curl\BrowserClient' not found in /Browser.php:8

    Where can I get Curl\BrowserClient?

    opened by ndsda 5
  • Only Download Audio

    Only Download Audio

    when i share any video link its download only audio.

    $youtube = new YouTubeDownloader();
    
    $download = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=DGWpipnb9eY&t=1s");
    
    if ($download->getAllFormats()) {
            return redirect($download->getFirstCombinedFormat()->url);
     }
    
    opened by sesita 3
  • I can't get this to work!

    I can't get this to work!

    I can't get this to work. Can someone help me by giving me directions? I just want the application to return a json with the url. How can I do it without using composer and leave it functional?

    opened by cryzet 0
  • Get video captions

    Get video captions

    I added the few functions to get the caption links according to my need. I also want to add caption formats but later.

    $downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=aqz-KE-bpKQ");
            
    $captions = $downloadOptions->getAllCaptions();
    
    opened by NumairAwan 0
  • Using Tor as Proxy

    Using Tor as Proxy

    I'm using tor as proxy like this:

    $youtube = new YouTubeDownloader(); $youtube->getBrowser()->setProxy('127.0.0.1:9050'); $downloadOptions = $youtube->getDownloadLinks('https://www.youtube.com/watch?v=e-ORhEE9VVg');

    But I got this error:

    PHP Fatal error: Uncaught YouTube\Exception\YouTubeException: Page failed to load. HTTP error: Received HTTP code 501 from proxy after CONNECT

    is this error from youtube server or else??

    opened by kihanb 0
  • added useful functions to DownloadOptions class

    added useful functions to DownloadOptions class

    // get best combined format by video quality public function getBestCombinedFormat()

    // get best video format by quality public function getBestVideoFormat()

    // get best audio format by quality public function getBestAudioFormat()

    opened by xafable 0
Releases(v3.1.1)
  • v3.1.1(Mar 10, 2022)

  • v3.1.0(Oct 21, 2021)

    • Improved logic for fetching download links that are (usually) not throttled. https://github.com/Athlon1600/youtube-downloader/issues/142
    • Miscellaneous refactoring to make this library more object oriented
    Source code(tar.gz)
    Source code(zip)
  • v3.0.2(Jul 14, 2021)

    • fetching get_video_info is now working again. Something had changed on YouTube's end to break it. https://github.com/Athlon1600/youtube-downloader/pull/120
    • Added support for PHP 8 https://github.com/Athlon1600/youtube-downloader/pull/121
    • Implemented a consentCookies method that allows bypassing cookies consent screen that gets shown to European IPs. https://github.com/Athlon1600/youtube-downloader/issues/125
    Source code(tar.gz)
    Source code(zip)
    youtube-downloader.zip(226.88 KB)
  • v3.0.1(May 24, 2021)

  • v2.1.2(Mar 4, 2021)

    • Update to SignatureDecoder class. Match functions with double quotes in their name. Issue: https://github.com/Athlon1600/youtube-downloader/issues/99
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Feb 27, 2021)

    Lots of code refactoring with many breaking changes, but everything now is much easier to read and understand.
    Some of the major changes:

    • Added a new php-curl-file-downloader dependency. Previous Browser class just duplicated a bunch of the same HTTP logic that I wrote for that library anyways.

    • We're no longer passing arrays back and forth everywhere. That's just a bad programming practice in general. Most of those arrays are now objects. For example: getDownloadLinks method which used to return an array of links, now returns a DownloadOptions object where each "option" is also an object (StreamFormat).

    • getDownloadLinks now throws a YouTubeException if something unexpected happens. Previously it just returned an empty array.
      We will be using Exceptions a lot more instead of just returning false or null as we were doing before.

    • Youtube was renamed to YouTube (capitalized twice) everywhere, because that is just how YouTube itself does it: https://developers.google.com/youtube/v3/code_samples/php

    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Oct 17, 2020)

    • fixed a critical bug where video links were not returned due to improper parsing of player_response JS code that usually appears on /watch?v=XXX page itself.
    • added an alternative way to parse such details for special cases. Solution provided by @julitroalves: https://github.com/Athlon1600/youtube-downloader/issues/73#issuecomment-686552940
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Jul 28, 2020)

    • updated regex pattern for extracting function name used when decoding video signatures. Fixes: https://github.com/Athlon1600/youtube-downloader/issues/68
    Source code(tar.gz)
    Source code(zip)
  • v2.0.9(Jul 22, 2020)

  • v2.0.8(Jul 17, 2020)

    • added ability for underlying browser instance to use a proxy server
    • misc bug fixes regarding non-existing array indices
    • added phpstan.neon.dist
    Source code(tar.gz)
    Source code(zip)
  • v2.0.7(Jun 8, 2020)

    • Fixed issue #57 that had to do with cypher decryption that broke when youtube changed one of the properties inside its code from cipher to signatureCipher
    Source code(tar.gz)
    Source code(zip)
  • v2.0.6(Mar 31, 2020)

    • improved recognition of the types of video/audio links returned by YouTube. All the itag data now comes from:
      https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L429

    • updated README

    • better handling of errors inside demo application

    Source code(tar.gz)
    Source code(zip)
  • v2.0.5(Feb 10, 2020)

  • v2.0.4(Feb 9, 2020)

  • v2.0.3(Feb 5, 2020)

  • v2.0.2(Dec 31, 2019)

    • many videos do not need signature decryption. Deal with such videos in a different way.
    • properly handle exceptions in PHP7 - specifically: DivisionByZeroError
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Dec 31, 2019)

  • v2.0.0(Dec 31, 2019)

  • v1.0.1(Mar 1, 2017)

  • v1.0.0(Dec 28, 2016)

Mira - A lightweight WebUI alternative to top/htop for GNU/Linux.

Mira Mira lets you monitor your server's resource usage through a responsive WebUI. ======== Introduction Screenshots Installation Limitations Known I

Jams246 9 Mar 27, 2022
FreeScout — Free self-hosted help desk & shared mailbox (Zendesk / Help Scout alternative)

Free Self-Hosted Zendesk & Help Scout Alternative FreeScout is the super lightweight free open source help desk and shared inbox written in PHP7+ (Lar

FreeScout 1.8k Jan 2, 2023
The API & platform builder, build your apps 10x faster even more, it's open source & 100% free !

The API & platform builder, build your apps 10x faster, even more. It's open source & 100% free ! Try live demo Why badaso ? 100% FREE - No need for e

Uasoft 1k Jan 2, 2023
A good, non-specialized Laravel base site for faster app development

Larastrap This is a non-specialized Laravel base site containing generalized components for faster development of nearly any type of site. It includes

Memphis PHP 2 Jul 31, 2022
Online All in One PHP Video & Audio Downloader From YouTube,Facebook,Twitter,Pinterest,Instagram,MXtakatak,IPL, Tiktok and 1000+ More Sites too

DLhut Contact me If You Find ANy Bug ... PHP Search and Download any Videos from any site. Online All in One Video & Audio Downloader From YouTube,Fac

Vijay Kumar 4 Nov 8, 2021
Online All in One Video & Audio Downloader From YouTube,Facebook,Twitter,Pinterest,Instagram,MXtakatak,IPL, Tiktok and 1000+ More Sites too

DLhut Contact me If You Find ANy Bug ... PHP Search and Download any Videos from any site. Online All in One Video & Audio Downloader From YouTube,Fac

Vijay Kumar 6 Oct 11, 2021
Belajar laravel 8 via YouTube....

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

null 1 Nov 6, 2021
The forum is a base for our Youtube tutorial series on "how to build a forum"

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

AngelJay 15 Oct 11, 2022
Download YouTube videos in MP4 and MP3 formats easily

Laravel Youtube Downloader Download YouTube videos in MP4 and MP3 formats easily ✨ Demo Install git clone https://github.com/IhsanDevs/LaravelYoutubeD

Ihsan Devs 4 Apr 18, 2022
A Web UI frontend for YouTube-DL

A Web UI frontend for YouTube-DL This is a small project that creates a simple and easy to use user interface for downloading content with YouTube-DL

Alex G 4 Jun 25, 2022
YouTubeClone - Web Projects Build By Laravel Framework v8 & LiveWire it's Small project to upload video Like Youtube

YouTubeClone YouTubeClone - Web Projects Build By Laravel Framework & LiveWire it's Small project to upload video Like Youtube Use Laravel v8.80.0 Ima

Hesham Adel 1 Jan 24, 2022
A Blogging Platform with a built-in Feed Aggregator. Built with AngularJS and Laravel.

ReMark ReMark is an open source publishing platform built with the informed content creator in mind. It works as: A blogging platform A feed aggregato

Ren 4 Nov 1, 2019
A framework for building rich, data-driven applications in PHP and MySQL

Xataface A framework for building rich, data-driven applications in PHP and MySQL License GPL Requirements PHP 5.2 or higher MySQL 5 or higher Install

Steve Hannah 129 Dec 13, 2022
Demo of using geo data in PHP web applications

phpgeo-demo Demo of using geo data in PHP web applications Goals Demonstrate basic data storage and retrieval methods using Geo specific data Orient t

J Corry 2 Jul 10, 2016
Phalcon - Développez des applications web complexes et performantes en PHP

Phalcon - Développez des applications web complexes et performantes en PHP Ce projet GitHub contient les sources du livre : Phalcon 3 - Développez des

Les Enovateurs 3 Jul 5, 2022
QuidPHP/Core is a PHP library that provides an extendable platform to create dynamic applications

QuidPHP/Core About QuidPHP/Core is a PHP library that provides an extendable platform to create dynamic applications. It is part of the QuidPHP packag

QuidPHP 4 Jul 2, 2022
Exploit the vulnerability to install arbitrary applications in k61v1 without ROOT

k61v1injector Arbitrary application installer for Qin F21 Pro Exploit the vulnerability to install arbitrary applications in k61v1 without ROOT. Feel

Jim Wu 14 Nov 10, 2022
DBase - An easy-to-use backend for mobile and web applications

DBase DBase is an easy-to-use backend for your mobile and web applications, host the files in an Ubuntu server and use the SDKs to perform CRUD operat

Frank Eno ~ XSGames 39 May 25, 2022
CollectiveAccess is a web-based suite of applications providing a framework for management, description, and discovery of complex digital

README: Pawtucket2 version 1.7.14 About CollectiveAccess CollectiveAccess is a web-based suite of applications providing a framework for management, d

CollectiveAccess 70 Sep 28, 2022