mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
890 B
JavaScript
34 lines
890 B
JavaScript
const { create: createPlaylist } = require('../../core/playlist')
|
|
const { normalize: normalizeUrl } = require('../../core/url')
|
|
const { db, logger, file } = require('../../core')
|
|
const { orderBy } = require('natural-orderby')
|
|
const _ = require('lodash')
|
|
|
|
async function main() {
|
|
logger.info('loading streams...')
|
|
await db.streams.load()
|
|
let streams = await db.streams.find({})
|
|
|
|
streams = streams.map(stream => {
|
|
stream.url = normalizeUrl(stream.url)
|
|
|
|
return stream
|
|
})
|
|
|
|
logger.info('sorting links...')
|
|
streams = orderBy(
|
|
streams,
|
|
['channel', s => (s.channel ? '' : s.title), 'url'],
|
|
['asc', 'asc', 'asc']
|
|
)
|
|
|
|
logger.info('saving...')
|
|
const files = _.groupBy(streams, 'filepath')
|
|
for (const filepath in files) {
|
|
const playlist = createPlaylist(files[filepath], { public: false })
|
|
await file.create(filepath, playlist.toString())
|
|
}
|
|
}
|
|
|
|
main()
|