From a1c4bf99ef6a10d414bc444b7cc2aba54012cbfd Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 22 Jan 2022 19:44:52 +0300 Subject: [PATCH 1/4] Update create-database.js --- scripts/commands/create-database.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/commands/create-database.js b/scripts/commands/create-database.js index a08ae368..61fa785b 100644 --- a/scripts/commands/create-database.js +++ b/scripts/commands/create-database.js @@ -42,6 +42,7 @@ async function getChannels() { const groupId = `${region}/${site}` const items = await parser.parseChannels(filepath) for (const item of items) { + if (!item.site || !item.site_id || !item.xmltv_id || !item.name) continue const key = `${item.site}:${item.site_id}` if (!channels[key]) { const countryCode = item.xmltv_id.split('.')[1] From 7424ede4fa38a8b4e1af61904f1925fed70677f8 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 22 Jan 2022 19:45:08 +0300 Subject: [PATCH 2/4] Update tvtv.us.config.js --- sites/tvtv.us/tvtv.us.config.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sites/tvtv.us/tvtv.us.config.js b/sites/tvtv.us/tvtv.us.config.js index baa9b7ca..3dd94614 100644 --- a/sites/tvtv.us/tvtv.us.config.js +++ b/sites/tvtv.us/tvtv.us.config.js @@ -12,7 +12,7 @@ module.exports = { }/airings?startDateTime=${date.format()}&endDateTime=${date.add(1, 'd').format()}` }, logo({ channel }) { - return channel.logo + return `http://tvtv.tmsimg.com/assets/s${channel.site_id}_ll_h15_ad.png?w=360&h=270` }, parser: function ({ content }) { let programs = [] @@ -40,14 +40,12 @@ module.exports = { .catch(console.log) return data.data - .filter(i => ['Satellite'].includes(i.type)) + .filter(i => !['Radio Station'].includes(i.type)) .map(item => { return { lang: 'en', site_id: item.id, - xmltv_id: item.shortName, - name: item.name, - logo: item.logo + name: item.name } }) } From 2605a5f4cae19b4b07f0e49bf5c892ef7c691e79 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 23 Jan 2022 15:06:03 +0300 Subject: [PATCH 3/4] Update tvtv.us.config.js --- sites/tvtv.us/tvtv.us.config.js | 62 +++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/sites/tvtv.us/tvtv.us.config.js b/sites/tvtv.us/tvtv.us.config.js index 3dd94614..01ea4eee 100644 --- a/sites/tvtv.us/tvtv.us.config.js +++ b/sites/tvtv.us/tvtv.us.config.js @@ -12,7 +12,7 @@ module.exports = { }/airings?startDateTime=${date.format()}&endDateTime=${date.add(1, 'd').format()}` }, logo({ channel }) { - return `http://tvtv.tmsimg.com/assets/s${channel.site_id}_ll_h15_ad.png?w=360&h=270` + return channel.logo }, parser: function ({ content }) { let programs = [] @@ -34,23 +34,65 @@ module.exports = { return programs }, async channels({ country }) { + const channels = [] + const data = await axios .get(`https://www.tvtv.${country}/api/stations`) .then(r => r.data) .catch(console.log) - return data.data - .filter(i => !['Radio Station'].includes(i.type)) - .map(item => { - return { - lang: 'en', - site_id: item.id, - name: item.name - } - }) + const stations = data.data.filter(i => !['Radio Station'].includes(i.type)) + for (const station of stations) { + const stationData = await axios + .get(`https://www.tvtv.us/gn/d/v1.1/stations/${station.id}`) + .then(r => r.data[0] || {}) + .catch(console.log) + if (!stationData) continue + + let channel + const logo = parseChannelLogo(stationData.preferredImage) + switch (stationData.type) { + case 'Low Power Broadcast': + case 'Full Power Broadcast': + channel = { + site_id: station.id, + name: stationData.name, + xmltv_id: parseChannelId(stationData), + logo + } + break + default: + channel = { + site_id: station.id, + name: stationData.name, + logo + } + break + } + + if (channel) { + channels.push(channel) + } + } + + return channels } } +function parseChannelLogo(image) { + return image && image.uri ? `http://tvtv.tmsimg.com/${image.uri}` : null +} + +function parseChannelId(data) { + if (!data.callSign) return null + if (/^((CB|C[F-K]|V[A-G]|VO|VX|VY|X[J-O])[0-9A-Z-]+)/.test(data.callSign)) + return `${data.callSign}.ca` + if (/^((XH|XE)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.mx` + if (/^((K|N|W)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.us` + + return null +} + function parseItems(content) { return JSON.parse(content) } From 0ae8cf623a2ab971c57c0bfd815c85ee378068f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 23 Jan 2022 15:07:28 +0300 Subject: [PATCH 4/4] Update create-database.js --- scripts/commands/create-database.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/commands/create-database.js b/scripts/commands/create-database.js index 61fa785b..a08ae368 100644 --- a/scripts/commands/create-database.js +++ b/scripts/commands/create-database.js @@ -42,7 +42,6 @@ async function getChannels() { const groupId = `${region}/${site}` const items = await parser.parseChannels(filepath) for (const item of items) { - if (!item.site || !item.site_id || !item.xmltv_id || !item.name) continue const key = `${item.site}:${item.site_id}` if (!channels[key]) { const countryCode = item.xmltv_id.split('.')[1]