2022-02-06 22:04:56 +01:00
|
|
|
const { create: createPlaylist } = require('../core/playlist')
|
|
|
|
const { db, logger, generator, file, api } = require('../core')
|
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 02:42:15 +01:00
|
|
|
// console.log(streams)
|
2022-02-06 22:04:56 +01:00
|
|
|
await generator.generate('categories', streams)
|
2022-02-06 22:19:09 +01:00
|
|
|
await generator.generate('countries', streams)
|
2022-02-06 23:22:20 +01:00
|
|
|
await generator.generate('languages', streams)
|
|
|
|
await generator.generate('regions', streams)
|
2022-02-07 00:27:15 +01:00
|
|
|
await generator.generate('index_m3u', streams)
|
2022-02-07 01:52:47 +01:00
|
|
|
await generator.generate('index_nsfw_m3u', streams)
|
|
|
|
await generator.generate('index_category_m3u', streams)
|
2022-02-07 02:42:15 +01:00
|
|
|
await generator.generate('index_country_m3u', streams)
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
// await generateIndexCountry()
|
|
|
|
// await generateIndexLanguage()
|
|
|
|
// await generateIndexRegion()
|
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() {
|
|
|
|
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.countries.load()
|
|
|
|
let countries = await api.countries.all()
|
|
|
|
countries = _.keyBy(countries, 'code')
|
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')
|
|
|
|
|
|
|
|
await db.streams.load()
|
|
|
|
let streams = await db.streams.find({})
|
|
|
|
|
|
|
|
return streams.map(stream => {
|
|
|
|
const channel = channels[stream.channel_id] || null
|
|
|
|
|
|
|
|
stream.channel = channel
|
2022-02-07 02:42:15 +01:00
|
|
|
if (channel) {
|
|
|
|
stream.broadcast_area = channel.broadcast_area.map(item => {
|
|
|
|
const [_, code] = item.split('/')
|
|
|
|
return code
|
|
|
|
})
|
|
|
|
stream.categories = channel.categories.map(id => categories[id])
|
|
|
|
stream.languages = channel.languages.map(code => languages[code])
|
|
|
|
stream.guides = guides[stream.channel_id] ? guides[stream.channel_id].map(g => g.url) : []
|
|
|
|
} else {
|
|
|
|
stream.broadcast_area = []
|
|
|
|
stream.categories = []
|
|
|
|
stream.languages = []
|
|
|
|
stream.guides = []
|
|
|
|
}
|
2022-02-06 22:04:56 +01:00
|
|
|
|
|
|
|
return stream
|
|
|
|
})
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|
2022-02-07 00:27:15 +01:00
|
|
|
|
|
|
|
// async function generateIndexLanguage() {
|
|
|
|
// logger.info(`Generating index.language.m3u...`)
|
|
|
|
|
|
|
|
// await generator.generate(
|
|
|
|
// `${PUBLIC_PATH}/index.language.m3u`,
|
|
|
|
// {},
|
|
|
|
// {
|
|
|
|
// onLoad: function (items) {
|
|
|
|
// let results = items
|
|
|
|
// .filter(item => !item.languages || !item.languages.length)
|
|
|
|
// .map(item => {
|
|
|
|
// const newItem = _.cloneDeep(item)
|
|
|
|
// newItem.group_title = 'Undefined'
|
|
|
|
// newItem.categories = []
|
|
|
|
// return newItem
|
|
|
|
// })
|
|
|
|
// for (const language of languages) {
|
|
|
|
// let filtered = items
|
|
|
|
// .filter(item => {
|
|
|
|
// return (
|
|
|
|
// Array.isArray(item.languages) &&
|
|
|
|
// item.languages.map(c => c.code).includes(language.code)
|
|
|
|
// )
|
|
|
|
// })
|
|
|
|
// .map(item => {
|
|
|
|
// const newItem = _.cloneDeep(item)
|
|
|
|
// newItem.group_title = language.name
|
|
|
|
// return newItem
|
|
|
|
// })
|
|
|
|
// results = results.concat(filtered)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return results
|
|
|
|
// },
|
|
|
|
// sortBy: item => {
|
|
|
|
// if (item.group_title === 'Undefined') return '_'
|
|
|
|
// return item.group_title
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
|
|
|
|
// async function generateIndexRegion() {
|
|
|
|
// logger.info(`Generating index.region.m3u...`)
|
|
|
|
|
|
|
|
// await generator.generate(
|
|
|
|
// `${PUBLIC_PATH}/index.region.m3u`,
|
|
|
|
// {},
|
|
|
|
// {
|
|
|
|
// onLoad: function (items) {
|
|
|
|
// let results = items
|
|
|
|
// .filter(item => !item.regions.length)
|
|
|
|
// .map(item => {
|
|
|
|
// const newItem = _.cloneDeep(item)
|
|
|
|
// newItem.group_title = 'Undefined'
|
|
|
|
// newItem.categories = []
|
|
|
|
// return newItem
|
|
|
|
// })
|
|
|
|
// for (const region of regions) {
|
|
|
|
// let filtered = items
|
|
|
|
// .filter(item => {
|
|
|
|
// return item.regions.map(c => c.code).includes(region.code)
|
|
|
|
// })
|
|
|
|
// .map(item => {
|
|
|
|
// const newItem = _.cloneDeep(item)
|
|
|
|
// newItem.group_title = region.name
|
|
|
|
// return newItem
|
|
|
|
// })
|
|
|
|
// results = results.concat(filtered)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return results
|
|
|
|
// },
|
|
|
|
// sortBy: item => {
|
|
|
|
// if (item.group_title === 'Undefined') return '_'
|
|
|
|
// return item.group_title
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
// }
|