[GH-ISSUE #858] YouTube Playlist Audio Download #585

Closed
opened 2026-02-26 02:33:37 +03:00 by kerem · 3 comments
Owner

Originally created by @monstrousmg on GitHub (Nov 21, 2018).
Original GitHub issue: https://github.com/koel/koel/issues/858

I've integrated youtube-dl onto koel and wrote a couple routes and scripts that would enable the mass download of youtube video's audios individually and in mass, and automatically sync the files after download.

If you are interested, I can provide this code to you at no cost along with any development/usage notes.

Originally created by @monstrousmg on GitHub (Nov 21, 2018). Original GitHub issue: https://github.com/koel/koel/issues/858 I've integrated youtube-dl onto koel and wrote a couple routes and scripts that would enable the mass download of youtube video's audios individually and in mass, and automatically sync the files after download. If you are interested, I can provide this code to you at no cost along with any development/usage notes.
kerem 2026-02-26 02:33:37 +03:00
Author
Owner

@decaby7e commented on GitHub (Nov 21, 2018):

Please do! What I'm doing now is using youtube-dl on a per-song basis on my server, which is rather annoying :/

<!-- gh-comment-id:440847640 --> @decaby7e commented on GitHub (Nov 21, 2018): Please do! What I'm doing now is using youtube-dl on a per-song basis on my server, which is rather annoying :/
Author
Owner

@monstrousmg commented on GitHub (Nov 23, 2018):

Sure, here are the instructions for a simple set up. I do recommend finding a structure you're happier with though for namespacing and organization purposes!

  1. composer require norkunas/youtube-dl-php
  2. php artisan make:controller YoutubeController
  3. Add the following routes to api.php:
    a. Route::post('youtube/single/{vid}', 'YoutubeController@download');
    b. Route::post('youtube/bulk', 'YoutubeController@massDownload');
  4. Use the following code in your script:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use YoutubeDl\YoutubeDl;
use YoutubeDl\Exception\CopyrightException;
use YoutubeDl\Exception\NotFoundException;
use YoutubeDl\Exception\PrivateVideoException;

use App\Facades\Media;

class YoutubeController extends Controller
{
    //EX: 
    // Method: POST
    // URL: http://YOURURL.TLD/youtube/single/{vid}
    public function download($vid) {
    	$this->singleDownload($vid);

        Media::sync();

        return 'Processing Complete';
    }

    //EX: 
    // Method: POST
    // URL: http://YOURURL.TLD/api/youtube/bulk
    // List: [ "f8Xx-kL0rcw", "HtcWvsiQkZE", "ci67LphFIFM" ]
    public function massDownload(Request $request) {
    	$list = json_decode($request->input('list'), true);

    	foreach ($list as $key => $song) {
    		echo '<pre>';
    		print_r("Downloading: <a href='https://www.youtube.com/watch?v=".$song."'>https://www.youtube.com/watch?v=".$song."</a>");
    		echo '</pre>';
    		$this->singleDownload($song);
    	}

    	Media::sync();
    	return 'Processed List';
    }

    private function singleDownload($vid) {
    	try {
	    	$dl = new YoutubeDl([
			    'extract-audio' => true,
			    'audio-format' => 'mp3',
			    'audio-quality' => 0, // best
			    'output' => '%(title)s.%(ext)s',
			]);

			$dl->setDownloadPath(storage_path('app/music/audio'));

			$video = $dl->download('https://www.youtube.com/watch?v='.$vid);
    	} catch (Exception $e) {
    		echo '<pre>';
    		print_r("Could not download: <a href='https://www.youtube.com/watch?v=".$vid."'>https://www.youtube.com/watch?v=".$vid."</a>");
    		echo '</pre>';
    	}
    }
}
?>
  1. Look for the comments for a mini tutorial for single downloads and for bulk uploads.
  2. I recommend using postman for the download. For bulk, you'll want to use the parameter 'LIST', with the urls in a JSON array format.
  3. I compile my URLs via creating a playlist, and using a service to get all the URLs and strip them down to just the querystring that is in "v".
    a. Site to get URLs of playlist: http://www.williamsportwebdeveloper.com/FavBackUp.aspx
  4. There is a chance that a video might not download due to a signature error. If you run into this, you simply need to update your youtube-dl package on your server.
  5. It is worth noting that is made more for private listening than anything else. And it may take a few minutes to download a few hundred songs since it isn't sent off to REDIS or a command.
<!-- gh-comment-id:441291858 --> @monstrousmg commented on GitHub (Nov 23, 2018): Sure, here are the instructions for a simple set up. I do recommend finding a structure you're happier with though for namespacing and organization purposes! 1) composer require norkunas/youtube-dl-php 2) php artisan make:controller YoutubeController 3) _Add the following routes to api.php:_ a. Route::post('youtube/single/{vid}', 'YoutubeController@download'); b. Route::post('youtube/bulk', 'YoutubeController@massDownload'); 4) Use the following code in your script: ```php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use YoutubeDl\YoutubeDl; use YoutubeDl\Exception\CopyrightException; use YoutubeDl\Exception\NotFoundException; use YoutubeDl\Exception\PrivateVideoException; use App\Facades\Media; class YoutubeController extends Controller { //EX: // Method: POST // URL: http://YOURURL.TLD/youtube/single/{vid} public function download($vid) { $this->singleDownload($vid); Media::sync(); return 'Processing Complete'; } //EX: // Method: POST // URL: http://YOURURL.TLD/api/youtube/bulk // List: [ "f8Xx-kL0rcw", "HtcWvsiQkZE", "ci67LphFIFM" ] public function massDownload(Request $request) { $list = json_decode($request->input('list'), true); foreach ($list as $key => $song) { echo '<pre>'; print_r("Downloading: <a href='https://www.youtube.com/watch?v=".$song."'>https://www.youtube.com/watch?v=".$song."</a>"); echo '</pre>'; $this->singleDownload($song); } Media::sync(); return 'Processed List'; } private function singleDownload($vid) { try { $dl = new YoutubeDl([ 'extract-audio' => true, 'audio-format' => 'mp3', 'audio-quality' => 0, // best 'output' => '%(title)s.%(ext)s', ]); $dl->setDownloadPath(storage_path('app/music/audio')); $video = $dl->download('https://www.youtube.com/watch?v='.$vid); } catch (Exception $e) { echo '<pre>'; print_r("Could not download: <a href='https://www.youtube.com/watch?v=".$vid."'>https://www.youtube.com/watch?v=".$vid."</a>"); echo '</pre>'; } } } ?> ``` 5) _Look for the comments for a mini tutorial for single downloads and for bulk uploads._ 6) _I recommend using postman for the download. For bulk, you'll want to use the parameter 'LIST', with the urls in a JSON array format._ 7) _I compile my URLs via creating a playlist, and using a service to get all the URLs and strip them down to just the querystring that is in "v"._ a. _Site to get URLs of playlist:_ http://www.williamsportwebdeveloper.com/FavBackUp.aspx 8) _There is a chance that a video might not download due to a signature error. If you run into this, you simply need to update your youtube-dl package on your server_. 9) _It is worth noting that is made more for private listening than anything else. And it may take a few minutes to download a few hundred songs since it isn't sent off to REDIS or a command._
Author
Owner

@phanan commented on GitHub (Apr 22, 2020):

No plan to officially support this feature (copyright and stuff).

<!-- gh-comment-id:617629575 --> @phanan commented on GitHub (Apr 22, 2020): No plan to officially support this feature (copyright and stuff).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/koel-koel#585
No description provided.