Вопрос такой. Хочу сделать что-то вроде музыкального торрент трекера. Скажите, посоветуйте - если есть какие нибудь библиотеки, классы для работы с торент файлами. В общих чертах, я хочу вытащить из торрента количество сидеров, личеров, размер файлов и т.п. Если есть - подскажите пожалуйста и заодно просветите как ей (библиотекой, классом) пользоваться. Спс :roll:
а поискать? PHP: <?php class TorrentFile { var $index; var $source; var $final_array; function handler() { $char = $this->source[$this->index]; if (is_numeric($char)) return $this->handler_string(); if ($char == 'i') { ++$this->index; return $this->handler_int(); } if ($char=='l') { ++$this->index; return $this->handler_list(); } if ($char=='d') { ++$this->index; return $this->handler_dictonary(); } die("MAIN HANDLER: UNEXPECTED CHAR (position: $this->index): ".$char); } function handler_int() { $current_char=''; $number = ""; while (($current_char = $this->source[$this->index]) != 'e') { ++$this->index; $number .= $current_char; } ++$this->index; return (int) $number; } function handler_string(){ $size =""; while($this->source[$this->index] != ':') { $size .= $this->source[$this->index]; ++$this->index; } $i = ++$this->index; $this->index += $size; $x= substr($this->source, $i, $size); return $x; } function handler_list() { $return_list = array(); while ($this->source[$this->index] != 'e') { $this->index1 = $this->index; $return_list[] = $this->handler(); if ($this->index1 == $this->index) die("INFINITE LOOP IN THE LIST"); } ++$this->index; return $return_list; } function handler_dictonary() { $return_dict = array(); while ($this->source[$this->index] != 'e') { $this->index1 = $this->index; $return_dict[$this->handler_string()] = $this->handler(); if ($this->index1 == $this->index) die("INFINITE LOOP IN THE DICTONARY"); } ++$this->index; return $return_dict; } function parse_file($filename) { $this->source = file_get_contents($filename); $this->index = 0; $filesize = strlen($this->source); $this->final_array=array(); while($this->index<$filesize) { $this->index1 = $this->index; $this->final_array[] =$this->handler(); if ($this->index1 == $this->index) die("INFINITE LOOP IN THE ROOT LIST"); } $this->source = ''; return $this->final_array; } } header("Content-type: text/plain; charset=UTF-8"); $x = new TorrentFile(); print_r($x->parse_file("EpicFail.torrent"));
Vladson вот числа для файла 16гб PHP: echo (int)$number."\n"; даже если превысит лимит int он просто превратится во float и будет дальше работать, нет разве?
Оо круто - спасибо. Но чтот я не нашел какой элемент массива вытаскивает количество сидеров и личеров. Подскажите пожалуйста.
solistcomru Этого момента тут и быть не может. Прежде чем делать трекер лучше побольше узнайте о том как он работает...
http://wiki.theory.org/BitTorrentSpecification (англ.яз) Переводы скорее всего есть, но где не знаю, и знать не хочу...