From 870ac11e7033d9d0a52168d1965100f9cecb2436 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 12 Jan 2022 13:27:27 +0300 Subject: [PATCH] wip --- scripts/commands/create-database.js | 8 +- scripts/commands/load-cluster.js | 13 +- scripts/commands/update-database.js | 8 +- scripts/commands/update-guides.js | 158 +++++++++--------- tests/__data__/expected/{guides => }/epg.xml | 2 +- .../us.epg.xml => us/magticom.ge.epg.xml} | 2 +- .../za.epg.xml => za/dstv.com.epg.xml} | 0 tests/__data__/input/database/programs.db | 92 +++++----- ...annels.xml => example.com_us.channels.xml} | 0 tests/commands/create-database.test.js | 2 +- tests/commands/update-database.test.js | 1 + tests/commands/update-guides.test.js | 21 +-- 12 files changed, 159 insertions(+), 148 deletions(-) rename tests/__data__/expected/{guides => }/epg.xml (97%) rename tests/__data__/expected/guides/{countries/us.epg.xml => us/magticom.ge.epg.xml} (97%) rename tests/__data__/expected/guides/{countries/za.epg.xml => za/dstv.com.epg.xml} (100%) rename tests/__data__/input/{example.com.channels.xml => example.com_us.channels.xml} (100%) diff --git a/scripts/commands/create-database.js b/scripts/commands/create-database.js index d8c92bfd..ef2a1e82 100644 --- a/scripts/commands/create-database.js +++ b/scripts/commands/create-database.js @@ -33,10 +33,16 @@ async function loadChannels() { const files = await file.list(options.channels) for (const filepath of files) { const dir = file.dirname(filepath) + const filename = file.basename(filepath) + const [_, code] = filename.match(/_(.*).channels.xml/i) || ['', ''] + const [country, __] = code.split('-') || [null, null] const items = await parser.parseChannels(filepath) for (const item of items) { + // const countryCode = item.xmltv_id.split('.')[1] + // item.country = countryCode ? countryCode.toUpperCase() : null item.channelsPath = filepath item.configPath = `${dir}/${item.site}.config.js` + item.country = country.toUpperCase() channels.push(item) } } @@ -50,9 +56,7 @@ async function saveToDatabase() { const chunks = split(_.shuffle(channels), options.maxClusters) for (const [i, chunk] of chunks.entries()) { for (const item of chunk) { - const countryCode = item.xmltv_id.split('.')[1] item.cluster_id = i + 1 - item.country = countryCode ? countryCode.toUpperCase() : null await db.channels.insert(item) } } diff --git a/scripts/commands/load-cluster.js b/scripts/commands/load-cluster.js index 58f36804..e438d771 100644 --- a/scripts/commands/load-cluster.js +++ b/scripts/commands/load-cluster.js @@ -18,18 +18,18 @@ async function main() { logger.info(`Loading cluster: ${options.clusterId}`) logger.info(`Creating '${clusterLog}'...`) await file.create(clusterLog) - const items = await db.channels.find({ cluster_id: options.clusterId }) + const channels = await db.channels.find({ cluster_id: options.clusterId }) const days = options.days || 1 - const total = days * items.length + const total = days * channels.length logger.info(`Total ${total} requests`) logger.info('Loading...') const results = {} let i = 1 - for (const item of items) { - const config = require(file.resolve(item.configPath)) + for (const channel of channels) { + const config = require(file.resolve(channel.configPath)) config.days = config.days || days - const programs = await grabber.grab(item, config, (data, err) => { + const programs = await grabber.grab(channel, config, (data, err) => { logger.info( `[${i}/${total}] ${config.site} - ${data.channel.xmltv_id} - ${data.date.format( 'MMM D, YYYY' @@ -42,7 +42,8 @@ async function main() { }) await file.append( clusterLog, - JSON.stringify({ _id: item._id, site: config.site, programs }) + '\n' + JSON.stringify({ _id: channel._id, site: config.site, country: channel.country, programs }) + + '\n' ) } diff --git a/scripts/commands/update-database.js b/scripts/commands/update-database.js index 3c81ca9d..a1f9f582 100644 --- a/scripts/commands/update-database.js +++ b/scripts/commands/update-database.js @@ -9,9 +9,11 @@ async function main() { for (const filepath of files) { const results = await parser.parseLogs(filepath) results.forEach(result => { - const programs = result.programs.map(p => { - p.site = result.site - return p + const programs = result.programs.map(program => { + program.site = result.site + program.country = result.country + + return program }) db.programs.insert(programs) }) diff --git a/scripts/commands/update-guides.js b/scripts/commands/update-guides.js index 7be8822f..68e21292 100644 --- a/scripts/commands/update-guides.js +++ b/scripts/commands/update-guides.js @@ -1,25 +1,24 @@ const { db, logger, file, xml } = require('../core') const _ = require('lodash') -let channels = {} -let programs = {} let sources = {} const DB_DIR = process.env.DB_DIR || 'scripts/database' -const GUIDES_DIR = process.env.GUIDES_DIR || '.gh-pages/guides' +const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages' async function main() { - await setUp() - - await generateMainXML() - await generateCountries() + await generateEpgXML() + await generateGuides() } main() -async function generateMainXML() { +async function generateEpgXML() { logger.info(`Generating epg.xml...`) + const channels = await loadChannels() + const programs = await loadPrograms() + const output = {} const filteredChannels = Object.keys(programs) output.channels = _.flatten(Object.values(channels)) @@ -30,41 +29,28 @@ async function generateMainXML() { }) output.programs = _.flatten(Object.values(programs)) - await file.create(`${GUIDES_DIR}/epg.xml`, xml.create(output)) + await file.create(`${PUBLIC_DIR}/epg.xml`, xml.create(output)) } -async function generateCountries() { - logger.info(`Generating countries/...`) +async function generateGuides() { + logger.info(`Generating guides/...`) - const filteredChannels = Object.keys(programs).map(id => channels[id]) + let channels = await db.channels.find({}).sort({ xmltv_id: 1 }) + const programs = await db.programs.find({}).sort({ channel: 1, start: 1 }) + const grouped = _.groupBy(programs, i => `${i.country.toLowerCase()}/${i.site}`) - for (let channel of filteredChannels) { - const code = channel.country - const output = { - channels: [], - programs: [] - } - - output.channels = filteredChannels - .filter(c => c.country === code) - .map(c => { - c.site = sources[c.id] - return c - }) - - for (let channel of output.channels) { - output.programs = output.programs.concat(programs[channel.id]) - } - - await file.create(`${GUIDES_DIR}/countries/${code.toLowerCase()}.epg.xml`, xml.create(output)) + for (let groupId in grouped) { + const filepath = `${PUBLIC_DIR}/guides/${groupId}.epg.xml` + const groupProgs = grouped[groupId] + const groupChannels = Object.keys(_.groupBy(groupProgs, 'channel')).map(key => { + let [_, site] = groupId.split('/') + return channels.find(i => i.xmltv_id === key && i.site === site) + }) + const output = xml.create({ channels: groupChannels, programs: groupProgs }) + await file.create(filepath, output) } } -async function setUp() { - channels = await loadChannels() - programs = await loadPrograms() -} - async function loadChannels() { let items = await db.channels.find({}).sort({ xmltv_id: 1 }) @@ -89,50 +75,66 @@ async function loadChannels() { } async function loadPrograms() { - let items = await db.programs.find({}) + let programs = await db.programs.find({}) - items = _.sortBy(items, ['channel', 'start']) - items = _.groupBy(items, 'channel') - - for (let channel in items) { - let channelPrograms = items[channel] - channelPrograms = Object.values(_.groupBy(channelPrograms, i => i.site))[0] - let slots = _.groupBy(channelPrograms, i => `${i.start}_${i.stop}`) - - for (let slotId in slots) { - let program = { - channel, - title: [], - description: [], - categories: [], - image: null, - start: null, - stop: null - } - - slots[slotId].forEach(item => { - if (item.title) program.title.push({ lang: item.lang, value: item.title }) - if (item.description) - program.description.push({ - lang: item.lang, - value: item.description - }) - if (item.category) program.categories.push({ lang: item.lang, value: item.category }) - program.image = program.image || item.icon - program.start = item.start - program.stop = item.stop - sources[channel] = item.site - }) - - program.title = _.uniqBy(program.title, 'lang') - program.description = _.uniqBy(program.description, 'lang') - program.categories = _.uniqBy(program.categories, 'lang') - - slots[slotId] = program + programs = programs.map(program => { + return { + title: program.title ? [{ lang: program.lang, value: program.title }] : [], + description: program.description ? [{ lang: program.lang, value: program.description }] : [], + categories: program.category ? [{ lang: program.lang, value: program.category }] : [], + icon: program.icon, + channel: program.channel, + lang: program.lang, + start: program.start, + stop: program.stop, + site: program.site, + country: program.country, + _id: program._id } + }) - items[channel] = Object.values(slots) - } + programs = _.sortBy(programs, ['channel', 'start']) + programs = _.groupBy(programs, 'channel') - return items + // for (let channel in items) { + // let channelPrograms = items[channel] + // channelPrograms = Object.values(_.groupBy(channelPrograms, i => i.site))[0] + // let slots = _.groupBy(channelPrograms, i => `${i.start}_${i.stop}`) + + // for (let slotId in slots) { + // let program = { + // channel, + // title: [], + // description: [], + // categories: [], + // image: null, + // start: null, + // stop: null + // } + + // slots[slotId].forEach(item => { + // if (item.title) program.title.push({ lang: item.lang, value: item.title }) + // if (item.description) + // program.description.push({ + // lang: item.lang, + // value: item.description + // }) + // if (item.category) program.categories.push({ lang: item.lang, value: item.category }) + // program.image = program.image || item.icon + // program.start = item.start + // program.stop = item.stop + // sources[channel] = item.site + // }) + + // program.title = _.uniqBy(program.title, 'lang') + // program.description = _.uniqBy(program.description, 'lang') + // program.categories = _.uniqBy(program.categories, 'lang') + + // slots[slotId] = program + // } + + // items[channel] = Object.values(slots) + // } + + return programs } diff --git a/tests/__data__/expected/guides/epg.xml b/tests/__data__/expected/epg.xml similarity index 97% rename from tests/__data__/expected/guides/epg.xml rename to tests/__data__/expected/epg.xml index e3927962..b99a0b63 100644 --- a/tests/__data__/expected/guides/epg.xml +++ b/tests/__data__/expected/epg.xml @@ -1,5 +1,5 @@ -CNN International EuropeCNN Inthttps://magticom.ge +CNN Inthttps://magticom.ge M-Net Movies 2https://dstv.com CNN Newsroom SundayСвежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте. Fareed Zakaria GPSИнтервью с главными игроками мировой политики. diff --git a/tests/__data__/expected/guides/countries/us.epg.xml b/tests/__data__/expected/guides/us/magticom.ge.epg.xml similarity index 97% rename from tests/__data__/expected/guides/countries/us.epg.xml rename to tests/__data__/expected/guides/us/magticom.ge.epg.xml index d0b98ff3..5f444459 100644 --- a/tests/__data__/expected/guides/countries/us.epg.xml +++ b/tests/__data__/expected/guides/us/magticom.ge.epg.xml @@ -1,5 +1,5 @@ -CNN International EuropeCNN Inthttps://magticom.ge +CNN Inthttps://magticom.ge CNN Newsroom SundayСвежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте. Fareed Zakaria GPSИнтервью с главными игроками мировой политики. African Voices Changemakers. 114-я серия114-я серия. Африка сегодня - люди, новости, события. diff --git a/tests/__data__/expected/guides/countries/za.epg.xml b/tests/__data__/expected/guides/za/dstv.com.epg.xml similarity index 100% rename from tests/__data__/expected/guides/countries/za.epg.xml rename to tests/__data__/expected/guides/za/dstv.com.epg.xml diff --git a/tests/__data__/input/database/programs.db b/tests/__data__/input/database/programs.db index edb89bd8..6fd8851f 100644 --- a/tests/__data__/input/database/programs.db +++ b/tests/__data__/input/database/programs.db @@ -1,46 +1,46 @@ -{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641825900,"stop":1641826800,"site":"magticom.ge","_id":"12AJc0GeEJE9p4c3"} -{"title":"Connecting Africa. 114-я серия","description":"114-я серия. Проект, рассказывающий о людях и компаниях, которые совершают революцию в африканском бизнесе, и о тех, кто объединяет континент, выступая за свободную торговлю в Африке.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641843900,"stop":1641844800,"site":"magticom.ge","_id":"1dxcT34nyxzOlxBL"} -{"title":"Connect the World","description":"Актуальная мировая информация с разных континентов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641826800,"stop":1641830400,"site":"magticom.ge","_id":"2uJe4w2lgvjNOXo0"} -{"title":"The Lead with Jake Tapper","description":"Оперативная сводка новостей страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641844800,"stop":1641848400,"site":"magticom.ge","_id":"6As6GzEVhb3OWM0M"} -{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641817800,"stop":1641819600,"site":"magticom.ge","_id":"6DXKlITWehX1Jx4F"} -{"title":"CNN Newsroom with Michael Holmes","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641790800,"stop":1641794400,"site":"magticom.ge","_id":"AadPdMZ3s72y8NMk"} -{"title":"The Situation Room with Wolf Blitzer","description":"Командный центр новостей, политики и неординарных репортажей со всего мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641852000,"stop":1641855600,"site":"magticom.ge","_id":"Az3ABKy3HnE7sJZk"} -{"title":"One World with Zain Asher","description":"Освещаются важные новости с каждого континента, от политики и текущих дел до социальных вопросов и многого другого.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641830400,"stop":1641833100,"site":"magticom.ge","_id":"DMurxgt5OD0E9OIE"} -{"title":"TBD","description":"Информационно-познавательный проект CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641783600,"stop":1641785400,"site":"magticom.ge","_id":"HQJqM2kIa77llWbC"} -{"title":"Marketplace Africa. 548-я серия","description":"548-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641782700,"stop":1641783600,"site":"magticom.ge","_id":"Jn3khh5n9Brkxq4U"} -{"title":"CNN Newsroom with Michael Holmes","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641787200,"stop":1641789900,"site":"magticom.ge","_id":"KcrIoQTXtUdw74sO"} -{"title":"The Global Brief with Bianca Nobilo","description":"Global Brief с Бьянкой Нобило проницательно исследует меняющийся мир для меняющейся аудитории, обеспечивая непревзойденную глубину и качество для занятых зрителей в быстро меняющемся мире.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641848400,"stop":1641850200,"site":"magticom.ge","_id":"LGD7WmQogDRxZn01"} -{"title":"CNN Newsroom with Rosemary Church","description":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641798000,"stop":1641805200,"site":"magticom.ge","_id":"LyCBivUTdZFW9X53"} -{"title":"Marketplace Africa. 549-я серия","description":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641833100,"stop":1641834000,"site":"magticom.ge","_id":"PbrZinuZKgBHqDVj"} -{"title":"African Voices Changemakers. 114-я серия","description":"114-я серия. Африка сегодня - люди, новости, события.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641780000,"stop":1641781800,"site":"magticom.ge","_id":"SvrCK31v78V5y7EA"} -{"title":"Anderson Cooper 360","description":"Уникальный взгляд Андерсона Купера на главные события мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641859200,"stop":1641862800,"site":"magticom.ge","_id":"TFGrOFJGkaOs9pU7"} -{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641850200,"stop":1641852000,"site":"magticom.ge","_id":"UynlLeT41MsjFElg"} -{"title":"New Day","description":"Свежий обзор событий в стране и мире.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641808800,"stop":1641817800,"site":"magticom.ge","_id":"UyvhQ4wRNq5d5XRd"} -{"title":"Amanpour","description":"Сводка новостей от знаменитой ведущей канала CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641834000,"stop":1641837600,"site":"magticom.ge","_id":"WbsOCkmPH5gjmo4M"} -{"title":"Early Start","description":"Новости дня с Кристиной Романс и Дейвом Бриггсом.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641805200,"stop":1641808800,"site":"magticom.ge","_id":"YB96P2mMO4TA0pID"} -{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641789900,"stop":1641790800,"site":"magticom.ge","_id":"aDdCAlgqLG2yxM1m"} -{"title":"CNN Newsroom Sunday","description":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641772800,"stop":1641776400,"site":"magticom.ge","_id":"aYCk87dUOAkCJE9x"} -{"title":"Fareed Zakaria GPS","description":"Интервью с главными игроками мировой политики.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641776400,"stop":1641780000,"site":"magticom.ge","_id":"c1nCoWVetBZ3mn5q"} -{"title":"Inside Africa. 586-я серия","description":"586-я серия. Своеобразное \"путешествие\" по Африке - почувствуйте все разнообразие культур различных стран и регионов континента.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641785400,"stop":1641787200,"site":"magticom.ge","_id":"goaDr7BsGGm3LCfz"} -{"title":"CNN Newsroom with Robyn Curnow","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641794400,"stop":1641797100,"site":"magticom.ge","_id":"nixd3gRF1S1K0ZOs"} -{"title":"Marketplace Africa. 549-я серия","description":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641781800,"stop":1641782700,"site":"magticom.ge","_id":"r1b8EvZc0tYs88ga"} -{"title":"Erin Burnett OutFront","description":"Обсуждение самых важных мировых тем в эфире канала CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641855600,"stop":1641859200,"site":"magticom.ge","_id":"sIQtUtowtATc7dLj"} -{"title":"Connect the World","description":"Актуальная мировая информация с разных континентов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641823200,"stop":1641825900,"site":"magticom.ge","_id":"tXBIZ2BZBIkhnoTZ"} -{"title":"Quest Means Business","description":"Ричард Квест возглавляет группу экспертов и корреспондентов, чтобы предоставить актуальные факты, цифры и анализ из делового мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641841200,"stop":1641843900,"site":"magticom.ge","_id":"xlE5epkjzdfUQpXO"} -{"title":"First Move with Julia Chatterley","description":"Несколько больших историй, связанных с открытием рынков в США.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641819600,"stop":1641823200,"site":"magticom.ge","_id":"yEVXucyUomVmktMF"} -{"title":"Hala Gorani Tonight","description":"Используя свой 25-летний журналистский опыт, Хала Горани будет освещать ключевые события в картине дня посредством диалога с гостями и экспертами-аналитиками.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641837600,"stop":1641841200,"site":"magticom.ge","_id":"yPgmYrWwfxHW3WUA"} -{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641797100,"stop":1641798000,"site":"magticom.ge","_id":"zX70wOz5drExRTJX"} -{"title":"Robin Hood","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641822300,"stop":1641829200,"site":"dstv.com","_id":"1AoKArQw6MxP6pVU"} -{"title":"The Water Diviner","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641776100,"stop":1641782700,"site":"dstv.com","_id":"6v7w0SB4IlnfEEu3"} -{"title":"Bad Boys For Life","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641847200,"stop":1641850800,"site":"dstv.com","_id":"83VRYvggmyfCzkOm"} -{"title":"12 Strong","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641814500,"stop":1641822300,"site":"dstv.com","_id":"DbjwscjIuVDY8TPx"} -{"title":"Backdraft","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641801300,"stop":1641809400,"site":"dstv.com","_id":"IwuwkjCKqWvio7ba"} -{"title":"Force Of Nature","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641841200,"stop":1641847200,"site":"dstv.com","_id":"LP56HczEup0ed3Xx"} -{"title":"Mafia","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641809400,"stop":1641814500,"site":"dstv.com","_id":"MM9DPxERAgGGak39"} -{"title":"The Last Witch Hunter","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641834780,"stop":1641841200,"site":"dstv.com","_id":"MciJOpN3YCodj6Na"} -{"title":"Beyond The Line","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641796500,"stop":1641801300,"site":"dstv.com","_id":"ZKA2s6QrM0xRrfGz"} -{"title":"Paranoia","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641790200,"stop":1641796500,"site":"dstv.com","_id":"ZpdIZeSRhPycDX9D"} -{"title":"The Scorpion King","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641829200,"stop":1641834780,"site":"dstv.com","_id":"doO4Lh1pAt6L6wHa"} -{"title":"Fatman","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641761700,"stop":1641767700,"site":"dstv.com","_id":"fHahGuzHnU7xVEJX"} -{"title":"Outbreak","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641782700,"stop":1641790200,"site":"dstv.com","_id":"mkvcMP4FMwL2a5ax"} -{"title":"Motherless Brooklyn","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641767700,"stop":1641776100,"site":"dstv.com","_id":"nxTIAJsBwyXztRun"} +{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641825900,"stop":1641826800,"site":"magticom.ge","country":"US","_id":"12AJc0GeEJE9p4c3"} +{"title":"Connecting Africa. 114-я серия","description":"114-я серия. Проект, рассказывающий о людях и компаниях, которые совершают революцию в африканском бизнесе, и о тех, кто объединяет континент, выступая за свободную торговлю в Африке.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641843900,"stop":1641844800,"site":"magticom.ge","country":"US","_id":"1dxcT34nyxzOlxBL"} +{"title":"Connect the World","description":"Актуальная мировая информация с разных континентов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641826800,"stop":1641830400,"site":"magticom.ge","country":"US","_id":"2uJe4w2lgvjNOXo0"} +{"title":"The Lead with Jake Tapper","description":"Оперативная сводка новостей страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641844800,"stop":1641848400,"site":"magticom.ge","country":"US","_id":"6As6GzEVhb3OWM0M"} +{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641817800,"stop":1641819600,"site":"magticom.ge","country":"US","_id":"6DXKlITWehX1Jx4F"} +{"title":"CNN Newsroom with Michael Holmes","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641790800,"stop":1641794400,"site":"magticom.ge","country":"US","_id":"AadPdMZ3s72y8NMk"} +{"title":"The Situation Room with Wolf Blitzer","description":"Командный центр новостей, политики и неординарных репортажей со всего мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641852000,"stop":1641855600,"site":"magticom.ge","country":"US","_id":"Az3ABKy3HnE7sJZk"} +{"title":"One World with Zain Asher","description":"Освещаются важные новости с каждого континента, от политики и текущих дел до социальных вопросов и многого другого.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641830400,"stop":1641833100,"site":"magticom.ge","country":"US","_id":"DMurxgt5OD0E9OIE"} +{"title":"TBD","description":"Информационно-познавательный проект CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641783600,"stop":1641785400,"site":"magticom.ge","country":"US","_id":"HQJqM2kIa77llWbC"} +{"title":"Marketplace Africa. 548-я серия","description":"548-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641782700,"stop":1641783600,"site":"magticom.ge","country":"US","_id":"Jn3khh5n9Brkxq4U"} +{"title":"CNN Newsroom with Michael Holmes","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641787200,"stop":1641789900,"site":"magticom.ge","country":"US","_id":"KcrIoQTXtUdw74sO"} +{"title":"The Global Brief with Bianca Nobilo","description":"Global Brief с Бьянкой Нобило проницательно исследует меняющийся мир для меняющейся аудитории, обеспечивая непревзойденную глубину и качество для занятых зрителей в быстро меняющемся мире.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641848400,"stop":1641850200,"site":"magticom.ge","country":"US","_id":"LGD7WmQogDRxZn01"} +{"title":"CNN Newsroom with Rosemary Church","description":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641798000,"stop":1641805200,"site":"magticom.ge","country":"US","_id":"LyCBivUTdZFW9X53"} +{"title":"Marketplace Africa. 549-я серия","description":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641833100,"stop":1641834000,"site":"magticom.ge","country":"US","_id":"PbrZinuZKgBHqDVj"} +{"title":"African Voices Changemakers. 114-я серия","description":"114-я серия. Африка сегодня - люди, новости, события.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641780000,"stop":1641781800,"site":"magticom.ge","country":"US","_id":"SvrCK31v78V5y7EA"} +{"title":"Anderson Cooper 360","description":"Уникальный взгляд Андерсона Купера на главные события мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641859200,"stop":1641862800,"site":"magticom.ge","country":"US","_id":"TFGrOFJGkaOs9pU7"} +{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641850200,"stop":1641852000,"site":"magticom.ge","country":"US","_id":"UynlLeT41MsjFElg"} +{"title":"New Day","description":"Свежий обзор событий в стране и мире.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641808800,"stop":1641817800,"site":"magticom.ge","country":"US","_id":"UyvhQ4wRNq5d5XRd"} +{"title":"Amanpour","description":"Сводка новостей от знаменитой ведущей канала CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641834000,"stop":1641837600,"site":"magticom.ge","country":"US","_id":"WbsOCkmPH5gjmo4M"} +{"title":"Early Start","description":"Новости дня с Кристиной Романс и Дейвом Бриггсом.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641805200,"stop":1641808800,"site":"magticom.ge","country":"US","_id":"YB96P2mMO4TA0pID"} +{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641789900,"stop":1641790800,"site":"magticom.ge","country":"US","_id":"aDdCAlgqLG2yxM1m"} +{"title":"CNN Newsroom Sunday","description":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641772800,"stop":1641776400,"site":"magticom.ge","country":"US","_id":"aYCk87dUOAkCJE9x"} +{"title":"Fareed Zakaria GPS","description":"Интервью с главными игроками мировой политики.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641776400,"stop":1641780000,"site":"magticom.ge","country":"US","_id":"c1nCoWVetBZ3mn5q"} +{"title":"Inside Africa. 586-я серия","description":"586-я серия. Своеобразное \"путешествие\" по Африке - почувствуйте все разнообразие культур различных стран и регионов континента.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641785400,"stop":1641787200,"site":"magticom.ge","country":"US","_id":"goaDr7BsGGm3LCfz"} +{"title":"CNN Newsroom with Robyn Curnow","description":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641794400,"stop":1641797100,"site":"magticom.ge","country":"US","_id":"nixd3gRF1S1K0ZOs"} +{"title":"Marketplace Africa. 549-я серия","description":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641781800,"stop":1641782700,"site":"magticom.ge","country":"US","_id":"r1b8EvZc0tYs88ga"} +{"title":"Erin Burnett OutFront","description":"Обсуждение самых важных мировых тем в эфире канала CNN.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641855600,"stop":1641859200,"site":"magticom.ge","country":"US","_id":"sIQtUtowtATc7dLj"} +{"title":"Connect the World","description":"Актуальная мировая информация с разных континентов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641823200,"stop":1641825900,"site":"magticom.ge","country":"US","_id":"tXBIZ2BZBIkhnoTZ"} +{"title":"Quest Means Business","description":"Ричард Квест возглавляет группу экспертов и корреспондентов, чтобы предоставить актуальные факты, цифры и анализ из делового мира.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641841200,"stop":1641843900,"site":"magticom.ge","country":"US","_id":"xlE5epkjzdfUQpXO"} +{"title":"First Move with Julia Chatterley","description":"Несколько больших историй, связанных с открытием рынков в США.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641819600,"stop":1641823200,"site":"magticom.ge","country":"US","_id":"yEVXucyUomVmktMF"} +{"title":"Hala Gorani Tonight","description":"Используя свой 25-летний журналистский опыт, Хала Горани будет освещать ключевые события в картине дня посредством диалога с гостями и экспертами-аналитиками.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641837600,"stop":1641841200,"site":"magticom.ge","country":"US","_id":"yPgmYrWwfxHW3WUA"} +{"title":"World Sport","description":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","category":null,"icon":null,"channel":"CNNInternationalEurope.us","lang":"ru","start":1641797100,"stop":1641798000,"site":"magticom.ge","country":"US","_id":"zX70wOz5drExRTJX"} +{"title":"Robin Hood","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641822300,"stop":1641829200,"site":"dstv.com","country":"ZA","_id":"1AoKArQw6MxP6pVU"} +{"title":"The Water Diviner","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641776100,"stop":1641782700,"site":"dstv.com","country":"ZA","_id":"6v7w0SB4IlnfEEu3"} +{"title":"Bad Boys For Life","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641847200,"stop":1641850800,"site":"dstv.com","country":"ZA","_id":"83VRYvggmyfCzkOm"} +{"title":"12 Strong","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641814500,"stop":1641822300,"site":"dstv.com","country":"ZA","_id":"DbjwscjIuVDY8TPx"} +{"title":"Backdraft","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641801300,"stop":1641809400,"site":"dstv.com","country":"ZA","_id":"IwuwkjCKqWvio7ba"} +{"title":"Force Of Nature","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641841200,"stop":1641847200,"site":"dstv.com","country":"ZA","_id":"LP56HczEup0ed3Xx"} +{"title":"Mafia","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641809400,"stop":1641814500,"site":"dstv.com","country":"ZA","_id":"MM9DPxERAgGGak39"} +{"title":"The Last Witch Hunter","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641834780,"stop":1641841200,"site":"dstv.com","country":"ZA","_id":"MciJOpN3YCodj6Na"} +{"title":"Beyond The Line","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641796500,"stop":1641801300,"site":"dstv.com","country":"ZA","_id":"ZKA2s6QrM0xRrfGz"} +{"title":"Paranoia","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641790200,"stop":1641796500,"site":"dstv.com","country":"ZA","_id":"ZpdIZeSRhPycDX9D"} +{"title":"The Scorpion King","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641829200,"stop":1641834780,"site":"dstv.com","country":"ZA","_id":"doO4Lh1pAt6L6wHa"} +{"title":"Fatman","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641761700,"stop":1641767700,"site":"dstv.com","country":"ZA","_id":"fHahGuzHnU7xVEJX"} +{"title":"Outbreak","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641782700,"stop":1641790200,"site":"dstv.com","country":"ZA","_id":"mkvcMP4FMwL2a5ax"} +{"title":"Motherless Brooklyn","description":null,"category":null,"icon":null,"channel":"MNetMovies2.za","lang":"en","start":1641767700,"stop":1641776100,"site":"dstv.com","country":"ZA","_id":"nxTIAJsBwyXztRun"} diff --git a/tests/__data__/input/example.com.channels.xml b/tests/__data__/input/example.com_us.channels.xml similarity index 100% rename from tests/__data__/input/example.com.channels.xml rename to tests/__data__/input/example.com_us.channels.xml diff --git a/tests/commands/create-database.test.js b/tests/commands/create-database.test.js index 4cbc3fc8..bde74fd8 100644 --- a/tests/commands/create-database.test.js +++ b/tests/commands/create-database.test.js @@ -22,7 +22,7 @@ it('can create channels database', () => { site_id: '140', name: 'CNN International Europe', site: 'example.com', - channelsPath: 'tests/__data__/input/example.com.channels.xml', + channelsPath: 'tests/__data__/input/example.com_us.channels.xml', configPath: 'tests/__data__/input/example.com.config.js', cluster_id: 1 }) diff --git a/tests/commands/update-database.test.js b/tests/commands/update-database.test.js index a4c1effb..d2fcf55c 100644 --- a/tests/commands/update-database.test.js +++ b/tests/commands/update-database.test.js @@ -23,6 +23,7 @@ it('can update database', () => { '_id', 'category', 'channel', + 'country', 'description', 'icon', 'lang', diff --git a/tests/commands/update-guides.test.js b/tests/commands/update-guides.test.js index 91163c74..1e71b8f9 100644 --- a/tests/commands/update-guides.test.js +++ b/tests/commands/update-guides.test.js @@ -15,31 +15,32 @@ beforeEach(() => { 'tests/__data__/temp/database/programs.db' ) - execSync( - 'DB_DIR=tests/__data__/temp/database GUIDES_DIR=tests/__data__/output/guides node scripts/commands/update-guides.js', + const r = execSync( + 'DB_DIR=tests/__data__/temp/database PUBLIC_DIR=tests/__data__/output node scripts/commands/update-guides.js', { encoding: 'utf8' } ) + console.log(r) }) afterEach(() => { fs.rmdirSync('tests/__data__/temp', { recursive: true }) }) -it('can generate epg.xml', () => { - const output = content('tests/__data__/output/guides/epg.xml') - const expected = content('tests/__data__/expected/guides/epg.xml') +fit('can generate epg.xml', () => { + const output = content('tests/__data__/output/epg.xml') + const expected = content('tests/__data__/expected/epg.xml') expect(output).toBe(expected) }) -it('can generate /countries guides', () => { - const output1 = content('tests/__data__/output/guides/countries/us.epg.xml') - const expected1 = content('tests/__data__/expected/guides/countries/us.epg.xml') +it('can generate /guides', () => { + const output1 = content('tests/__data__/output/guides/us/magticom.ge.epg.xml') + const expected1 = content('tests/__data__/expected/guides/us/magticom.ge.epg.xml') expect(output1).toBe(expected1) - const output2 = content('tests/__data__/output/guides/countries/za.epg.xml') - const expected2 = content('tests/__data__/expected/guides/countries/za.epg.xml') + const output2 = content('tests/__data__/output/guides/za/dstv.com.epg.xml') + const expected2 = content('tests/__data__/expected/guides/za/dstv.com.epg.xml') expect(output2).toBe(expected2) })