1. Fetch File Information
There are two formats of 4shared.com’s link download:
Format 1: like:
http://www.4shared.com/file/253231421/73f7da19(/GoodFellas.html)?
http://www.4shared.com/file/246032259/f70f9982(/_online.html)?
Format 2: like:
http://www.4shared.com/video/ABBPbvS8(/Divided_Heart.html)?
()? meaning yes or no
step 1 using regular expression to detect format of link:
with format 1, fileID is 253231421 or 246032259
with format 2, we use API’s function: decodeLink to find fileID
$regexp = "/^http:\/\/(www\.)?4shared\.com\/((file\/(\d+)\/[0-9a-f]+)|([a-z]+\/[0-9a-zA-Z\_\-]+))(\/[^\/]+)?$/";
Format 1:
$url = "http://www.4shared.com/file/253231421/73f7da19/GoodFellas.html"; preg_match($regexp,$url,$m); var_dump($m);
result:
array(7) {
[0]=>
string(62) “http://www.4shared.com/file/253231421/73f7da19/GoodFellas.html”
[1]=>
string(4) “www.”
[2]=>
string(23) “file/253231421/73f7da19”
[3]=>
string(23) “file/253231421/73f7da19”
[4]=>
string(9) “253231421”
[5]=>
string(0) “”
[6]=>
string(16) “/GoodFellas.html”
}
Format 2:
$url = "http://4shared.com/video/ABBPbvS8/Divided_Heart.html"; preg_match($regexp,$url,$m); var_dump($m);
result:
array(7) {
[0]=>
string(52) “http://4shared.com/video/ABBPbvS8/Divided_Heart.html”
[1]=>
string(0) “”
[2]=>
string(14) “video/ABBPbvS8”
[3]=>
string(0) “”
[4]=>
string(0) “”
[5]=>
string(14) “video/ABBPbvS8”
[6]=>
string(19) “/Divided_Heart.html”
}
So, if $m[4]!=”” we use format 1.
Step 2: find fileID:
Warning: catch exception SoapFault
$wsdl = "http://api.4shared.com/jax2/DesktopApp?wsdl"; $a = new SoapClient($wsdl ); try{ $id = $a->decodeLink( "email","pass","http://4shared.com/video/ABBPbvS8/Divided_Heart.html" ); }catch(SoapFault $e){ echo $e->getmessage(); die(); } echo $id;
result:
1340130325
step 3: fetch file’s informations:
we use API’s function: getFileInfo to fetch file’s informations
$info = $a->getFileInfo("email","pass",$id ); var_dump($info);
result:
object(stdClass)#2 (13) {
[“date”]=>
string(20) “2012-04-05T10:40:53Z”
[“directory”]=>
bool(false)
[“downloadCount”]=>
int(0)
[“downloadLink”]=>
string(56) “http://www.4shared.com/video/ABBPbvS8/Divided_Heart.html”
[“empty”]=>
bool(false)
[“id”]=>
int(1340130325)
[“md5”]=>
string(32) “13e5390636037afda502aadd0e5bd542”
[“name”]=>
string(17) “Divided Heart.mp4”
[“parentId”]=>
int(48715715)
[“removed”]=>
bool(false)
[“shared”]=>
bool(false)
[“size”]=>
int(6159739)
[“version”]=>
int(0)
}
2. Fetch File Description
we use API’s function: getFileDescription to fetch file’s description
$description = $a->getFileDescription("email","pass",$id ); var_dump($description);
result:
object(stdClass)#2 (1) {
[“item”]=>
array(3) {
[0]=>
string(0) “”
[1]=>
string(0) “”
[2]=>
string(0) “”
}
}