mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Update update.ts
This commit is contained in:
parent
7e07f40809
commit
44bb8a5788
1 changed files with 27 additions and 15 deletions
|
@ -1,51 +1,63 @@
|
|||
import { Channel } from 'epg-grabber'
|
||||
import { Logger, Storage, Collection } from '@freearhey/core'
|
||||
import { IssueLoader, HTMLTable, Markdown } from '../../core'
|
||||
import { IssueLoader, HTMLTable, ChannelsParser } from '../../core'
|
||||
import { Issue, Site } from '../../models'
|
||||
import { SITES_DIR, DOT_SITES_DIR } from '../../constants'
|
||||
import path from 'path'
|
||||
import { SITES_DIR, ROOT_DIR } from '../../constants'
|
||||
|
||||
async function main() {
|
||||
const logger = new Logger({ disabled: true })
|
||||
const loader = new IssueLoader()
|
||||
const storage = new Storage(SITES_DIR)
|
||||
const sitesStorage = new Storage(SITES_DIR)
|
||||
const channelsParser = new ChannelsParser({ storage: sitesStorage })
|
||||
const sites = new Collection()
|
||||
|
||||
logger.info('loading list of sites')
|
||||
const folders = await storage.list('*/')
|
||||
const folders = await sitesStorage.list('*/')
|
||||
|
||||
logger.info('loading issues...')
|
||||
const issues = await loadIssues(loader)
|
||||
|
||||
logger.info('putting the data together...')
|
||||
folders.forEach((domain: string) => {
|
||||
for (const domain of folders) {
|
||||
const filteredIssues = issues.filter((issue: Issue) => domain === issue.data.get('site'))
|
||||
const site = new Site({
|
||||
domain,
|
||||
issues: filteredIssues
|
||||
})
|
||||
|
||||
const files = await sitesStorage.list(`${domain}/*.channels.xml`)
|
||||
for (const filepath of files) {
|
||||
const channels = await channelsParser.parse(filepath)
|
||||
|
||||
site.totalChannels += channels.count()
|
||||
site.markedChannels += channels.filter((channel: Channel) => channel.xmltv_id).count()
|
||||
}
|
||||
|
||||
sites.add(site)
|
||||
})
|
||||
}
|
||||
|
||||
logger.info('creating sites table...')
|
||||
const data = new Collection()
|
||||
sites.forEach((site: Site) => {
|
||||
data.add([
|
||||
`<a href="sites/${site.domain}">${site.domain}</a>`,
|
||||
`${site.totalChannels} / ${site.markedChannels}`,
|
||||
site.getStatus().emoji,
|
||||
site.getIssues().all().join(', ')
|
||||
])
|
||||
})
|
||||
|
||||
const table = new HTMLTable(data.all(), [{ name: 'Site' }, { name: 'Status' }, { name: 'Notes' }])
|
||||
|
||||
const readmeStorage = new Storage(DOT_SITES_DIR)
|
||||
await readmeStorage.save('_table.md', table.toString())
|
||||
|
||||
logger.info('updating sites.md...')
|
||||
const configPath = path.join(DOT_SITES_DIR, 'config.json')
|
||||
const sitesMarkdown = new Markdown(configPath)
|
||||
sitesMarkdown.compile()
|
||||
const table = new HTMLTable(data.all(), [
|
||||
{ name: 'Site' },
|
||||
{ name: 'Channels *', align: 'center' },
|
||||
{ name: 'Status' },
|
||||
{ name: 'Notes' }
|
||||
])
|
||||
const rootStorage = new Storage(ROOT_DIR)
|
||||
const sitesTemplate = await new Storage().load('scripts/templates/_sites.md')
|
||||
const sitesContent = sitesTemplate.replace('_TABLE_', table.toString())
|
||||
await rootStorage.save('SITES.md', sitesContent)
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue