Files
epg/scripts/update-codes.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-09-04 21:50:43 +03:00
const countries = require('./countries.json')
2021-10-07 22:59:31 +03:00
const file = require('./file.js')
2021-10-13 05:23:12 +03:00
const parser = require('epg-parser')
2021-09-03 22:57:22 +03:00
async function main() {
2021-03-28 02:09:46 +03:00
console.log('Starting...')
2021-09-05 02:29:46 +03:00
2021-10-12 21:38:37 +03:00
const files = await file.list('.gh-pages/guides/**/*.xml')
2021-10-07 22:59:31 +03:00
2021-09-05 02:29:46 +03:00
let codes = {}
2021-09-04 06:58:36 +03:00
for (const filename of files) {
2021-10-07 22:59:31 +03:00
const url = filename.replace('.gh-pages', 'https://iptv-org.github.io/epg')
2021-10-13 05:23:12 +03:00
const epg = file.read(filename)
const parsed = parser.parse(epg)
parsed.channels.forEach(channel => {
if (!codes[channel.id]) {
codes[channel.id] = {
tvg_id: channel.id,
display_name: channel.name[0].value,
logo: channel.icon[0],
2021-10-14 04:50:24 +03:00
country: channel.id.split('.')[1],
guides: [url]
2021-10-13 05:23:12 +03:00
}
2021-09-16 01:37:33 +03:00
} else {
2021-10-13 05:23:12 +03:00
codes[channel.id].guides.push(url)
2021-09-04 06:58:36 +03:00
}
2021-03-28 02:09:46 +03:00
})
2021-09-04 06:58:36 +03:00
}
2021-03-28 02:09:46 +03:00
2021-09-04 06:58:36 +03:00
const sorted = Object.values(codes).sort((a, b) => {
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) return -1
if (a.display_name.toLowerCase() > b.display_name.toLowerCase()) return 1
return 0
2021-03-28 02:09:46 +03:00
})
2021-10-13 05:23:12 +03:00
console.log(`Saving '.gh-pages/codes.json'...`)
file.write('.gh-pages/codes.json', JSON.stringify(sorted))
2021-09-04 21:50:43 +03:00
const _items = {}
countries.forEach(country => {
_items[country.code] = {
...country,
2021-09-05 02:05:09 +03:00
expanded: false,
2021-09-04 21:50:43 +03:00
channels: []
}
})
sorted.forEach(channel => {
const item = _items[channel.country]
if (item) {
channel.hash = `${channel.display_name}:${channel.tvg_id}`.toLowerCase()
item.channels.push(channel)
}
})
2021-10-13 05:23:12 +03:00
console.log(`Saving '.gh-pages/items.json'...`)
file.write('.gh-pages/items.json', JSON.stringify(_items))
2021-09-04 21:50:43 +03:00
2021-09-04 06:58:36 +03:00
console.log('Done')
2021-03-28 02:09:46 +03:00
}
main()