Search code examples
phppythonyoutube-dl

Setting up youtube-dl on the server to retrieve just the download link


So I'm having problems setting up youtube-dl on my server. Here's the PHP script that calls YoutubeDL.py.

<?php
error_reporting(-1);
$command = "usr/bin/python youtube-dl/YoutubeDL.py --get-url  " . "https://www.youtube.com/watch?v=v4kgeyM7j6Y";

header('Content-Type: text/html; charset=utf-8');
$command = escapeshellcmd($command);
$output = shell_exec($command);
echo $output;
?>

I've set YoutubeDL.py privileges to 777, however I'm not getting any output.


Solution

  • youtube-dl/YoutubeDL.py is an internal file with the main class. It is not sufficient to run. Instead, properly install youtube-dl, using one of the following options:


    install system-wide, for example with sudo pip install youtube-dl. Afterwards, the command to run youtube-dl will be simply youtube-dl.


    Install and run it somewhere else, for example with

    curl https://yt-dl.org/latest/youtube-dl -o ./youtube-dl
    chmod a+rx ./youtube-dl
    

    The command is ./youtube-dl, or, if you leave out the second line, python ./youtube-dl.


    If you want to modify the source, follow the developer instructions. Either download the tarball and unpack it, or use git:

    git clone https://github.com/rg3/youtube-dl.git
    youtube-dl/youtube_dl/__main__.py  # run youtube-dl
    

    Run by executing youtube-dl/youtube_dl/__main__.py, python -m youtube_dl when ./youtube-dl is in your Python PATH, or python youtube-dl/youtube_dl/__main__.py.