announce() public method

Getter and setter of torrent announce url / list If the argument is a string, announce url is added to announce list (or set as announce if announce is not set) If the argument is an array/object, set announce url (with first url) and list (if array has more than one url), tiered list supported If the argument is false announce url & list are unset
public announce ( $announce = null ) : string | array | null
return string | array | null announce url / list or null if not set
Beispiel #1
0
             $trackersCount = $trackersCount + 1;
         } else {
             if (count($trackers) > 0) {
                 $announce_list[] = $trackers;
                 $trackers = array();
             }
         }
     }
 }
 if (count($trackers) > 0) {
     $announce_list[] = $trackers;
 }
 $torrent = new Torrent($tname);
 $torrent->clear_announce();
 if (count($announce_list) > 0) {
     $torrent->announce($announce_list[0][0]);
     if ($trackersCount > 1) {
         $torrent->announce_list($announce_list);
     }
 }
 if (isset($request['comment'])) {
     $comment = trim($request['comment']);
     if (strlen($comment)) {
         $torrent->comment($comment);
     }
 }
 if ($request['private']) {
     $torrent->is_private(true);
 }
 $fname = rTask::formatPath($taskNo) . "/result.torrent";
 $torrent->save($fname);
Beispiel #2
0
 $fname = $req->val[0] . $hash . ".torrent";
 if (empty($req->val[0]) || !is_readable($fname)) {
     if (strlen($req->val[2]) && is_readable($req->val[2])) {
         $fname = $req->val[2];
     } else {
         $fname = null;
     }
 }
 if ($fname) {
     $torrent = new Torrent($fname);
     if (!$torrent->errors()) {
         $needToProcessed = true;
         $lst = $torrent->announce_list();
         if (!$lst) {
             if (count($trks->list)) {
                 if ($torrent->announce()) {
                     $torrent->announce_list($trks->addToBegin ? array_merge($trks->list, array(array($torrent->announce()))) : array_merge(array(array($torrent->announce())), $trks->list));
                 } else {
                     $torrent->announce($trks->list[0][0]);
                     $torrent->announce_list($trks->list);
                 }
             } else {
                 $needToProcessed = false;
             }
         } else {
             $addition = $trks->list;
             foreach ($lst as $group) {
                 foreach ($group as $tracker) {
                     $addition = clearTracker($addition, $tracker);
                 }
             }
<?php

require_once 'Torrent.class.php';
// create torrent
$torrent = new Torrent('./torrents', 'http://torrent.tracker/annonce');
if (!($error = $torrent->error())) {
    $torrent->save('test.torrent');
    // save to disk
} else {
    echo '<br>DEBUG: ', $error;
    // error method return the last error message
}
// print torrent info
$torrent = new Torrent('./test.torrent');
echo '<pre>private: ', $torrent->is_private() ? 'yes' : 'no', '<br>annonce: ';
var_dump($torrent->announce());
echo '<br>name: ', $torrent->name(), '<br>comment: ', $torrent->comment(), '<br>piece_length: ', $torrent->piece_length(), '<br>size: ', $torrent->size(2), '<br>hash info: ', $torrent->hash_info(), '<br>stats: ';
var_dump($torrent->scrape());
echo '<br>content: ';
var_dump($torrent->content());
echo '<br>source: ', $torrent;
// modify torrent
$torrent->announce('http://alternate-torrent.tracker/annonce');
// add a tracker
$torrent->announce(false);
// reset announce trackers
$torrent->announce(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce'));
// set tracker(s), it also works with a 'one tracker' array...
$torrent->announce(array(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce'), 'http://another-torrent.tracker/annonce'));
// set tiered trackers
$torrent->comment('hello world');
Beispiel #4
0
 public function download()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_tracker');
     $torrent_id = $this->getState('torrent.id');
     $db = $this->getDbo();
     $user = JFactory::getUser();
     $config = new JConfig();
     if ($user->get('guest') && $params->get('allow_guest') == 0 || !TrackerHelper::user_permissions('download_torrents', $user->id)) {
         echo "<script> alert(\"" . JText::_("COM_TRACKER_USER_CANNOT_DOWNLOAD_TORRENT") . "\"); window.history.go(-1);</script>\n";
         return;
     }
     # Get the total number of records
     $query = $db->getQuery(true);
     $query->select('count(*)');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $total = $db->loadResult();
     if (!$total) {
         echo "<script> alert('" . JText::_('COM_TRACKER_INVALID_TORRENT') . "'); window.history.go(-1);</script>\n";
         return;
     }
     // All OK so far, let's continue
     # Get the torrent
     $query->clear();
     $query->select('*');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $row = $db->loadObjectList();
     $row = $row[0];
     $torrentfile = $row->fid . "_" . $row->filename;
     if (!is_file(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_DOESNT_EXIST') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     if (!is_readable(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_ISNT_READABLE') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     # Get the xbt tracker config
     $query->clear();
     $query->select('name, value');
     $query->from('xbt_config');
     $db->setQuery($query);
     $tracker = $db->loadObjectList('name');
     // ###############################################################################################################################
     // New Torrent pass version use
     // ###############################################################################################################################
     $uid = $user->id;
     $torrent_pass_private_key = $tracker['torrent_pass_private_key']->value;
     # Get the user torrent pass version
     $query->clear();
     $query->select('torrent_pass_version');
     $query->from('#__tracker_users');
     $query->where('id = ' . $user->id);
     $db->setQuery($query);
     $torrent_pass_version = $db->loadResult();
     $torrent = new Torrent(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile);
     // ###############################################################################################################################
     // reset announce trackers
     $torrent->announce(false);
     // Private Torrents
     if ($params->get('make_private') == 1 && !$torrent->is_private()) {
         $torrent->is_private(true);
     }
     // Generate the new torrent passkey from the newly modified torrent
     $torrent_pass = sprintf('%08x%s', $user->id, substr(sha1(sprintf('%s %d %d %s', $torrent_pass_private_key, $torrent_pass_version, $user->id, pack('H*', $torrent->hash_info()))), 0, 24));
     // Check if we have several trackers
     if ($params->get('trackers_address') == '') {
         $announceurl = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
         // adds the default "site" tracker
         $torrent->announce($announceurl);
     } else {
         $trackers_address = explode(",", $params->get('trackers_address'));
         $trackers_address = str_replace(" ", "", $trackers_address);
         for ($i = 0; $i < count($trackers_address); $i++) {
             $other_trackers = 'http://' . $trackers_address[$i] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
             $torrent->announce($other_trackers);
         }
     }
     // Put some comment in the torrent
     $torrent->comment('Torrent downloaded from ' . $config->sitename);
     // If we have tags enabled, put the site name in a Tag and send the torrent filename
     if ($params->get('tag_in_torrent') == 1) {
         $torrent->send('[' . $config->sitename . ']' . $row->name . '.torrent');
     } else {
         $torrent->send();
     }
 }
Beispiel #5
0
function is_torrent($filePath)
{
    $torrent = new Torrent($filePath);
    $isAccepted = $torrent->errors() ? false : true;
    if (!$isAccepted) {
        die("erreurs : <pre>" . print_r($torrent->errors(), true) . "</pre>");
    }
    $isWellFormed = $torrent->name() != null && $torrent->announce() != null;
    return $isAccepted && $isWellFormed;
}