Files
epg/scripts/create-matrix.js

38 lines
930 B
JavaScript
Raw Normal View History

2021-10-13 19:56:46 +03:00
const { Command } = require('commander')
2021-10-12 01:42:32 +03:00
const file = require('./file')
2021-10-15 00:58:42 +03:00
const grabber = require('epg-grabber')
2021-10-12 01:42:32 +03:00
2021-10-13 19:56:46 +03:00
const program = new Command()
program
.option('--include <include>', 'List of files to include', parseList)
.option('--exclude <exclude>', 'List of files to exclude', parseList)
.parse(process.argv)
2021-10-12 01:42:32 +03:00
2021-10-13 19:56:46 +03:00
const options = program.opts()
2021-10-15 04:34:41 +03:00
file.list('sites/**/*.channels.xml', options.include, options.exclude).then(files => {
2021-10-13 19:56:46 +03:00
const matrix = {
guide: []
}
files.forEach(filename => {
2021-10-15 04:34:41 +03:00
const country = filename.match(/sites\/.*\/.*_(.*)\.channels\.xml/i)[1]
2021-10-15 00:58:42 +03:00
2021-10-13 19:56:46 +03:00
const channelsFile = file.read(filename)
2021-10-15 00:58:42 +03:00
const parsed = grabber.parseChannels(channelsFile)
matrix.guide.push({
site: parsed.site,
country
2021-10-12 01:42:32 +03:00
})
2021-10-13 01:27:03 +03:00
})
2021-10-13 19:56:46 +03:00
const output = `::set-output name=matrix::${JSON.stringify(matrix)}`
console.log(output)
})
function parseList(str) {
if (!str) return []
return str.split(',')
}