feat(magnet): Added xl (eXact Length) parametr (#1883)

This commit is contained in:
Roman Kelesidis 2025-04-23 23:57:03 +07:00 committed by GitHub
parent 04b0a477d3
commit c0cdcff488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 11 deletions

4
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a906f822bca0d03bee43a9efe8529350", "content-hash": "291864741a4c19d097861853d529836c",
"packages": [ "packages": [
{ {
"name": "arokettu/bencode", "name": "arokettu/bencode",
@ -3741,7 +3741,7 @@
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.1 | ^8.2 | ^8.3 | ^8.4" "php": ">=8.1"
}, },
"platform-dev": {}, "platform-dev": {},
"plugin-api-version": "2.6.0" "plugin-api-version": "2.6.0"

View file

@ -149,7 +149,7 @@ if ($tor_reged && $tor_info) {
// Magnet link // Magnet link
$user_passkey = \TorrentPier\Legacy\Torrent::getPasskey($bt_user_id); $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 // ratio limits
$min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor']; $min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor'];

View file

@ -1811,14 +1811,14 @@ function decode_text_match($txt)
/** /**
* Create magnet link * Create magnet link
* *
* @param string $infohash * @param string $infohash (xt=urn:btih)
* @param string $infohash_v2 * @param string $infohash_v2 (xt=urn:btmh:1220)
* @param string $auth_key * @param string $auth_key (tr)
* @param string $name * @param string $name (dn)
* * @param int|string $length (xl)
* @return string * @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; 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); $magnet .= 'xt=urn:btmh:1220' . bin2hex($infohash_v2);
} }
$length = (int)$length;
if ($length > 0) {
$magnet .= '&xl=' . $length;
}
return '<a title="' . ($v2_support ? $lang['MAGNET_v2'] : $lang['MAGNET']) . '" href="' . $magnet . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . "?{$bb_cfg['passkey_key']}=$auth_key") . '&dn=' . urlencode($name) . '"><img src="' . ($v2_support ? $images['icon_magnet_v2'] : $images['icon_magnet']) . '" width="12" height="12" border="0" /></a>'; return '<a title="' . ($v2_support ? $lang['MAGNET_v2'] : $lang['MAGNET']) . '" href="' . $magnet . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . "?{$bb_cfg['passkey_key']}=$auth_key") . '&dn=' . urlencode($name) . '"><img src="' . ($v2_support ? $images['icon_magnet_v2'] : $images['icon_magnet']) . '" width="12" height="12" border="0" /></a>';
} }

View file

@ -713,7 +713,7 @@ if ($allowed_forums) {
$s_last = $tor['seeder_last_seen']; $s_last = $tor['seeder_last_seen'];
$att_id = $tor['attach_id']; $att_id = $tor['attach_id'];
$size = $tor['size']; $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']; $compl = $tor['complete_count'];
$dl_sp = $dl ? humn_size($dl, min: 'KB') . '/s' : '0 KB/s'; $dl_sp = $dl ? humn_size($dl, min: 'KB') . '/s' : '0 KB/s';
$ul_sp = $ul ? humn_size($ul, min: 'KB') . '/s' : '0 KB/s'; $ul_sp = $ul ? humn_size($ul, min: 'KB') . '/s' : '0 KB/s';

View file

@ -468,7 +468,7 @@ foreach ($topic_rowset as $topic) {
]); ]);
if (isset($topic['tor_size'])) { 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', [ $template->assign_block_vars('t.tor', [
'SEEDERS' => (int)$topic['seeders'], 'SEEDERS' => (int)$topic['seeders'],