feat: Add option to use original torrent filenames for downloads (#2064)

* feat: Add option to use original torrent filenames for downloads

* Update displaying_torrent.php
This commit is contained in:
Roman Kelesidis 2025-07-30 10:14:00 +03:00 committed by GitHub
commit 07399fc00d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 7 deletions

View file

@ -66,6 +66,7 @@ $tracker_status = $attachments['_' . $post_id][$i]['tracker_status'];
$download_count = declension((int)$attachments['_' . $post_id][$i]['download_count'], 'times'); $download_count = declension((int)$attachments['_' . $post_id][$i]['download_count'], 'times');
$tor_file_size = humn_size($attachments['_' . $post_id][$i]['filesize']); $tor_file_size = humn_size($attachments['_' . $post_id][$i]['filesize']);
$tor_file_time = bb_date($attachments['_' . $post_id][$i]['filetime']); $tor_file_time = bb_date($attachments['_' . $post_id][$i]['filetime']);
$real_filename = clean_filename(basename($attachments['_' . $post_id][$i]['real_filename']));
$tor_reged = (bool)$tracker_status; $tor_reged = (bool)$tracker_status;
$show_peers = (bool)$bb_cfg['bt_show_peers']; $show_peers = (bool)$bb_cfg['bt_show_peers'];
@ -88,11 +89,15 @@ if ($tor_auth_reg || $tor_auth_del) {
$tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url; $tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url;
} }
if ($bb_cfg['tracker']['use_real_filename']) {
$display_name = $real_filename;
} else {
if ($bb_cfg['tracker']['use_old_torrent_name_format']) { if ($bb_cfg['tracker']['use_old_torrent_name_format']) {
$display_name = '[' . $bb_cfg['server_name'] . '].t' . $bt_topic_id . '.' . TORRENT_EXT; $display_name = '[' . $bb_cfg['server_name'] . '].t' . $bt_topic_id . '.' . TORRENT_EXT;
} else { } else {
$display_name = $t_data['topic_title'] . ' [' . $bb_cfg['server_name'] . '-' . $bt_topic_id . ']' . '.' . TORRENT_EXT; $display_name = $t_data['topic_title'] . ' [' . $bb_cfg['server_name'] . '-' . $bt_topic_id . ']' . '.' . TORRENT_EXT;
} }
}
if (!$tor_reged) { if (!$tor_reged) {
$template->assign_block_vars('postrow.attach.tor_not_reged', [ $template->assign_block_vars('postrow.attach.tor_not_reged', [

View file

@ -747,7 +747,8 @@ $bb_cfg['tracker'] = [
'hybrid_stat_protocol' => 1, // For hybrid torrents there are two identical requests sent by clients, for counting stats we gotta choose one, you can change this to '2' in future, when v1 protocol is outdated 'hybrid_stat_protocol' => 1, // For hybrid torrents there are two identical requests sent by clients, for counting stats we gotta choose one, you can change this to '2' in future, when v1 protocol is outdated
'disabled_v1_torrents' => false, // disallow registration of v1-only torrents, for future implementations where client will use v2 only and there won't be need for v1, thus relieving tracker 'disabled_v1_torrents' => false, // disallow registration of v1-only torrents, for future implementations where client will use v2 only and there won't be need for v1, thus relieving tracker
'disabled_v2_torrents' => false, // disallow registration of v2-only torrents 'disabled_v2_torrents' => false, // disallow registration of v2-only torrents
'use_old_torrent_name_format' => false, // when enabled, the names of torrent files will have the classic format: [yoursite.com].txxx.torrent 'use_real_filename' => false, // Use original torrent filename for downloads. If disabled, filename will be generated automatically
'use_old_torrent_name_format' => false, // Use classic filename format '[yoursite.com].txxx.torrent'. Only works when use_real_filename is disabled
]; ];
// Ratio settings // Ratio settings

View file

@ -644,11 +644,16 @@ class Torrent
// Send torrent // Send torrent
$output = Bencode::encode($tor); $output = Bencode::encode($tor);
$real_filename = clean_filename(basename($attachment['real_filename']));
if ($bb_cfg['tracker']['use_real_filename']) {
$dl_fname = $real_filename;
} else {
if ($bb_cfg['tracker']['use_old_torrent_name_format']) { if ($bb_cfg['tracker']['use_old_torrent_name_format']) {
$dl_fname = '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.' . TORRENT_EXT; $dl_fname = '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.' . TORRENT_EXT;
} else { } else {
$dl_fname = html_ent_decode($topic_title) . ' [' . $bb_cfg['server_name'] . '-' . $topic_id . ']' . '.' . TORRENT_EXT; $dl_fname = html_ent_decode($topic_title) . ' [' . $bb_cfg['server_name'] . '-' . $topic_id . ']' . '.' . TORRENT_EXT;
} }
}
if (!empty($_COOKIE['explain'])) { if (!empty($_COOKIE['explain'])) {
$out = "attach path: $filename<br /><br />"; $out = "attach path: $filename<br /><br />";