2022-02-11 19:07:16 +01:00
|
|
|
const { db, generator, api, logger, file } = require('../../core')
|
2022-02-12 01:11:55 +01:00
|
|
|
const { orderBy } = require('natural-orderby')
|
2021-12-12 05:10:03 +01:00
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
async function main() {
|
2022-02-06 22:04:56 +01:00
|
|
|
const streams = await loadStreams()
|
2022-02-07 03:53:30 +01:00
|
|
|
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating categories/...')
|
2022-02-06 22:04:56 +01:00
|
|
|
await generator.generate('categories', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating countries/...')
|
2022-02-06 22:19:09 +01:00
|
|
|
await generator.generate('countries', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating languages/...')
|
2022-02-06 23:22:20 +01:00
|
|
|
await generator.generate('languages', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating regions/...')
|
2022-02-06 23:22:20 +01:00
|
|
|
await generator.generate('regions', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.category.m3u...')
|
2022-02-07 01:52:47 +01:00
|
|
|
await generator.generate('index_category_m3u', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.country.m3u...')
|
2022-02-07 02:42:15 +01:00
|
|
|
await generator.generate('index_country_m3u', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.language.m3u...')
|
2022-02-07 03:53:30 +01:00
|
|
|
await generator.generate('index_language_m3u', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.m3u...')
|
2022-02-07 03:53:30 +01:00
|
|
|
await generator.generate('index_m3u', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.nsfw.m3u...')
|
2022-02-07 03:53:30 +01:00
|
|
|
await generator.generate('index_nsfw_m3u', streams)
|
2022-02-07 23:11:47 +01:00
|
|
|
logger.info('generating index.region.m3u...')
|
2022-02-07 03:53:30 +01:00
|
|
|
await generator.generate('index_region_m3u', streams)
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
main()
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
async function loadStreams() {
|
2022-02-07 23:11:47 +01:00
|
|
|
await db.streams.load()
|
2022-02-13 05:03:39 +01:00
|
|
|
let streams = await db.streams.find({ is_online: true })
|
|
|
|
streams = orderBy(streams, ['channel', 'height', 'url'], ['asc', 'desc', 'asc'])
|
|
|
|
streams = _.uniqBy(streams, stream => stream.channel || _.uniqueId())
|
2022-02-07 23:11:47 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
await api.channels.load()
|
|
|
|
let channels = await api.channels.all()
|
|
|
|
channels = _.keyBy(channels, 'id')
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
await api.categories.load()
|
|
|
|
let categories = await api.categories.all()
|
|
|
|
categories = _.keyBy(categories, 'id')
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
await api.languages.load()
|
|
|
|
let languages = await api.languages.all()
|
|
|
|
languages = _.keyBy(languages, 'code')
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
await api.guides.load()
|
|
|
|
let guides = await api.guides.all()
|
|
|
|
guides = _.groupBy(guides, 'channel')
|
|
|
|
|
2022-02-13 05:03:39 +01:00
|
|
|
streams = streams.map(stream => {
|
|
|
|
const channel = channels[stream.channel] || null
|
2022-02-11 17:56:11 +01:00
|
|
|
const filename = file.getFilename(stream.filepath)
|
|
|
|
const [_, code] = filename.match(/^([a-z]{2})(_|$)/) || [null, null]
|
|
|
|
const defaultBroadcastArea = code ? [`c/${code.toUpperCase()}`] : []
|
2022-02-06 22:04:56 +01:00
|
|
|
|
2022-02-11 17:56:11 +01:00
|
|
|
stream.guides = channel && Array.isArray(guides[channel.id]) ? guides[channel.id] : []
|
|
|
|
stream.categories = channel ? channel.categories.map(id => categories[id]) : []
|
|
|
|
stream.languages = channel ? channel.languages.map(id => languages[id]) : []
|
|
|
|
stream.broadcast_area = channel ? channel.broadcast_area : defaultBroadcastArea
|
|
|
|
stream.is_nsfw = channel ? channel.is_nsfw : false
|
|
|
|
stream.logo = channel ? channel.logo : null
|
2022-02-06 22:04:56 +01:00
|
|
|
|
|
|
|
return stream
|
|
|
|
})
|
2022-02-13 05:03:39 +01:00
|
|
|
|
|
|
|
streams = orderBy(streams, ['title'], ['asc'])
|
|
|
|
|
|
|
|
return streams
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|