Update database/update.js
This commit is contained in:
parent
ce46e88939
commit
512885b251
@ -1,5 +1,4 @@
|
||||
const { db, store, parser, file, logger } = require('../../core')
|
||||
const statuses = require('../../data/statuses')
|
||||
const _ = require('lodash')
|
||||
|
||||
const items = []
|
||||
@ -80,8 +79,8 @@ async function updateStreams(items = [], results = {}, origins = {}) {
|
||||
if (result) {
|
||||
const { error, streams, requests } = result
|
||||
|
||||
const { is_online } = parseError(error)
|
||||
stream.set('is_online', { is_online })
|
||||
const status = parseStatus(error)
|
||||
stream.set('status', { status })
|
||||
|
||||
if (streams.length) {
|
||||
const { width, height, bitrate } = parseStreams(streams)
|
||||
@ -136,28 +135,28 @@ function parseStreams(streams) {
|
||||
streams = streams.filter(s => s.codec_type === 'video')
|
||||
streams = _.orderBy(
|
||||
streams,
|
||||
['height', s => (s.tags.variant_bitrate ? parseInt(s.tags.variant_bitrate) : 0)],
|
||||
['height', s => (s.tags && s.tags.variant_bitrate ? parseInt(s.tags.variant_bitrate) : 0)],
|
||||
['desc', 'desc']
|
||||
)
|
||||
|
||||
const data = _.head(streams)
|
||||
if (data) {
|
||||
const bitrate = data.tags.variant_bitrate ? parseInt(data.tags.variant_bitrate) : 0
|
||||
const bitrate = data.tags && data.tags.variant_bitrate ? parseInt(data.tags.variant_bitrate) : 0
|
||||
return { width: data.width, height: data.height, bitrate }
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
|
||||
function parseError(error) {
|
||||
const output = {
|
||||
is_online: true,
|
||||
message: error
|
||||
}
|
||||
function parseStatus(error) {
|
||||
if (!error) return 'online'
|
||||
|
||||
if (error && !error.includes('403')) {
|
||||
output.is_online = false
|
||||
switch (error) {
|
||||
case 'Operation timed out':
|
||||
return 'timeout'
|
||||
case 'Server returned 403 Forbidden (access denied)':
|
||||
return 'blocked'
|
||||
default:
|
||||
return 'error'
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{"title":"ЛДПР ТВ","channel":"LDPRTV.ru","filepath":"tests/__data__/output/channels/ru.m3u","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"2ST8btby3mmsgPF0","is_online":false}
|
||||
{"title":"BBC News HD","channel":"BBCNews.uk","filepath":"tests/__data__/output/channels/uk.m3u","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http_referrer":null,"user_agent":null,"cluster_id":3,"_id":"3TbieV1ptnZVCIdn","is_online":true}
|
||||
{"title":"ATV","channel":"AndorraTV.ad","filepath":"tests/__data__/output/channels/ad.m3u","url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"I6cjG2xCBRFFP4sz","is_online":false}
|
||||
{"title":"BBC News HD","channel":"BBCNewsHD.ad","filepath":"tests/__data__/output/channels/uk.m3u","url":"https://master.starmena-cloud.com/hls/libyas.m3u8","http_referrer":null,"user_agent":null,"cluster_id":3,"_id":"WTbieV1ptnZVCIdn","is_online":true,"bitrate":0,"width":1024,"height":576}
|
||||
{"title":"Kayhan TV","channel":"KayhanTV.af","filepath":"channels/af.m3u","url":"http://208.93.117.113/live/Stream1/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"cFFpFVzSn6xFMUF3","is_online":false}
|
||||
{"title":"Sharq","channel":"Sharq.af","filepath":"channels/af.m3u","bitrate":2226543,"width":1280,"height":720,"url":"https://forerunnerrtmp.livestreamingcdn.com/output18/output18.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"u7iyA6cjtf1iWWAZ","is_online":true}
|
||||
{"title":"ЛДПР ТВ","channel":"LDPRTV.ru","filepath":"tests/__data__/output/channels/ru.m3u","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"2ST8btby3mmsgPF0","status":"timeout"}
|
||||
{"title":"BBC News HD","channel":"BBCNews.uk","filepath":"tests/__data__/output/channels/uk.m3u","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http_referrer":null,"user_agent":null,"cluster_id":3,"_id":"3TbieV1ptnZVCIdn","status":"blocked"}
|
||||
{"title":"ATV","channel":"AndorraTV.ad","filepath":"tests/__data__/output/channels/ad.m3u","url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"I6cjG2xCBRFFP4sz","status":"error"}
|
||||
{"title":"BBC News HD","channel":"BBCNewsHD.ad","filepath":"tests/__data__/output/channels/uk.m3u","url":"https://master.starmena-cloud.com/hls/libyas.m3u8","http_referrer":null,"user_agent":null,"cluster_id":3,"_id":"WTbieV1ptnZVCIdn","status":"online","bitrate":0,"width":1024,"height":576}
|
||||
{"title":"Kayhan TV","channel":"KayhanTV.af","filepath":"channels/af.m3u","url":"http://208.93.117.113/live/Stream1/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"cFFpFVzSn6xFMUF3","status":"error"}
|
||||
{"title":"Sharq","channel":"Sharq.af","filepath":"channels/af.m3u","bitrate":2226543,"width":1280,"height":720,"url":"https://forerunnerrtmp.livestreamingcdn.com/output18/output18.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"cluster_id":1,"_id":"u7iyA6cjtf1iWWAZ","status":"online"}
|
||||
|
Loading…
Reference in New Issue
Block a user