//Get files here
$torrentInfo['files'] = $info["file tree"];
foreach ($info["file tree"] as $key => $value) {
$path = $key;
foreach($value as $detail){
$filecount = ++$filecount;
$torrentsize += $detail['length'];
$newfiles[] = [
'path' => $path, // key is important
'length' => $detail['length']
];
}
}
// Replace File Stucture
$torrentInfo['files'] = $newfiles; $hash = hash('sha256', Bencode::encode($info));
$torrentInfo['hash'] = mb_substr($hash, 0, 40);$hash; public function Parse($filename = "")
{
$torrentInfo = array();
$array = array();
//check file type is a torrents
$torrent = explode(".", $filename);
// $fileend = end($torrent);
$fileend = strtolower(end($torrent));
if ($fileend == "torrent") {
$parse = file_get_contents("$filename");
// If Parse Lets Read It
if (!isset($parse)) {
Redirect::autolink(URLROOT, Lang::T("Error Getting Torrent file"));
} else {
// Decode File Array
$array = Bencode::decode($parse);
// If Array Lets Read It
if ($array === false) {
Redirect::autolink(URLROOT, Lang::T("Unable to decode file."));
} else {
if (array_key_exists("info", $array) === false) {
Redirect::autolink(URLROOT . "/index", Lang::T("Error opening torrent.<br>"));
} else {
//Get Announce URL
$torrentInfo['announce'] = $array["announce"];
//Get Announce List Array
if (isset($array["announce-list"])) {
$torrentInfo["announce-list"] = $array["announce-list"];
}
// Calculates date from UNIX Epoch
$torrentInfo["creation date"] = date('r', $array["creation date"]);
//Get torrents comment
if (isset($array['comment'])) {
$torrentInfo['comment'] = $array['comment'];
}
// Read info - files
$info = $array["info"];
// The name of the torrents is different to the file name
$torrentInfo['name'] = $info['name'];
// Calculate Size/Count
$filecount = 0;
$torrentsize = 0;
// Get file list
if (isset($info["files"]) && is_array($info["files"])) {
// Calculates SHA1 Hash
$torrentInfo['hash'] = hash('sha1', Bencode::encode($info));
// Return Marker To identify as v1
$torrentInfo['type'] = '1';
//Get files here
$torrentInfo['files'] = $info["files"];
foreach ($info["files"] as $file) {
$filecount = ++$filecount;
$torrentsize += $file['length'];
}
$torrentInfo['length'] = $torrentsize;
$torrentInfo['ttfilecount'] = $filecount;
} elseif (isset($info["file tree"]) && is_array($info["file tree"])) {
// Calculates SHA256 Hash
$torrentInfo['hash'] = hash('sha256', Bencode::encode($info));
// Return Marker To identify as v2
$torrentInfo['type'] = '2';
//Get files here
$torrentInfo['files'] = $info["file tree"];
//$torrentInfo['files'] = array("path"=>$info["file tree"], "length"=>$info["file tree"][$torrentInfo['name']][$torrentInfo['length']]);
foreach ($info["file tree"] as $key => $value) {
$test = array_flatten($torrentInfo['files']);
$filecount = ++$filecount;
$torrentsize += $test['length'];
$newfiles[] = [
'path' => array($key),
'length' => $test['length']
];
}
// Replace File Stucture
$torrentInfo['files'] = $newfiles;
$torrentInfo['length'] = $torrentsize;
$torrentInfo['ttfilecount'] = $filecount;
} else {
// Single File Torrent
$torrentInfo['name'] = $info['name'];
$torrentInfo['length'] = $info['length'];
$torrentInfo['ttfilecount'] = 1;
}
}
}
}
}
return $torrentInfo;
//var_dump($torrentInfo);
}//convert multi to single array
function array_flatten($array) {
if (!is_array($array)) {
return FALSE;
}
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = array_merge($result, array_flatten($value));
}
else {
$result[$key] = $value;
}
}
return $result;
} // Target File
$torrent_dir = UPLOADDIR."/torrents/2.torrent";
// Lets Get Contents
$parse = file_get_contents($torrent_dir);
// If Parse Lets Read It
if (!isset($parse)) {
Redirect::autolink(URLROOT, Lang::T("Error Getting Torrent file"));
} else {
// Decode File Array
$array = Bencode::decode($parse);
// If Array Lets Read It
if ($array === false) {
Redirect::autolink(URLROOT, Lang::T("Unable to decode file."));
} else {
if (array_key_exists("info", $array) === false) {
Redirect::autolink(URLROOT . "/index", Lang::T("Error opening torrent.<br>"));
} else {
//Get Announce URL
$torrentInfo['announce'] = $array["announce"];
//Get Announce List Array
if (isset($array["announce-list"])) {
$torrentInfo["announce-list"] = $array["announce-list"];
}
// Calculates date from UNIX Epoch
$torrentInfo["creation date"] = date('r', $array["creation date"]);
//Get torrents comment
if (isset($array['comment'])) {
$torrentInfo['comment'] = $array['comment'];
}
// Read info - files
$info = $array["info"];
// The name of the torrents is different to the file name
$torrentInfo['name'] = $info['name'];
// Calculate Size/Count
$filecount = 0;
$torrentsize = 0;
// Get file list
if (isset($info["files"]) && is_array($info["files"])) {
// Calculates SHA1 Hash
$torrentInfo['hash'] = hash('sha1', Bencode::encode($info));
// Return Marker To identify as v1
$torrentInfo['type'] = '1';
//Get files here
$torrentInfo['files'] = $info["files"];
foreach ($info["files"] as $file) {
$filecount = ++$filecount;
$torrentsize += $file['length'];
}
$torrentInfo['length'] = $torrentsize;
$torrentInfo['ttfilecount'] = $filecount;
} elseif (isset($info["file tree"]) && is_array($info["file tree"])) {
// Calculates SHA256 Hash
$torrentInfo['hash'] = hash('sha256', Bencode::encode($info));
// Return Marker To identify as v2
$torrentInfo['type'] = '2';
//Get files here
$torrentInfo['files'] = $info["file tree"][$torrentInfo['name']];
foreach ($info["file tree"][$torrentInfo['name']] as $file) {
$filecount = ++$filecount;
$torrentsize += $file['length'];
}
$torrentInfo['length'] = $torrentsize;
$torrentInfo['ttfilecount'] = $filecount;
} else {
// Single File Torrent
$torrentInfo['name'] = $info['name'];
$torrentInfo['length'] = $info['length'];
$torrentInfo['ttfilecount'] = 1;
}
echo 'so heres the return parse function<br>';
echo '<pre>' , print_r($torrentInfo) , '</pre><br>';
}
}
}Quote:array(6) {
["announce"]=> string(27) "http://example.com/announce"
["hash"]=> string(40) "c14199bbec64d0e9e439aa3b6b7639e666b86eca"
["creation date"]=> string(31) "Sat, 15 Jan 2022 07:44:49 +0100"
["name"]=> string(7) "test64K"
["length"]=> int(65536)
["ttfilecount"]=> int(1)
}
INSERT INTO `torrents` (`id`, `info_hash`, `name`, `filename`, `save_as`, `descr`, `image1`, `image2`, `category`, `size`, `added`, `type`, `numfiles`, `comments`, `views`, `hits`, `times_completed`, `leechers`, `seeders`, `last_action`, `visible`, `banned`, `owner`, `anon`, `numratings`, `ratingsum`, `nfo`, `announce`, `external`, `torrentlang`, `freeleech`, `tube`, `tmdb`, `uplreq`, `sticky`, `vip`, `announcelist`, `filelist`) VALUES
(2, 'c14199bbec64d0e9e439aa3b6b7639e666b86eca', 'test64K', '2.torrent', '2.torrent', 'test', NULL, NULL, 45, 65536, '2022-01-15 06:36:43', 'single', 1, 0, 0, 0, 0, 0, 0, '2022-01-15 06:36:43', 'yes', 'no', 1, 'no', 0, 0, 'no', 0x687474703a2f2f6578616d706c652e636f6d2f616e6e6f756e6365, 'yes', 0, '0', NULL, NULL, 'no', 'no', '', 'b:0;', 'b:0;');
$torrent_dir = "uploads/2.torrent";Quote:Uncaught Exception: 2022-01-14 20:16:26 - SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'size' cannot be null in file /global/torrent1/app/libraries/DB.php on line 39
Call Stack
[0] File: /global/torrent1/app/libraries/DB.php Line: 39
Function: PDOStatement->execute
Call parameters
Param[0]: Passed value: array (
0 => 'Wind\'s.mp3.torrent',
1 => '1',
2 => 'Wind\'s.mp3',
3 => 0,
4 => 'test v2',
5 => NULL,
6 => NULL,
7 => 18,
8 => NULL,
9 => '2022-01-14 20:16:26',
10 => 'c22e5f3b13ce8e230a6c3b0775fb83c9a524f91d',
11 => NULL,
12 => 1,
13 => 'Wind\'s.mp3.torrent',
14 => 'https://torrenttrader.uk/announce.php',
15 => 'no',
16 => 'no',
17 => 0,
18 => 'no',
19 => '2022-01-14 20:16:26',
20 => 0,
21 => NULL,
22 => NULL,
23 => 'b:0;',
)
echo '<br><br>v2 torrent<br><br>';
$torrent_dir = UPLOADDIR."/torrents/2.torrent";
$test = Bencode::load($torrent_dir);
var_dump($test);
echo '<br><br>another v2 torrent<br><br>';
$torrent_dir = UPLOADDIR."/torrents/16.torrent";
$test = Bencode::load($torrent_dir);
var_dump($test);
echo '<br><br>original v1 torrent<br><br>';
$torrent_dir = UPLOADDIR."/torrents/1.torrent";
$test = Bencode::load($torrent_dir);
var_dump($test); $pvkey_var = "v_".$id;
$views = $_SESSION[$pvkey_var] == 1 ? $row["views"] + 0 : $row["views"] + 1;
$_SESSION[$pvkey_var] = 1;
DB::update('torrents', ['views'=>$views], ['id'=>$id]); kiki2020:in forum the QUOTE reply not work ! sort only [quote=] , pseudo is blank
;extension=sockets /*
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
*/