1

I've got a list of 400 song titles, and have them hyperlinked to the the search results page. Example picture

I've got both youtube-dl and J Downloader, but don't know what parameters I need in youtube-dl to download the high quality mp3 from the list of search URL's on videos? I only want it to download the first video from every search as mp3.

2 Answers2

0

I wrote a Ruby script (wrapper over youtube-dl) which I use to download audio - you can see it here

The code which extracts the audio is:

DESTINATION_PATH="/home/max/Downloads"
URL="https://www.youtube.com/watch?v=cASW7BFWf6U"
cd $DESTINATION_PATH && youtube-dl --extract-audio --prefer-ffmpeg --audio-format mp3 --yes-playlist --audio-quality 3 $URL`

With this you can use your HTML parsing library of choice to get the first video off youtube's search results. I personally have experience with Nokogiri, and from here it seems you can use a command line tool.

For example,

CSS_SELECTOR="#selector_of_the_first_video"
curl -s $URL | nokogiri -e 'puts $_.at_css("$CSS_SELECTOR").text'
max pleaner
  • 26,189
  • 9
  • 66
  • 118
0

Your question doesn't explain what exactly is it that you are trying to do with the rest of your list. Anyway, I'll show you how to get MP3 of first link.

  1. First, separate your URL's with comma (,)
  2. Now fetch the whole file in PHP

    $file = 'path_to_file';
    $data = file_get_contents($file);
    
  3. Turn list into an array

    $songs_list = explode(",", $data);
    
  4. Set count and loop through array

    foreach ($songs_list as $key => $song) {
        if ($count == 1) {
            $commad = 'youtube-dl --extract-audio --audio-format mp3 youtube_video_url_here';
            shell_exec($commad); // now audio of first video will be downloaded as MP3
        } else {
           // do the rest of your work on list
        }
    }
    

    Below goes the complete script

    <?php
        $file = 'path_to_file';
        $data = file_get_contents($file);
        $songs_list = explode(",", $data);
        $count = 1;
        foreach ($songs_list as $key => $song) {
             if ($count == 1) {
                 $commad = 'youtube-dl --extract-audio --audio-format mp3 youtube_video_url_here';
                 shell_exec($commad); // now audio of first video will be downloaded as MP3
             } else {
                 // do the rest of your work on list
             }
       }
    ?>