Sat, 30th Aug 2008 08:59:17
Never fear, this site is here

#Download music from songza

Author: AtnNn
Tue, 15th Apr 2008 22:10:40
Filed under: Coding, Music, Website.
Songza is a popular website that allows you to listen to almost any song instantly. Most of the songs are MP3 files, but there doesn't seem to be a way to download them. Some of the results are youtube videos, but the videos are invisible, only the music plays. Let's fix that.

A quick look at the source code tells us that it finds the url of the songs using an AJAX query and then it passes it to the loadSong function. Here is the code (re-indented by me):

function setSound(songID){
  source=songID.substring(0,4);
  if(source==YT_SOURCE_ID||!in_array(source,SOURCES)){
    if(source!=YT_SOURCE_ID){
      ytID=songID;
      songID=YT_SOURCE_ID+"-"+songID;
      source=YT_SOURCE_ID;
    }else{
      ytID=songID.substring(5);
    }
    $.get('/a/finder',{v:ytID},
      function(data){
        code=data.match("&t=(.*?)&")[1];
        title=data.match("&title=(.*?)';")[1];
        title=eval('"'+title+'"');
        url="http://youtube.com/get_video?video_id="+ytID+"%26t="+code;
        SOURCE_DISC_URL=URL_DISC+title;
        SOURCE_BUY_URL=URL_BUY+title;
        SOURCE_IS_CC=false;
        loadSong(url,title,songID,'flv');
      });
  }else{
    $.getJSON('/a/song',{z:songID},
      function(data){
        title=data.title;
        url=data.url;
        if(data.url_buy){
          SOURCE_BUY_URL=data.url_buy;
          SOURCE_DISC_URL=data.url_discography;
          if(data.cc==1)
            SOURCE_IS_CC=true;
          else
             SOURCE_IS_CC=false;
        }else{
          SOURCE_DISC_URL=URL_DISC+title;
          SOURCE_BUY_URL=URL_BUY+title;
          SOURCE_IS_CC=false;
        }
        loadSong(url,title,songID,'mp3');
      });
  }
}


Instead of writing our own sript to query songza and get the song url, we can just change the loadSong function by using a bookmarklet. Let's have it create a link to every song we try to play:

function(url,t,s,ty){
  document.getElementById('search').innerHTML+=
    '<br><a href="' + url + '">' + url + '</a>';
}


Add the bookmarklet to your bookmarks and open it after going on songza. Instead of playing the songs you choose, a direct link will appear.

Enjoy!
There are no comments on this post. Make one

Stumble Upon REDDIT Digg! del.icio.us

Powered by Debian, Jack Daniels, Guinness, and excessive quantities of caffeine and sugar.