Update database/create.js
This commit is contained in:
parent
37b77a7d62
commit
682824a45d
|
@ -30,13 +30,24 @@ async function findStreams() {
|
|||
await api.channels.load()
|
||||
await db.streams.load()
|
||||
|
||||
const files = await file.list(`${options.inputDir}/**/*.m3u`)
|
||||
const streams = []
|
||||
const files = await file.list(`${options.inputDir}/**/*.m3u`)
|
||||
for (const filepath of files) {
|
||||
const items = await parser.parsePlaylist(filepath)
|
||||
for (const item of items) {
|
||||
item.filepath = filepath
|
||||
streams.push(item)
|
||||
|
||||
const stream = store.create()
|
||||
const channel = await api.channels.find({ id: item.tvg.id })
|
||||
|
||||
stream.set('channel', { channel: channel ? channel.id : null })
|
||||
stream.set('title', { title: item.name })
|
||||
stream.set('filepath', { filepath: item.filepath })
|
||||
stream.set('url', { url: item.url })
|
||||
stream.set('http_referrer', { http_referrer: item.http.referrer })
|
||||
stream.set('user_agent', { user_agent: item.http['user-agent'] })
|
||||
|
||||
streams.push(stream)
|
||||
}
|
||||
}
|
||||
logger.info(`found ${streams.length} streams`)
|
||||
|
@ -50,17 +61,7 @@ async function saveToDatabase(streams = []) {
|
|||
await db.streams.reset()
|
||||
const chunks = split(_.shuffle(streams), options.maxClusters)
|
||||
for (const [i, chunk] of chunks.entries()) {
|
||||
for (const item of chunk) {
|
||||
const stream = store.create()
|
||||
const channel = await api.channels.find({ id: item.tvg.id })
|
||||
const channel_id = channel ? channel.id : null
|
||||
|
||||
stream.set('channel', { channel: channel_id })
|
||||
stream.set('title', { title: item.name })
|
||||
stream.set('filepath', { filepath: item.filepath })
|
||||
stream.set('url', { url: item.url })
|
||||
stream.set('http_referrer', { http_referrer: item.http.referrer })
|
||||
stream.set('user_agent', { user_agent: item.http['user-agent'] })
|
||||
for (const stream of chunk) {
|
||||
stream.set('cluster_id', { cluster_id: i + 1 })
|
||||
|
||||
await db.streams.insert(stream.data())
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function ({ channel }) {
|
||||
return channel || null
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
exports.url = require('./url')
|
||||
exports.http_referrer = require('./http_referrer')
|
||||
exports.user_agent = require('./user_agent')
|
||||
exports.channel = require('./channel')
|
||||
|
|
Loading…
Reference in New Issue