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,11 +122,11 @@ class BencodeTorrent extends BencodeDecode {
122 122
    * Add the announce URL to a torrent
123 123
    */
124 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 131
   public static function add_announce_list($Data, $Urls) {
132 132
     $r = 'd13:announce-listl';
@@ -137,7 +137,6 @@ class BencodeTorrent extends BencodeDecode {
137 137
       }
138 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,19 +236,15 @@ class TORRENT extends BENCODE_DICT {
236 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 243
       unset($SubList->Str);
247 244
       $AnnounceList->Val[] = $SubList;
248 245
     }
249 246
     $this->Val['announce-list'] = $AnnounceList;
250 247
   }
251
-  */
252 248
 
253 249
   function set_announce_url($Announce) {
254 250
     $this->Val['announce'] = $Announce;

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

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

Loading…
Cancel
Save