Update update.js

This commit is contained in:
Aleksandr Statciuk 2022-06-09 02:56:50 +03:00
parent b46e41f181
commit f53cd8bf5d
1 changed files with 15 additions and 12 deletions

View File

@ -27,10 +27,11 @@ async function updateStreams(items = [], results = {}, origins = {}) {
stream.set('status', { status }) stream.set('status', { status })
if (result.streams.length) { if (result.streams.length) {
const { width, height, bitrate } = parseMediaInfo(result.streams) const { width, height, bitrate, frame_rate } = parseMediaInfo(result.streams)
stream.set('width', { width }) stream.set('width', { width })
stream.set('height', { height }) stream.set('height', { height })
stream.set('bitrate', { bitrate }) stream.set('bitrate', { bitrate })
stream.set('frame_rate', { frame_rate })
} }
if (result.requests.length) { if (result.requests.length) {
@ -124,19 +125,21 @@ function findOrigin(requests = [], origins = {}) {
function parseMediaInfo(streams) { function parseMediaInfo(streams) {
streams = streams.filter(s => s.codec_type === 'video') streams = streams.filter(s => s.codec_type === 'video')
streams = _.orderBy( streams = streams.map(s => {
streams, s.bitrate = s.tags && s.tags.variant_bitrate ? parseInt(s.tags.variant_bitrate) : 0
['height', s => (s.tags && s.tags.variant_bitrate ? parseInt(s.tags.variant_bitrate) : 0)], s.frame_rate = parseFrameRate(s.r_frame_rate)
['desc', 'desc']
)
const data = _.head(streams) return s
if (data) { })
const bitrate = data.tags && data.tags.variant_bitrate ? parseInt(data.tags.variant_bitrate) : 0 streams = _.orderBy(streams, ['height', 'bitrate'], ['desc', 'desc'])
return { width: data.width, height: data.height, bitrate }
return _.head(streams) || {}
} }
return {} function parseFrameRate(r_frame_rate = '0/0') {
let parts = r_frame_rate.split('/')
return parseInt(parts[0])
} }
function parseStatus(error) { function parseStatus(error) {