diff --git a/scripts/update-codes.js b/scripts/update-codes.js index ee0338f0..28771be6 100644 --- a/scripts/update-codes.js +++ b/scripts/update-codes.js @@ -3,19 +3,17 @@ const path = require('path') const convert = require('xml-js') const axios = require('axios') const countries = require('./countries.json') +const file = require('./file.js') async function main() { console.log('Starting...') + const files = await file.list('.gh-pages/guides/*.xml') + let codes = {} for (const filename of files) { - const url = `https://iptv-org.github.io/epg/guides/${filename}.guide.xml` - console.log(`Loading '${url}'...`) - const file = await axios - .get(url) - .then(r => r.data) - .catch(console.log) - const channels = parseChannels(file) + const url = filename.replace('.gh-pages', 'https://iptv-org.github.io/epg') + const channels = parseChannels(file.read(filename)) channels.forEach(channel => { if (!codes[channel.tvg_id]) { channel.guides = [url] @@ -68,8 +66,8 @@ function convertToJSON(arr) { return JSON.stringify(arr) } -function parseChannels(file) { - const result = convert.xml2js(file) +function parseChannels(xml) { + const result = convert.xml2js(xml) const tv = result.elements.find(el => el.name === 'tv') return tv.elements @@ -88,36 +86,4 @@ function parseChannels(file) { }) } -const files = [ - 'andorradifusio.ad', - 'astro.com.my', - 'comteco.com.bo', - 'cosmote.gr', - 'digiturk.com.tr', - 'elcinema.com', - 'guidatv.sky.it', - 'hd-plus.de', - 'm.tv.sms.cz', - 'maxtv.hrvatskitelekom.hr', - 'mediaset.it', - 'meo.pt', - 'mi.tv', - 'mncvision.id', - 'ontvtonight.com', - 'programacion-tv.elpais.com', - 'programetv.ro', - 'programme-tv.net', - 'programtv.onet.pl', - 'telkussa.fi', - 'tv.lv', - 'tv.yandex.ru', - 'tvgid.ua', - 'tvguide.com', - 'tvprofil.com', - 'tvtv.ca', - 'tvtv.us', - 'vidio.com', - 'znbc.co.zm' -] - main()