w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Download a song directly to visitor's computer using youtube-dl
  1. Download the song (and convert it to mp3) to the server (into an accessible folder) but set the output files name to the identifier from youtube (https://youtube.com/watch?=IDENTIFIER). This way, it won't download the same file twice, when somebody else wants the same one. In PHP you can get it similarly to this:

    $link = $_GET['link']; // This is the Youtube link
    $id = str_replace("https://youtube.com/watch?=", ""); // This will remove
    the youtube link itself
  2. When downloaded, just print out the link to the file.

  3. If you want to save bandwidth, then check if a file with the same identifier already exists. If it does, then just give the user the existing one.

Hope this helps. =)

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.