diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 9af5e74a3..c1534b4d8 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -397,12 +397,15 @@ class Torrent } // Getting multi-peers + $external_seeders = $external_leechers = 0; if ($bb_cfg['tracker']['multitracker']['enabled']) { - $torrent = \Arokettu\Torrent\TorrentFile::loadFromString($file_contents); - $announcers = $torrent->getAnnounceList()->toArray(); + $tor['announce-list'] = array_merge(array_column($tor['announce-list'], 0), [$tor['announce']]); + $announcers = array_unique($tor['announce-list'], SORT_REGULAR); $multiTracker = new MultiTracker([ bin2hex($info_hash ?? $info_hash_v2) - ], $announcers[0]); + ], $announcers); + $external_seeders = $multiTracker->seeders; + $external_leechers = $multiTracker->leechers; } if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " $info_hash_where LIMIT 1")) { @@ -454,8 +457,8 @@ class Torrent $size = sprintf('%.0f', (float)$totallen); - $columns = 'info_hash, info_hash_v2, post_id, poster_id, topic_id, forum_id, attach_id, size, reg_time, tor_status'; - $values = "'$info_hash_sql', '$info_hash_v2_sql', $post_id, $poster_id, $topic_id, $forum_id, $attach_id, '$size', $reg_time, $tor_status"; + $columns = 'info_hash, info_hash_v2, post_id, poster_id, topic_id, forum_id, attach_id, size, reg_time, tor_status, ext_seeders, ext_leechers'; + $values = "'$info_hash_sql', '$info_hash_v2_sql', $post_id, $poster_id, $topic_id, $forum_id, $attach_id, '$size', $reg_time, $tor_status, $external_seeders, $external_leechers"; $sql = "INSERT INTO " . BB_BT_TORRENTS . " ($columns) VALUES ($values)"; diff --git a/src/MultiTracker.php b/src/MultiTracker.php index 7f9212e1e..90c904fb0 100644 --- a/src/MultiTracker.php +++ b/src/MultiTracker.php @@ -15,9 +15,28 @@ namespace TorrentPier; */ class MultiTracker { + public int $leechers; + public int $seeders; + public function __construct(array $infoHashes, array $trackers) { $scraper = new Scraper(); - $info = $scraper->scrape($infoHashes, $trackers); + $announcerInfo = $scraper->scrape($infoHashes, $trackers); + + $seeders = $leechers = 0; + if (!$scraper->hasErrors()) { + foreach ($infoHashes as $infoHash) { + $announcerInfo = $announcerInfo[$infoHash]; + $seeders = $announcerInfo['seeders']; + $leechers = $announcerInfo['leechers']; + } + } else { + dump($scraper->getErrors()); + } + + //dd([$seeders, $leechers]); + + $this->leechers = $leechers; + $this->seeders = $seeders; } }