1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Programming' started by rodvan, Dec 5, 2016.

  1. rodvan

    rodvan Jr. VIP Jr. VIP

    Joined:
    Jul 27, 2010
    Messages:
    1,321
    Likes Received:
    505
    Occupation:
    developer, marketing, automation, machine learning
    Location:
    Wizard of Bots
    Home Page:
    Well people, I 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.

    [​IMG]

    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.
    A 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:

    Code:
    “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:
    Code:
    ?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=(.+)&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?

    [​IMG]
     
    • Thanks Thanks x 1
  2. MikeyMikey13

    MikeyMikey13 Supreme Member

    Joined:
    May 25, 2014
    Messages:
    1,411
    Likes Received:
    389
    Nice share, will test it later.
     
  3. Yogesh1998

    Yogesh1998 Regular Member

    Joined:
    May 24, 2014
    Messages:
    302
    Likes Received:
    117
    Gender:
    Male
    Occupation:
    Student
    Location:
    India
    Home Page:
    Nice share man!
    I also use something similar to download movies/shows. I just type in index of "keyword" and the first few results usually are the folders having the required content.
    Works great!
     
  4. Smm seller

    Smm seller BANNED BANNED

    Joined:
    Aug 17, 2016
    Messages:
    80
    Likes Received:
    0
    Gender:
    Female
    Thanks mate :)
     
  5. shadow2015

    shadow2015 Junior Member

    Joined:
    Jan 17, 2015
    Messages:
    112
    Likes Received:
    14
    Occupation:
    L2 Security Engineer (Network)
    Location:
    London UK
    hahah, I always use YT, but this is handy, at I will be able to check my Focal/Naim

    thank you
     
  6. comet07

    comet07 Newbie

    Joined:
    Dec 19, 2016
    Messages:
    1
    Likes Received:
    0
    Gender:
    Male
    Home Page:
    thank you bro
     
  7. webtrance86

    webtrance86 Newbie

    Joined:
    Dec 2, 2016
    Messages:
    16
    Likes Received:
    1
    Gender:
    Male
    Location:
    United States
    Great its very help full Thanks