Browse Source

Support announce-list for old style torrent blobs

spaghetti 8 years ago
parent
commit
8d3b95ac3c
3 changed files with 10 additions and 12 deletions
  1. 3
    4
      classes/bencodetorrent.class.php
  2. 4
    8
      classes/torrent.class.php
  3. 3
    0
      classes/torrentsdl.class.php

+ 3
- 4
classes/bencodetorrent.class.php View File

122
    * Add the announce URL to a torrent
122
    * Add the announce URL to a torrent
123
    */
123
    */
124
   public static function add_announce_url($Data, $Url) {
124
   public static function add_announce_url($Data, $Url) {
125
-    return 'd8:announce'.strlen($Url).':'.$Url . substr($Data, 1);
125
+    return 'd8:announce'.strlen($Url).':'.$Url.substr($Data, 1);
126
   }
126
   }
127
 
127
 
128
   /**
128
   /**
129
-   * Let's support announce lists
129
+   * Add list of announce URLs to a torrent
130
    */
130
    */
131
   public static function add_announce_list($Data, $Urls) {
131
   public static function add_announce_list($Data, $Urls) {
132
     $r = 'd13:announce-listl';
132
     $r = 'd13:announce-listl';
137
       }
137
       }
138
       $r .= 'e';
138
       $r .= 'e';
139
     }
139
     }
140
-    $r .= 'e' .substr($Data, 1);
141
-    return $r;
140
+    return $r.'e'.substr($Data, 1);
142
   }
141
   }
143
 }
142
 }

+ 4
- 8
classes/torrent.class.php View File

236
     return base64_encode(serialize($this->Val));
236
     return base64_encode(serialize($this->Val));
237
   }
237
   }
238
 
238
 
239
-  /*
240
-  To use this, please remove the announce-list unset in make_private and be sure to still set_announce_url for backwards compatibility
241
-  function set_multi_announce() {
242
-    $Trackers = func_get_args();
243
-    $AnnounceList = new BENCODE_LIST(array(),true);
244
-    foreach ($Trackers as $Tracker) {
245
-      $SubList = new BENCODE_LIST(array($Tracker),true);
239
+  function set_announce_list($UrlsList) {
240
+    $AnnounceList = new BENCODE_LIST(array(), true);
241
+    foreach ($UrlsList as $Urls) {
242
+      $SubList = new BENCODE_LIST($Urls, true);
246
       unset($SubList->Str);
243
       unset($SubList->Str);
247
       $AnnounceList->Val[] = $SubList;
244
       $AnnounceList->Val[] = $SubList;
248
     }
245
     }
249
     $this->Val['announce-list'] = $AnnounceList;
246
     $this->Val['announce-list'] = $AnnounceList;
250
   }
247
   }
251
-  */
252
 
248
 
253
   function set_announce_url($Announce) {
249
   function set_announce_url($Announce) {
254
     $this->Val['announce'] = $Announce;
250
     $this->Val['announce'] = $Announce;

+ 3
- 0
classes/torrentsdl.class.php View File

239
     $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
239
     $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
240
     $Tor->set_announce_url($AnnounceURL);
240
     $Tor->set_announce_url($AnnounceURL);
241
     unset($Tor->Val['announce-list']);
241
     unset($Tor->Val['announce-list']);
242
+    if (!empty($AnnounceList)) {
243
+      $Tor->set_announce_list($AnnounceList);
244
+    }
242
     unset($Tor->Val['url-list']);
245
     unset($Tor->Val['url-list']);
243
     unset($Tor->Val['libtorrent_resume']);
246
     unset($Tor->Val['libtorrent_resume']);
244
     return $Tor->enc();
247
     return $Tor->enc();

Loading…
Cancel
Save