mirror of
https://github.com/torrentpier/torrentpier.git
synced 2024-11-21 04:50:19 -08:00
001c210217
* Minor improvements * Update CHANGELOG.md * Update filelist.php * Update ffprobe_info.php * Updated * Update announce.php * Update announce.php * Update ffprobe_info.php * Updated * Update ffprobe_info.php * Update ffprobe_info.php * Updated * Update common.php * Update common.php * Revert "Update common.php" This reverts commit3793263ff0
. * Revert "Update common.php" This reverts commit3911e72dba
. * Update common.php * Updated * Update playback_m3u.tpl * Update ffprobe_info.php * Update playback_m3u.php * Update dl.php * Update dl.php * Updated * Update dl.php * Update playback_m3u.php * Revert "Update playback_m3u.php" This reverts commit8cf6e9a041
. * Revert "Update dl.php" This reverts commit7c11cc385b
. * Revert "Updated" This reverts commit9c004f0651
. * Revert "Update dl.php" This reverts commit26d5feffa5
. * Revert "Update dl.php" This reverts commit261f8d3e62
. * Update playback_m3u.php * Updated * Update dl.php * Update dl.php * Update CHANGELOG.md
144 lines
4.8 KiB
PHP
144 lines
4.8 KiB
PHP
<?php
|
||
/**
|
||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||
*
|
||
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
|
||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||
*/
|
||
|
||
if (!defined('IN_AJAX')) {
|
||
die(basename(__FILE__));
|
||
}
|
||
|
||
global $bb_cfg, $lang;
|
||
|
||
if (!$bb_cfg['torr_server']['enabled']) {
|
||
$this->ajax_die($lang['MODULE_OFF']);
|
||
}
|
||
|
||
$attach_id = $this->request['attach_id'] ?? '';
|
||
if (empty($attach_id) || !is_numeric($attach_id)) {
|
||
$this->ajax_die($lang['INVALID_ATTACH_ID']);
|
||
}
|
||
|
||
$file_index = $this->request['file_index'] ?? '';
|
||
if (empty($file_index) || !is_numeric($file_index)) {
|
||
$this->ajax_die("Invalid file index: $file_index");
|
||
}
|
||
|
||
if (!$info_hash = (string)$this->request['info_hash'] or !ctype_xdigit($info_hash)) {
|
||
$this->ajax_die("Invalid info_hash: $info_hash");
|
||
}
|
||
|
||
$isAudio = !empty($this->request['is_audio']);
|
||
|
||
// Get ffprobe info from TorrServer
|
||
$ffpInfo = (new \TorrentPier\TorrServerAPI())->getFfpInfo($info_hash, $file_index, $attach_id);
|
||
$ffpInfo = $ffpInfo->{$file_index};
|
||
if (isset($ffpInfo->streams)) {
|
||
// Video codec information
|
||
$videoCodecIndex = array_search('video', array_column($ffpInfo->streams, 'codec_type'));
|
||
if (is_int($videoCodecIndex)) {
|
||
$videoCodecInfo = $ffpInfo->streams[$videoCodecIndex];
|
||
}
|
||
// Audio codec information
|
||
$audioTracks = array_filter($ffpInfo->streams, function ($e) {
|
||
return $e->codec_type === 'audio';
|
||
});
|
||
// Audio tracks information
|
||
$audioDub = array_map(function ($stream) {
|
||
global $lang;
|
||
|
||
$result = '<span class="warnColor2">' . sprintf($lang['AUDIO_TRACK'], (!isset($stream->index) || $stream->index === 0) ? 1 : $stream->index) . '</span><br>';
|
||
if (isset($stream->tags->language)) {
|
||
if (isset($stream->tags->title)) {
|
||
$result .= '<b>' . mb_strtoupper($stream->tags->language, 'UTF-8') . ' (' . $stream->tags->title . ')' . '</b>';
|
||
} else {
|
||
$result .= '<b>' . mb_strtoupper($stream->tags->language, 'UTF-8') . '</b>';
|
||
}
|
||
$result .= '<br>';
|
||
}
|
||
|
||
if (!empty($stream->codec_name)) {
|
||
$result .= sprintf($lang['AUDIO_CODEC'], $stream->codec_long_name, mb_strtoupper($stream->codec_name, 'UTF-8')) . '<br>';
|
||
}
|
||
if (!empty($stream->bit_rate) && is_int($stream->bit_rate)) {
|
||
$result .= sprintf($lang['BITRATE'], humn_bitrate($stream->bit_rate)) . '<br>';
|
||
}
|
||
if (!empty($stream->sample_rate) && is_int($stream->sample_rate)) {
|
||
$result .= sprintf($lang['SAMPLE_RATE'], humn_sample_rate($stream->sample_rate)) . '<br>';
|
||
}
|
||
if (!empty($stream->channels)) {
|
||
$result .= sprintf($lang['CHANNELS'], $stream->channels) . '<br>';
|
||
}
|
||
if (!empty($stream->channel_layout)) {
|
||
$result .= sprintf($lang['CHANNELS_LAYOUT'], $stream->channel_layout);
|
||
}
|
||
|
||
return $result;
|
||
}, $audioTracks);
|
||
|
||
// Generate output data
|
||
$data = [
|
||
'filesize' => sprintf($lang['FILESIZE'] . ': <b>%s</b>', humn_size($ffpInfo->format->size)),
|
||
'resolution' => (!$isAudio && isset($videoCodecInfo)) ? sprintf($lang['RESOLUTION'], $videoCodecInfo->width . 'x' . $videoCodecInfo->height) : '',
|
||
'video_codec' => (!$isAudio && isset($videoCodecInfo->codec_name)) ? sprintf($lang['VIDEO_CODEC'], $videoCodecInfo->codec_long_name, mb_strtoupper($videoCodecInfo->codec_name, 'UTF-8')) : '',
|
||
'audio_dub' => implode('<hr>', $audioDub)
|
||
];
|
||
|
||
// Validate output data
|
||
$result = '<hr>';
|
||
if (!empty($data['resolution'])) {
|
||
$result .= $data['resolution'] . '<br>';
|
||
}
|
||
if (!empty($data['filesize'])) {
|
||
$result .= $data['filesize'] . '<br>';
|
||
}
|
||
if (!empty($data['video_codec'])) {
|
||
$result .= $data['video_codec'];
|
||
}
|
||
if (!empty($data['audio_dub'])) {
|
||
$result .= '<hr>' . $data['audio_dub'];
|
||
}
|
||
|
||
$this->response['ffprobe_data'] = $result;
|
||
}
|
||
|
||
/**
|
||
* Bitrate to human-readable format
|
||
*
|
||
* @param int $bitrate
|
||
* @param string $space
|
||
* @return string
|
||
*/
|
||
function humn_bitrate(int $bitrate, string $space = ' '): string
|
||
{
|
||
if ($bitrate >= 1000000) {
|
||
$unit = 'Mbps';
|
||
$bitrate /= 1000000;
|
||
} elseif ($bitrate >= 1000) {
|
||
$unit = 'kbps';
|
||
$bitrate /= 1000;
|
||
} else {
|
||
$unit = 'bps';
|
||
}
|
||
|
||
return sprintf('%d', commify($bitrate)) . $space . $unit;
|
||
}
|
||
|
||
/**
|
||
* Sample rate to human-readable format
|
||
*
|
||
* @param int $sample_rate
|
||
* @param string $space
|
||
* @return string
|
||
*/
|
||
function humn_sample_rate(int $sample_rate, string $space = ' '): string
|
||
{
|
||
$unit = '';
|
||
return sprintf('%.1f', commify($sample_rate)) . $space . $unit;
|
||
}
|
||
|
||
$this->response['file_index'] = $file_index;
|