2022-08-10 02:41:06 +02:00
|
|
|
const { logger, db, api, file } = require('../../core')
|
2022-02-12 23:40:38 +01:00
|
|
|
const _ = require('lodash')
|
2022-08-10 02:41:06 +02:00
|
|
|
const dayjs = require('dayjs')
|
|
|
|
const utc = require('dayjs/plugin/utc')
|
|
|
|
dayjs.extend(utc)
|
2022-02-12 23:40:38 +01:00
|
|
|
|
2022-02-13 09:50:57 +01:00
|
|
|
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.api'
|
2022-02-12 23:40:38 +01:00
|
|
|
|
|
|
|
async function main() {
|
2022-08-10 02:41:06 +02:00
|
|
|
await api.streams.load()
|
2022-02-12 23:40:38 +01:00
|
|
|
await db.streams.load()
|
2022-08-10 02:41:06 +02:00
|
|
|
const now = dayjs.utc().format()
|
2022-02-12 23:40:38 +01:00
|
|
|
let streams = await db.streams.find({})
|
2022-02-13 08:29:11 +01:00
|
|
|
streams = _.sortBy(streams, 'channel')
|
2022-02-12 23:40:38 +01:00
|
|
|
streams = streams.map(stream => {
|
2022-08-13 19:43:40 +02:00
|
|
|
let data = {
|
2022-02-13 03:42:39 +01:00
|
|
|
channel: stream.channel,
|
2022-02-12 23:40:38 +01:00
|
|
|
url: stream.url,
|
2022-02-13 05:16:59 +01:00
|
|
|
http_referrer: stream.http_referrer,
|
|
|
|
user_agent: stream.user_agent,
|
2022-02-13 08:29:11 +01:00
|
|
|
status: stream.status,
|
2022-02-13 03:42:39 +01:00
|
|
|
width: stream.width,
|
|
|
|
height: stream.height,
|
2022-06-09 02:00:33 +02:00
|
|
|
bitrate: stream.bitrate,
|
|
|
|
frame_rate: stream.frame_rate
|
2022-02-12 23:40:38 +01:00
|
|
|
}
|
2022-08-10 02:41:06 +02:00
|
|
|
|
|
|
|
let addedAt = now
|
|
|
|
let updatedAt = now
|
|
|
|
let found = api.streams.find({ url: stream.url })
|
|
|
|
if (found) {
|
2022-08-13 19:43:40 +02:00
|
|
|
data = JSON.parse(JSON.stringify(data))
|
2022-08-10 02:41:06 +02:00
|
|
|
normalized = _.omit(found, ['added_at', 'updated_at', 'checked_at'])
|
|
|
|
if (_.isEqual(data, normalized)) {
|
|
|
|
addedAt = found.added_at || now
|
|
|
|
updatedAt = found.updated_at || now
|
|
|
|
} else {
|
|
|
|
addedAt = found.added_at || now
|
|
|
|
updatedAt = now
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.added_at = addedAt
|
|
|
|
data.updated_at = updatedAt
|
|
|
|
data.checked_at = now
|
|
|
|
|
|
|
|
return data
|
2022-02-12 23:40:38 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams))
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|