Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * ZippyShare Scraper v0.1
- * by _Tobias
- * Usage:
- * $list [an array with full ZippyShare download page links]
- * $dlf [the folder in which the files will be downloaded]
- * Run from CLI please!
- */
- if(php_sapi_name() != 'cli') {
- die('Run this script from CLI!'.PHP_EOL);
- }
- $list = array('http://www53.zippyshare.com/v/8362983/file.html');
- // $list = explode(PHP_EOL, file_get_contents('FileWithNewlineSeperatedLinks.txt'));
- $dlf = 'downloads/';
- if(!is_dir($dlf)) {
- if(!mkdir($dlf)) {
- die("Can't create download folder");
- }
- }
- foreach($list as $v) {
- if(strlen($v) === 0) {
- continue;
- }
- $html = file_get_contents($v);
- // get download url
- if(preg_match('/var a = ([0-9%]+?);/', $html, $matches)) { // with var
- $token = eval('return '.$matches[1].';');
- preg_match('/href = "(.+?)";/', $html, $matches);
- $url = str_replace('"+a+"', $token, $matches[1]);
- }
- else { // without var, older servers
- preg_match('/href = (.+?);/', $html, $matches);
- $url = str_replace(array('"+', '+"'), array('".', '."'), $matches[1]); // + to . for php
- $url = eval('return '.$url.';');
- }
- // get size
- preg_match_all('/<font style=".+?">([0-9]{1}.+?B)<\/font>/', $html, $matches);
- $size = $matches[1][0];
- // get title
- preg_match('/<meta property="og:title" content="(.+?) " \/>/', $html, $matches);
- $title = $matches[1];
- // get server number
- preg_match('/www([0-9]+?)\./', $html, $matches);
- // assemble url
- $url = 'http://www'.$matches[1].'.zippyshare.com'.$url;
- // get session cookie
- $header = '';
- foreach($http_response_header as $h) {
- if(strpos($h, 'Set-Cookie: JSESSIONID=') === 0) {
- preg_match('/JSESSIONID=([A-F0-9]+?);/', $h, $matches);
- $header = 'Cookie: JSESSIONID='.$matches[1];
- }
- }
- // create a context for the download
- $context = stream_context_create(array('http' => array('method' => 'GET', 'header' => $header)));
- // assemble file name
- $fn = $dlf.$no.". ".$title;
- // start download
- if(is_file($fn)) {
- echo 'Skipping '.$title.' ('.$size.')'.PHP_EOL;
- continue;
- }
- else {
- echo 'Downloading '.$title.' ('.$size.')'.PHP_EOL;
- }
- file_put_contents($fn, file_get_contents($url, false, $context));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement