diff --git a/library/ajax/ffprobe_info.php b/library/ajax/ffprobe_info.php index c408c28cb..2fcb73dee 100644 --- a/library/ajax/ffprobe_info.php +++ b/library/ajax/ffprobe_info.php @@ -29,8 +29,61 @@ if (!$info_hash = (string)$this->request['info_hash']) { $this->ajax_die('Invalid info_hash'); } -dump($attach_id); -dump($file_index); -dump($info_hash); +$isAudio = (bool)$this->request['is_audio']; -$this->response['ffprobe_data'] = '123'; +// Get ffprobe info from TorrServer +$ffpInfo = (new \TorrentPier\TorrServerAPI())->getFfpInfo($info_hash, $file_index, $attach_id); +$ffpInfo = $ffpInfo->{$filesCount}; +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'; + }); + $audioDub = array_map(function ($stream) { + global $lang; + + $result = '' . sprintf($lang['AUDIO_TRACK'], (!isset($stream->index) || $stream->index === 0) ? 1 : $stream->index) . '
'; + if (isset($stream->tags->language)) { + if (isset($stream->tags->title)) { + $result .= '' . mb_strtoupper($stream->tags->language, 'UTF-8') . ' (' . $stream->tags->title . ')' . ''; + } else { + $result .= '' . mb_strtoupper($stream->tags->language, 'UTF-8') . ''; + } + $result .= '
'; + } + + if (!empty($stream->codec_name)) { + $result .= sprintf($lang['AUDIO_CODEC'], mb_strtoupper($stream->codec_name, 'UTF-8')) . '
'; + } + if (!empty($stream->bit_rate)) { + $result .= sprintf($lang['BITRATE'], humn_bitrate($stream->bit_rate)) . '
'; + } + if (!empty($stream->sample_rate)) { + $result .= sprintf($lang['SAMPLE_RATE'], $stream->sample_rate) . '
'; + } + if (!empty($stream->channels)) { + $result .= sprintf($lang['CHANNELS'], $stream->channels) . '
'; + } + if (!empty($stream->channel_layout)) { + $result .= sprintf($lang['CHANNELS_LAYOUT'], $stream->channel_layout); + } + + return $result; + }, $audioTracks); + + $template->assign_block_vars('m3ulist.ffprobe', [ + 'FILESIZE' => sprintf($lang['FILESIZE'] . ': %s', 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'], mb_strtoupper($videoCodecInfo->codec_name, 'UTF-8')) : '', + 'AUDIO_DUB' => implode('
', $audioDub) + ]); +} + +$this->response['ffprobe_data'] = ' + +'; diff --git a/playback_m3u.php b/playback_m3u.php index 121c5778f..ce42899eb 100644 --- a/playback_m3u.php +++ b/playback_m3u.php @@ -94,59 +94,6 @@ foreach ($m3uData as $entry) { 'M3U_DL_LINK' => $m3uFile, 'TITLE' => $title, ]); - - // Get ffprobe info from TorrServer - $ffpInfo = (new \TorrentPier\TorrServerAPI())->getFfpInfo($row['info_hash'] ?? $row['info_hash_v2'], $filesCount, $row['attach_id']); - $ffpInfo = $ffpInfo->{$filesCount}; - 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'; - }); - $audioDub = array_map(function ($stream) { - global $lang; - - $result = '' . sprintf($lang['AUDIO_TRACK'], (!isset($stream->index) || $stream->index === 0) ? 1 : $stream->index) . '
'; - if (isset($stream->tags->language)) { - if (isset($stream->tags->title)) { - $result .= '' . mb_strtoupper($stream->tags->language, 'UTF-8') . ' (' . $stream->tags->title . ')' . ''; - } else { - $result .= '' . mb_strtoupper($stream->tags->language, 'UTF-8') . ''; - } - $result .= '
'; - } - - if (!empty($stream->codec_name)) { - $result .= sprintf($lang['AUDIO_CODEC'], mb_strtoupper($stream->codec_name, 'UTF-8')) . '
'; - } - if (!empty($stream->bit_rate)) { - $result .= sprintf($lang['BITRATE'], humn_bitrate($stream->bit_rate)) . '
'; - } - if (!empty($stream->sample_rate)) { - $result .= sprintf($lang['SAMPLE_RATE'], $stream->sample_rate) . '
'; - } - if (!empty($stream->channels)) { - $result .= sprintf($lang['CHANNELS'], $stream->channels) . '
'; - } - if (!empty($stream->channel_layout)) { - $result .= sprintf($lang['CHANNELS_LAYOUT'], $stream->channel_layout); - } - - return $result; - }, $audioTracks); - - $template->assign_block_vars('m3ulist.ffprobe', [ - 'FILESIZE' => sprintf($lang['FILESIZE'] . ': %s', 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'], mb_strtoupper($videoCodecInfo->codec_name, 'UTF-8')) : '', - 'AUDIO_DUB' => implode('
', $audioDub) - ]); - } } // Generate output diff --git a/styles/templates/default/playback_m3u.tpl b/styles/templates/default/playback_m3u.tpl index d2ed11a43..29cf25edb 100644 --- a/styles/templates/default/playback_m3u.tpl +++ b/styles/templates/default/playback_m3u.tpl @@ -1,12 +1,13 @@

{PAGE_TITLE}

@@ -32,7 +33,7 @@ {m3ulist.TITLE}
- {L_SHOW_MORE_INFORMATION_FILE} + {L_SHOW_MORE_INFORMATION_FILE}

{m3ulist.ffprobe.RESOLUTION}