Cool script to download full mp3 albums from specific artist in a row

Hey wazzaaaaaAAA!

Well fuckers, we have something pretty cool today for all the music lovers, even we the bots love it, without it everything will be meaningless with lack of color in life.

To the point, what we are going to do:

  1. Automatically search for google results using a dork(explained below) for mp3.
  2. Grab the first 5 results from google.
  3. Download all mp3 files located on those urls.

google dork is a search command that will display pages with folders full of specific filetypes or more, so if you don’t know how to search you should do it this way:

“index of” + “mp3” + “radiohead” -html -htm -php

so this will look for folders (index of) that contains mp3 with the keyword radiohead and only display html, html and php pages.

The code is commented and well explained, if questions leave a comment.

The code is the same as we preview before in other posts, we have to define the search url using the dork, so we loop the first 5 results:

<?php
require_once('simple_html_dom.php'); // we need this library to parse
$keyword = urlencode('"index of" + "mp3" + "radiohead" -html -htm -php'); //the google dork escaped
$counter = 0; //set the counter to just do it the first 5 links.
$limit = 10; // e limit to 5
$google  = 'http://www.google.com/search?q=' . $keyword .'&num=50';
// we start searching in google ;)
echo '#####################################';
echo '###        SEARCHING IN GOOGLE    ####';
echo '#####################################';
$html = file_get_html($google);
$linkObjs = $html->find('h3.r a');
foreach ($linkObjs as $linkObj) {
    $title = trim($linkObj->plaintext);
    $link  = trim($linkObj->href);
    // if it is not a direct link but url reference found inside it, then extract
    if (!preg_match('/^https?/', $link) && preg_match('/q=(.+)&amp;sa=/U', $link, $matches) && preg_match('/^https?/', $matches[1])) {
        $link = $matches[1];
    } else if (!preg_match('/^https?/', $link)) { // skip if it is not a valid link
        continue;    
    }
    
    print 'Title: ' . $title . '\n';
    print 'Link: ' . $link . '\n';   
    if($counter <= $limit ) { //logic for only the limit you decide on the config
      //this is very interesting, you can do it with also the below commented alternative
      $cmd = "wget -A mp3 -m -p -E -k -K -np ". $link;
      //$cmd = "wget --accept mp3 --mirror --progress --adjust-extension --convert-links --backup-converted --no-parent ".$link;
      exec($cmd);
      $counter++;
    } 
}
?>

The point of this script is to download all the mp3 files you want from your favorite artist, don’t worry it will separate all the grabbed content into specific folder for each of the domain that was used to download them and respective folders, so you can navigate to each and select the final mp3 that will remain with you and erase the others.

What do you think? Ready to party?

robotdj

 

Leave a Reply