Last active
February 24, 2017 18:38
-
-
Save atmoner/9dd2faef5c5b12a594e4e4e846384073 to your computer and use it in GitHub Desktop.
Torrent dumper for bittytorrent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//error_reporting(E_ERROR); | |
$path = dirname(__FILE__); | |
require_once $path.'/libs/startup.php'; | |
require_once $path.'/libs/class.bdecode.php'; | |
require_once $path.'/libs/class.bencode.php'; // To create info hash of torrent | |
/* | |
// Bitty categorie | |
6 6> Animation/Hentai | |
7 7> Books | |
8 8> DVD | |
9 9> Games | |
10 10> HD Video | |
11 11> Pictures | |
12 12> Video | |
// Torrent group cat | |
34 34> DVD | |
48 48> HD | |
47 47> video | |
51 51 > picture | |
*/ | |
//for ($i=270; $i>1; $i--) { | |
for ($i=10; $i>0; $i--) { | |
$url = 'https://torrentsgroup.com/torrents.php?cat=51&page='.$i; | |
if ($i = 0) { | |
break; | |
} else | |
boot($url); | |
} | |
function boot($url) | |
{ | |
$headers = [ | |
'X-Apple-Tz: 0', | |
'X-Apple-Store-Front: 143444,12', | |
'Accept: text/html', | |
//'Accept-Encoding: gzip, deflate', | |
'Accept-Language: en-US,en;q=0.5', | |
'Cache-Control: no-cache', | |
'Content-Type: application/x-www-form-urlencoded; charset=utf-8', | |
'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0' | |
]; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
if (preg_match('`^https://`i', $url)) | |
{ | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
} | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'); | |
$page_content = curl_exec($ch); | |
$dom = new domDocument; | |
$dom->loadHTML($page_content); | |
//$dom->preserveWhiteSpace = false; | |
$torrents = $dom->getElementsByTagName('a'); | |
// var_dump($page_content); | |
foreach ($torrents as $torrent) { | |
if (preg_match("/torrent/i",$torrent->getAttribute('href')) && | |
!preg_match("/category/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrents-upload.php/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrents-today.php/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrents-search.php/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrentfreak/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrents-needseed.php/i",$torrent->getAttribute('href')) && | |
!preg_match("/torrentsgroup/i",$torrent->getAttribute('href')) && | |
!preg_match("/comments.php/i",$torrent->getAttribute('href')) && | |
!preg_match("/download.php/i",$torrent->getAttribute('href')) | |
) { | |
$entityUrl= $torrent->getAttribute('href'); | |
FunctionName("https://torrentsgroup.com/".$entityUrl); | |
} | |
} | |
} | |
function FunctionName($url) { | |
$path = dirname(__FILE__); | |
$imageUrl = ''; | |
$TorrentUrl = ''; | |
$desc = ''; | |
$html = file_get_contents($url); | |
$dom = new domDocument; | |
$dom->loadHTML($html); | |
$dom->preserveWhiteSpace = false; | |
$torrents = $dom->getElementsByTagName('a'); | |
$imgs = $dom->getElementsByTagName('img'); | |
$descs = $dom->getElementsByTagName('p'); | |
foreach ($torrents as $torrent) { | |
if (preg_match("/download.php/i",$torrent->getAttribute('href'))) { | |
$TorrentUrl = 'https://torrentsgroup.com/'.$torrent->getAttribute('href'); | |
} | |
} | |
//echo $TorrentUrl; | |
$filename = dumpTorrent($TorrentUrl); | |
$torrent = new BDECODE($path."/uploads/torrents/".$filename); | |
$resultTorrent = $torrent->result; | |
$hash = sha1(BEncode($resultTorrent['info'])); | |
rename($path."/uploads/torrents/".$filename, $path."/uploads/torrents/".$hash.".torrent"); | |
// Calcul the total size of content torrent | |
if (isset($resultTorrent["info"]) && $resultTorrent["info"]) $upfile=$resultTorrent["info"]; | |
else $upfile = 0; | |
if (isset($upfile["length"])) { | |
$size = (float)($upfile["length"]); | |
} else if (isset($upfile["files"])) { | |
// multifiles torrent | |
$size=0; | |
foreach ($upfile["files"] as $file) { | |
$size+=(float)($file["length"]); | |
} | |
} else $size = "0"; | |
if (isset($torrent->result['announce-list'])) | |
$announce = $torrent->result['announce-list']; | |
else | |
$announce = $torrent->result['announce']; | |
//var_dump($announce); | |
foreach ($imgs as $img) { | |
if (preg_match("/uploads\/images/i",$img->getAttribute('src'))) | |
$imageUrl = $img->getAttribute('src'); | |
} | |
//echo $imageUrl; | |
$ext = grab_image($imageUrl,$path.'/uploads/images/',$hash); | |
// $descs = $dom->getElementsByTagName('td'); | |
$classname="download"; | |
$finder = new DomXPath($dom); | |
$descs = $finder->query("//*[contains(@class, '$classname')]"); | |
foreach ($descs as $desc) { | |
$desc = $desc->nodeValue; | |
} | |
// echo $desc; | |
addTorrentsql($resultTorrent['info']["name"],$hash,$announce,$size,$ext,$desc); | |
} | |
function addTorrentsql($name,$hash,$announce,$size,$ext,$desc) | |
{ | |
global $db,$startUp; | |
$urlTitle = preg_replace("/[^a-zA-Z0-9]+/", "-", strtolower($name)); | |
// $db->query(); | |
$existetoto = $db->get_row("SELECT id FROM torrents WHERE info_hash = '".$db->escape($hash)."' "); | |
// $db->debug(); | |
if (!$existetoto) { | |
$startUp->addTorrent('1',$name,$urlTitle,'11', $desc,$hash,$announce,$size,$ext); | |
echo 'Ajouter!! <br />'; | |
} else | |
echo 'Doublon! <br />'; | |
} | |
function dumpTorrent($a) { | |
$path = dirname(__FILE__); | |
$save_to = $path.'/uploads/torrents/'; // Set torrent folder for download | |
// var_dump(basename($a)); | |
$filename = str_replace(basename($a), basename($a), basename($a)); | |
$fp = fopen ($save_to.basename($a), 'w+');//This is the file where we save the information | |
$ch = curl_init($a);//Here is the file we are downloading | |
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // Important | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 50); | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
curl_setopt($ch, CURLOPT_HEADER,0); // None header | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); // Binary transfer 1 | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($fp); | |
return basename($a); | |
} | |
function grab_image($url,$saveto,$to){ | |
$ch = curl_init ($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); | |
$raw=curl_exec($ch); | |
curl_close ($ch); | |
$ext = strrchr(basename($url), '.'); | |
$fp = fopen($saveto.$to.$ext,'w+'); | |
fwrite($fp, $raw); | |
fclose($fp); | |
return $ext; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment