Decoding the myspace image path

Myspace image paths are pretty simple to decode. It basically takes an image ID number and chops it to pieces and uses those as subdirectories. Now that we have the knowledge of how to decode it we can write scripts to encode an ID back into an image path..

How to decode

Example url http://myspace-604.vo.llnwd.net/00521/40/62/521272604_l.jpg (picture of jeffrey me and jake! cool!)
In this example, 521272604 is the id (http://myspace-604.vo.llnwd.net/00521/40/62/521272604_l.jpg)
We will be using the id to find all of the other numbers in the url.

The first number we'll figure out is the server number the image is pulled from. In this case, 604 is the server number, and to get this all you have to do is take the last 3 digits of the ID. simple! (Turns out the server number doesn't even matter, any number will work)

The next 3 are trickier than the server number, but still pretty simple.

You'll notice that the first directory is 5 numbers long, and in this case its 00521, and 521 happens to be the first 3 digits of our id. Now its not ALWAYS going to be the first 3 digits, after myspace gets its one billionth image it will be the first four digits, after 10 billion first 5 digits. As it stands myspace isn't setup to handle 100 billion photos, but that will never happen, right?

In this case directory 2 is 40, and you'll notice that there is no 40 in our ID. The way they get this is by taking the last 2 digits of our ID and reversing them. wow that was tough.

Directory 3 is similar to 2, except instead of the last 2 its next 2 after that reversed ... was that confusing?

Below are 2 functions, in PHP and Javascript, that will encode an ID into an image path for you. Enjoy!

PHP

function myspace_getimagepath($id){
	$id = strval($id);
	$len = strlen($id);
	$serverid = substr($id,$len-3,3);
	$dir1 = str_pad(substr($id,0,$len-6),5,'0',STR_PAD_LEFT);
	$dir2 = trim($id{$len-1}.$id{$len-2});
	$dir3 = trim($id{$len-3}.$id{$len-4});
	$path = "http://myspace-{$serverid}.vo.llnwd.net/{$dir1}/{$dir2}/{$dir3}/{$id}_l.jpg";
	return $path;

}

Javascript

function myspace_getimagepath(id){
	id = id.toString();
	serverid = id.substr(-3);
	dir1 = id.substr(0,id.length-6);
	while(dir1.length<5) dir1 = '0'+dir1;
	dir2 =  id.substr(-2).split('').reverse().join('');
	dir3 = id.substr(-4).substr(0,2).split('').reverse().join('');
	path = 'http://myspace-'+serverid+'.vo.llnwd.net/'+dir1+'/'+dir2+'/'+dir3+'/'+id+'_l.jpg';
	return (path);
}

And now some random images from myspace

Threadless - Designer tshirts