Torrent::content PHP Method

content() public method

List torrent content
public content ( $precision = null ) : array
return array file(s) and size(s) list, files as keys and sizes as values
    public function content($precision = null)
    {
        $files = array();
        if (isset($this->info['files']) && is_array($this->info['files'])) {
            foreach ($this->info['files'] as $file) {
                $files[self::path($file['path'], $this->info['name'])] = $precision ? self::format($file['length'], $precision) : $file['length'];
            }
        } elseif (isset($this->info['name'])) {
            $files[$this->info['name']] = $precision ? self::format($this->info['length'], $precision) : $this->info['length'];
        }
        return $files;
    }

Usage Example

Beispiel #1
0
 private function getFileInformation($hash)
 {
     $shrinkWrap = $this->shrinkWrapper;
     $results = $shrinkWrap->query("SELECT SQL_NO_CACHE * FROM  `file_info` WHERE  `torrent_hash` = '{$hash}'");
     if (empty($results)) {
         $torrentFile = "C:/xampp/htdocs/apps/strike/torrents/api/download/" . $hash . ".torrent";
         $torrentTitle = $value["torrent_title"];
         if (!file_exists($torrentFile)) {
             $remoteTorrent = "http://torcache.net/torrent/{$hash}.torrent";
             $file_headers = @get_headers($file);
             if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                 $exists = false;
             } else {
                 $this->downloadFile($remoteTorrent, "C:/xampp/htdocs/apps/strike/torrents/api/download/" . $hash . ".torrent");
             }
         }
         $torrent = new Torrent($torrentFile);
         $file_names = array_keys($torrent->content());
         $file_lengths = array_values($torrent->content());
         $fileNameRecord = "";
         $fileLengthRecord = "";
         foreach ($file_names as &$value) {
             $fileNameRecord .= strlen($fileNameRecord) == 0 ? trim($value) : ", " . trim($value);
         }
         foreach ($file_lengths as &$value) {
             $fileLengthRecord .= strlen($fileLengthRecord) == 0 ? trim($value) : ", " . trim($value);
         }
         if (strpos($fileNameRecord, 'xampp') !== false) {
             $fileNameRecord = "Error";
         }
         $lengthArray = json_decode('[' . $fileLengthRecord . ']', true);
         $nameArray = explode(',', $fileNameRecord);
         $fileData = array(file_names => $nameArray, file_lengths => $lengthArray);
         $fileNameRecord = $this->shrinkWrapper->escape($fileNameRecord);
         $fileLengthRecord = $this->shrinkWrapper->escape($fileLengthRecord);
         $insertFileNames = $shrinkWrap->query("REPLACE into file_info (torrent_hash, file_names, file_sizes) values(\"{$hash}\", \"{$fileNameRecord}\", \"{$fileLengthRecord}\")");
         return $fileData;
     } else {
         $fileLengthRecord = $results[0]["file_sizes"];
         $fileNameRecord = $results[0]["file_names"];
         if (strpos($fileNameRecord, 'xampp') !== false) {
             $fileNameRecord = "Error";
         }
         $lengthArray = json_decode('[' . $fileLengthRecord . ']', true);
         $nameArray = explode(',', $fileNameRecord);
         $fileData = array(file_names => $nameArray, file_lengths => $lengthArray);
         return $fileData;
     }
 }
All Usage Examples Of Torrent::content