From c0cdcff48825ce5fb0c89c0ec44eb95686aee74c Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Wed, 23 Apr 2025 23:57:03 +0700 Subject: [PATCH] feat(magnet): Added `xl` (eXact Length) parametr (#1883) --- composer.lock | 4 ++-- library/attach_mod/displaying_torrent.php | 2 +- library/includes/functions.php | 17 +++++++++++------ tracker.php | 2 +- viewforum.php | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 94753599d..9b095995c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a906f822bca0d03bee43a9efe8529350", + "content-hash": "291864741a4c19d097861853d529836c", "packages": [ { "name": "arokettu/bencode", @@ -3741,7 +3741,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.1 | ^8.2 | ^8.3 | ^8.4" + "php": ">=8.1" }, "platform-dev": {}, "plugin-api-version": "2.6.0" diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 0af704a52..a8dda29f1 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -149,7 +149,7 @@ if ($tor_reged && $tor_info) { // Magnet link $user_passkey = \TorrentPier\Legacy\Torrent::getPasskey($bt_user_id); - $tor_magnet = create_magnet($tor_info['info_hash'], $tor_info['info_hash_v2'], $user_passkey, html_ent_decode($t_data['topic_title'])); + $tor_magnet = create_magnet($tor_info['info_hash'], $tor_info['info_hash_v2'], $user_passkey, html_ent_decode($t_data['topic_title']), $tor_size); // ratio limits $min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor']; diff --git a/library/includes/functions.php b/library/includes/functions.php index 2eaf182dc..ead1f5fb8 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1811,14 +1811,14 @@ function decode_text_match($txt) /** * Create magnet link * - * @param string $infohash - * @param string $infohash_v2 - * @param string $auth_key - * @param string $name - * + * @param string $infohash (xt=urn:btih) + * @param string $infohash_v2 (xt=urn:btmh:1220) + * @param string $auth_key (tr) + * @param string $name (dn) + * @param int|string $length (xl) * @return string */ -function create_magnet(string $infohash, string $infohash_v2, string $auth_key, string $name): string +function create_magnet(string $infohash, string $infohash_v2, string $auth_key, string $name, int|string $length = 0): string { global $bb_cfg, $images, $lang; @@ -1847,6 +1847,11 @@ function create_magnet(string $infohash, string $infohash_v2, string $auth_key, $magnet .= 'xt=urn:btmh:1220' . bin2hex($infohash_v2); } + $length = (int)$length; + if ($length > 0) { + $magnet .= '&xl=' . $length; + } + return ''; } diff --git a/tracker.php b/tracker.php index 3675f7375..2e94615b9 100644 --- a/tracker.php +++ b/tracker.php @@ -713,7 +713,7 @@ if ($allowed_forums) { $s_last = $tor['seeder_last_seen']; $att_id = $tor['attach_id']; $size = $tor['size']; - $tor_magnet = create_magnet($tor['info_hash'], $tor['info_hash_v2'], \TorrentPier\Legacy\Torrent::getPasskey($user_id), html_ent_decode($tor['topic_title'])); + $tor_magnet = create_magnet($tor['info_hash'], $tor['info_hash_v2'], \TorrentPier\Legacy\Torrent::getPasskey($user_id), html_ent_decode($tor['topic_title']), $size); $compl = $tor['complete_count']; $dl_sp = $dl ? humn_size($dl, min: 'KB') . '/s' : '0 KB/s'; $ul_sp = $ul ? humn_size($ul, min: 'KB') . '/s' : '0 KB/s'; diff --git a/viewforum.php b/viewforum.php index fa281dfcd..a8e17b581 100644 --- a/viewforum.php +++ b/viewforum.php @@ -468,7 +468,7 @@ foreach ($topic_rowset as $topic) { ]); if (isset($topic['tor_size'])) { - $tor_magnet = create_magnet($topic['info_hash'], $topic['info_hash_v2'], $topic['auth_key'], html_ent_decode($topic['topic_title'])); + $tor_magnet = create_magnet($topic['info_hash'], $topic['info_hash_v2'], $topic['auth_key'], html_ent_decode($topic['topic_title']), $topic['tor_size']); $template->assign_block_vars('t.tor', [ 'SEEDERS' => (int)$topic['seeders'],