mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Update update.js
This commit is contained in:
parent
44abcddd8b
commit
00e175714d
1 changed files with 23 additions and 37 deletions
|
@ -2,7 +2,7 @@ const { file, markdown, parser, logger, api, table } = require('../../core')
|
||||||
const { program } = require('commander')
|
const { program } = require('commander')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const CHANNELS_PATH = process.env.CHANNELS_PATH || 'sites/**/*.channels.xml'
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
||||||
|
|
||||||
const options = program
|
const options = program
|
||||||
.option('-c, --config <config>', 'Set path to config file', '.readme/readme.json')
|
.option('-c, --config <config>', 'Set path to config file', '.readme/readme.json')
|
||||||
|
@ -10,52 +10,34 @@ const options = program
|
||||||
.opts()
|
.opts()
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const items = []
|
|
||||||
|
|
||||||
await api.countries.load().catch(console.error)
|
await api.countries.load().catch(console.error)
|
||||||
const files = await file.list(CHANNELS_PATH).catch(console.error)
|
const logPath = `${LOGS_DIR}/guides/update.log`
|
||||||
for (const filepath of files) {
|
const results = await parser.parseLogs(logPath)
|
||||||
try {
|
const files = results.reduce((acc, curr) => {
|
||||||
const { site, channels } = await parser.parseChannels(filepath)
|
if (acc[curr.filename]) {
|
||||||
const dir = file.dirname(filepath)
|
acc[curr.filename].channels++
|
||||||
const config = require(file.resolve(`${dir}/${site}.config.js`))
|
} else {
|
||||||
if (config.ignore) continue
|
acc[curr.filename] = {
|
||||||
|
country: curr.country,
|
||||||
const filename = file.basename(filepath)
|
channels: 1,
|
||||||
const [__, suffix] = filename.match(/\_(.*)\.channels\.xml$/) || [null, null]
|
filename: curr.filename
|
||||||
const [code] = suffix.split('-')
|
}
|
||||||
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
site,
|
|
||||||
count: channels.length,
|
|
||||||
group: `${suffix}/${site}`
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await generateCountriesTable(items)
|
return acc
|
||||||
await updateReadme()
|
}, {})
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
||||||
async function generateCountriesTable(items = []) {
|
|
||||||
logger.info('generating countries table...')
|
|
||||||
|
|
||||||
let data = []
|
let data = []
|
||||||
for (const item of items) {
|
for (const filename in files) {
|
||||||
const country = api.countries.find({ code: item.code.toUpperCase() })
|
const item = files[filename]
|
||||||
|
const country = api.countries.find({ code: item.country })
|
||||||
if (!country) continue
|
if (!country) continue
|
||||||
|
|
||||||
data.push([
|
data.push([
|
||||||
country.name,
|
country.name,
|
||||||
`${country.flag} ${country.name}`,
|
`${country.flag} ${country.name}`,
|
||||||
item.count,
|
item.channels,
|
||||||
`<code>https://iptv-org.github.io/epg/guides/${item.group}.epg.xml</code>`
|
`<code>https://iptv-org.github.io/epg/guides/${filename}.xml</code>`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +55,12 @@ async function generateCountriesTable(items = []) {
|
||||||
])
|
])
|
||||||
|
|
||||||
await file.create('./.readme/_countries.md', output)
|
await file.create('./.readme/_countries.md', output)
|
||||||
|
|
||||||
|
await updateReadme()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
async function updateReadme() {
|
async function updateReadme() {
|
||||||
logger.info('updating readme.md...')
|
logger.info('updating readme.md...')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue