mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update update-readme.ts
This commit is contained in:
parent
66b3d2759a
commit
edea062456
1 changed files with 40 additions and 43 deletions
|
@ -29,8 +29,8 @@ type Program = {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Guide = {
|
type Guide = {
|
||||||
|
name?: string
|
||||||
flag: string
|
flag: string
|
||||||
name: string
|
|
||||||
url: string
|
url: string
|
||||||
channelCount: number
|
channelCount: number
|
||||||
emptyGuides: number
|
emptyGuides: number
|
||||||
|
@ -41,10 +41,11 @@ async function main() {
|
||||||
file
|
file
|
||||||
.list('.gh-pages/guides/**/*.xml')
|
.list('.gh-pages/guides/**/*.xml')
|
||||||
.then((files: string[]) => {
|
.then((files: string[]) => {
|
||||||
let guidesByCountry: Guide[] = []
|
const guidesByCountry: Guide[] = []
|
||||||
let guidesByUSState: Guide[] = []
|
const guidesByUSState: Guide[] = []
|
||||||
let guidesByCanadaProvince: Guide[] = []
|
const guidesByCanadaProvince: Guide[] = []
|
||||||
files.forEach((filename: string) => {
|
files.forEach((filename: string) => {
|
||||||
|
console.log(`Loading '${filename}'...`)
|
||||||
const matches: string[] = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i) || []
|
const matches: string[] = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i) || []
|
||||||
const code: string | undefined = matches[1]
|
const code: string | undefined = matches[1]
|
||||||
if (code === undefined) return
|
if (code === undefined) return
|
||||||
|
@ -59,42 +60,35 @@ async function main() {
|
||||||
if (showCount === 0) emptyGuides++
|
if (showCount === 0) emptyGuides++
|
||||||
})
|
})
|
||||||
|
|
||||||
const [_, stateCode] = code.split('-')
|
const guide: Guide = {
|
||||||
const country: Country | undefined = countries[code]
|
flag: '',
|
||||||
const us_state: State | undefined = countries['us']
|
url: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
|
||||||
? countries['us'].states[stateCode]
|
channelCount: epg.channels.length,
|
||||||
: undefined
|
emptyGuides
|
||||||
const ca_province: State | undefined = countries['ca']
|
}
|
||||||
? countries['ca'].states[stateCode]
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
if (country !== undefined) {
|
if (!code.includes('-')) {
|
||||||
guidesByCountry.push({
|
const country: Country | undefined = countries[code]
|
||||||
flag: country.flag,
|
if (!country) return
|
||||||
name: country.name,
|
guide.flag = country.flag
|
||||||
url: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
|
guide.name = country.name
|
||||||
channelCount: epg.channels.length,
|
guidesByCountry.push(guide)
|
||||||
emptyGuides
|
} else if (code.startsWith('us-')) {
|
||||||
})
|
const [_, stateCode] = code.split('-')
|
||||||
guidesByCountry = sortGuides(guidesByCountry)
|
const state: State | undefined = countries['us']
|
||||||
} else if (us_state !== undefined) {
|
? countries['us'].states[stateCode]
|
||||||
guidesByUSState.push({
|
: undefined
|
||||||
flag: '',
|
if (!state) return
|
||||||
name: us_state.name,
|
guide.name = state.name
|
||||||
url: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
|
guidesByUSState.push(guide)
|
||||||
channelCount: epg.channels.length,
|
} else if (code.startsWith('ca-')) {
|
||||||
emptyGuides
|
const [_, provinceCode] = code.split('-')
|
||||||
})
|
const province: State | undefined = countries['ca']
|
||||||
guidesByUSState = sortGuides(guidesByUSState)
|
? countries['ca'].states[provinceCode]
|
||||||
} else if (ca_province !== undefined) {
|
: undefined
|
||||||
guidesByCanadaProvince.push({
|
if (!province) return
|
||||||
flag: '',
|
guide.name = province.name
|
||||||
name: ca_province.name,
|
guidesByCanadaProvince.push(guide)
|
||||||
url: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
|
|
||||||
channelCount: epg.channels.length,
|
|
||||||
emptyGuides
|
|
||||||
})
|
|
||||||
guidesByCanadaProvince = sortGuides(guidesByCanadaProvince)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -124,6 +118,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateTable(guides: Guide[], header: string[]) {
|
function generateTable(guides: Guide[], header: string[]) {
|
||||||
|
guides = sortGuides(guides)
|
||||||
|
|
||||||
let output = '<table>\n'
|
let output = '<table>\n'
|
||||||
|
|
||||||
output += '\t<thead>\n\t\t<tr>'
|
output += '\t<thead>\n\t\t<tr>'
|
||||||
|
@ -135,6 +131,7 @@ function generateTable(guides: Guide[], header: string[]) {
|
||||||
output += '\t<tbody>\n'
|
output += '\t<tbody>\n'
|
||||||
for (let guide of guides) {
|
for (let guide of guides) {
|
||||||
const size = guides.filter((g: Guide) => g.name === guide.name).length
|
const size = guides.filter((g: Guide) => g.name === guide.name).length
|
||||||
|
if (!guide.name) continue
|
||||||
let root = output.indexOf(guide.name) === -1
|
let root = output.indexOf(guide.name) === -1
|
||||||
const rowspan = root && size > 1 ? ` rowspan="${size}"` : ''
|
const rowspan = root && size > 1 ? ` rowspan="${size}"` : ''
|
||||||
const name = `${guide.flag} ${guide.name}`
|
const name = `${guide.flag} ${guide.name}`
|
||||||
|
@ -153,10 +150,10 @@ function generateTable(guides: Guide[], header: string[]) {
|
||||||
|
|
||||||
function sortGuides(guides: Guide[]): Guide[] {
|
function sortGuides(guides: Guide[]): Guide[] {
|
||||||
return guides.sort((a, b) => {
|
return guides.sort((a, b) => {
|
||||||
var countryNameA = a.name.toLowerCase()
|
var nameA = a.name ? a.name.toLowerCase() : ''
|
||||||
var countryNameB = b.name.toLowerCase()
|
var nameB = b.name ? b.name.toLowerCase() : ''
|
||||||
if (countryNameA < countryNameB) return -1
|
if (nameA < nameB) return -1
|
||||||
if (countryNameA > countryNameB) return 1
|
if (nameA > nameB) return 1
|
||||||
return b.channelCount - a.channelCount
|
return b.channelCount - a.channelCount
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue