This commit is contained in:
Roman Kelesidis 2024-09-16 22:04:07 +07:00
commit 9c004f0651
2 changed files with 110 additions and 97 deletions

33
dl.php
View file

@ -18,9 +18,14 @@ $datastore->enqueue([
'cat_forums'
]);
$download_id = request_var('id', 0);
$download_id = request_var('id', '');
$thumbnail = request_var('thumb', 0);
$m3u = request_var('m3u', 0);
// Check M3U download mode
$is_m3u = false;
if (str_starts_with($download_id, \TorrentPier\TorrServerAPI::M3U['prefix'])) {
$is_m3u = true;
}
// Send file to browser
function send_file_to_browser($attachment, $upload_dir)
@ -89,6 +94,7 @@ if ($attach_config['disable_mod'] && !IS_ADMIN) {
bb_die($lang['ATTACHMENT_FEATURE_DISABLED']);
}
if (!$is_m3u) {
$sql = 'SELECT * FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int)$download_id;
if (!($result = DB()->sql_query($sql))) {
@ -101,15 +107,9 @@ if (!($attachment = DB()->sql_fetchrow($result))) {
$attachment['physical_filename'] = basename($attachment['physical_filename']);
if ($thumbnail) {
// Re-define $attachment['physical_filename'] for thumbnails
if ($thumbnail) {
$attachment['physical_filename'] = THUMB_DIR . '/t_' . $attachment['physical_filename'];
} elseif ($m3u) {
// Check m3u file exist
if (!$m3uFile = (new \TorrentPier\TorrServerAPI())->getM3UPath($m3u)) {
bb_die($lang['ERROR_NO_ATTACHMENT']);
}
$attachment['physical_filename'] = basename($m3uFile);
}
DB()->sql_freeresult($result);
@ -201,13 +201,26 @@ if (isset($download_mode[$attachment['extension']])) {
}
// Update download count
if ((!$m3u && !$thumbnail) && is_file(realpath($upload_dir . '/' . $attachment['physical_filename']))) {
if (!$thumbnail && is_file(realpath($upload_dir . '/' . $attachment['physical_filename']))) {
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int)$attachment['attach_id'];
if (!DB()->sql_query($sql)) {
bb_die('Could not update attachment download count');
}
}
} else {
$download_mode = INLINE_LINK;
$attachment = [];
// Check m3u file exist
if (!$m3uFile = (new \TorrentPier\TorrServerAPI())->getM3UPath((int)str_replace(\TorrentPier\TorrServerAPI::M3U['prefix'], '', $download_id))) {
bb_die($lang['ERROR_NO_ATTACHMENT']);
}
$attachment['physical_filename'] = $attachment['real_filename'] = basename($m3uFile);
$attachment['mimetype'] = mime_content_type($m3uFile);
$attachment['extension'] = str_replace('.', '', \TorrentPier\TorrServerAPI::M3U['extension']);
}
// Determine the 'presenting'-method
switch ($download_mode) {

View file

@ -99,7 +99,7 @@ foreach ($m3uData as $entry) {
'IS_VALID' => in_array($getExtension, array_merge($validFormats['audio'], $validFormats['video'])),
'IS_AUDIO' => in_array($getExtension, $validFormats['audio']),
'STREAM_LINK' => $streamLink,
'M3U_DL_LINK' => PLAYBACK_M3U_URL . $topic_id . '&dl_m3u=1',
'M3U_DL_LINK' => DL_URL . \TorrentPier\TorrServerAPI::M3U['prefix'] . $topic_id,
'TITLE' => $title,
]);
}