• Stars
    star
    776
  • Rank 58,561 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📺 PHP based alternative to youtube-dl and yt-dlp. Active and frequently updated! ⭐

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 public

Previous versions

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

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.

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:

#25 (comment)

Other Links

To-do list

  • Allow downloading of private videos.
  • Find a way to get around YouTube's throttling system that limits downloading speed to less than 100 kb/s for most most videos now...
  • 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.

More Repositories

1

php-proxy-app

Web Proxy Application built on php-proxy library ready to be installed on your server
PHP
816
star
2

php-proxy

A web proxy script written in PHP and built as an alternative to Glype.
PHP
293
star
3

notepad

📄 Web-based application for storing notes securely. Built with Vue + Node.js + Express
JavaScript
128
star
4

SerpScraper

🔎 Google/Bing search results scraping using PHP. Tested and working / May 13, 2020
PHP
89
star
5

win32gui

A tiny, header-only, Win32 API wrapper library that assists in building native GUI components for Windows platform.
C++
42
star
6

php-curl-file-downloader

⭐ Download large files using PHP and cURL
PHP
23
star
7

nginx-rtmp-server

📺 Build your own video streaming site using nginx-rtmp module.
TypeScript
20
star
8

php-proxy-plugin-bundle

PHP-Proxy Plugins made for unblockvideos.com
PHP
19
star
9

php-proxy-installer

Install PHP-Proxy app on your server with a one-line command
Shell
16
star
10

php-curl-client

A very simple curl client - less than 100 lines. Perfect for being a base class.
PHP
13
star
11

useful

👍 Useful shell scripts in one place
Shell
8
star
12

chat

💬 Chat application written in TypeScript with a Vue frontend
TypeScript
7
star
13

php-proxy-plugin-cache

Provides caching support for PHP-Proxy application
PHP
6
star
14

php-cookie-parser

🍪 Convert between various cookie formats
PHP
6
star
15

php-proxy-headers

PHP-based proxy judge script in a single file
PHP
5
star
16

vnstat-php

📊 Super simple status page for vnstat using PHP.
PHP
5
star
17

azenv

AZ Environment variables 1.04
PHP
4
star
18

ie_proxy

A tiny C++ library that makes it easy to change proxy settings
C++
4
star
19

php-captcha-solver

solve captchas using 2captcha.com
PHP
4
star
20

vnstat-limit

Automatically manage and limit your bandwidth consumption to avoid overcharges
Shell
3
star
21

http_request

A simple, header-only C++ library for making HTTP requests
C++
2
star
22

country.proxynova.com

Super simple Web Service used to determine client's country of origin.
1
star