diff --git a/package-lock.json b/package-lock.json index 11f9a120..2658dbcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "commander": "^8.2.0", "csv-parser": "^3.0.0", "dayjs": "^1.10.4", - "epg-grabber": "^0.15.1", + "epg-grabber": "^0.15.2", "epg-parser": "^0.1.6", "form-data": "^4.0.0", "glob": "^7.2.0", @@ -2007,9 +2007,9 @@ } }, "node_modules/epg-grabber": { - "version": "0.15.1", - "resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.15.1.tgz", - "integrity": "sha512-77lWOJllKrkv8LD1cl0bWGE+o4HRXy1vRHjvl23Yk1859jjYNPBPWj93KJUDXHBgtFA996t2R6AP9E+AC0uLWQ==", + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.15.2.tgz", + "integrity": "sha512-waXwyUkp+O9Wmos95H2DUb5KyFAgm6GrFUcsWY19G7vme4qx9paH2DhKlw7pPT/aIe5sTJm/jSNG25xTK1K8Fw==", "dependencies": { "axios": "^0.21.1", "axios-cookiejar-support": "^1.0.1", @@ -6431,9 +6431,9 @@ "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==" }, "epg-grabber": { - "version": "0.15.1", - "resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.15.1.tgz", - "integrity": "sha512-77lWOJllKrkv8LD1cl0bWGE+o4HRXy1vRHjvl23Yk1859jjYNPBPWj93KJUDXHBgtFA996t2R6AP9E+AC0uLWQ==", + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.15.2.tgz", + "integrity": "sha512-waXwyUkp+O9Wmos95H2DUb5KyFAgm6GrFUcsWY19G7vme4qx9paH2DhKlw7pPT/aIe5sTJm/jSNG25xTK1K8Fw==", "requires": { "axios": "^0.21.1", "axios-cookiejar-support": "^1.0.1", diff --git a/package.json b/package.json index 2f04153c..7bcf48e6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "commander": "^8.2.0", "csv-parser": "^3.0.0", "dayjs": "^1.10.4", - "epg-grabber": "^0.15.1", + "epg-grabber": "^0.15.2", "epg-parser": "^0.1.6", "form-data": "^4.0.0", "glob": "^7.2.0", diff --git a/scripts/commands/load-cluster.js b/scripts/commands/load-cluster.js index 070f14e0..4592c441 100644 --- a/scripts/commands/load-cluster.js +++ b/scripts/commands/load-cluster.js @@ -46,11 +46,13 @@ async function main() { } }) - const programs = await grabber.grab(channel, config, (data, err) => { + const programs = await grabber.grab(channel, config, async (data, err) => { + await db.channels.update({ _id: channel._id }, { $set: { logo: data.channel.logo } }) + logger.info( - `[${i}/${total}] ${config.site} - ${data.channel.xmltv_id} - ${data.date.format( - 'MMM D, YYYY' - )} (${data.programs.length} programs)` + `[${i}/${total}] ${channel.site} - ${data.id} - ${data.date.format('MMM D, YYYY')} (${ + data.programs.length + } programs)` ) if (err) logger.error(err.message) @@ -62,7 +64,7 @@ async function main() { clusterLog, JSON.stringify({ _id: channel._id, - site: config.site, + site: channel.site, country: channel.country, gid: channel.gid, programs @@ -70,6 +72,8 @@ async function main() { ) } + db.channels.compact() + logger.info(`Done in ${timer.format('HH[h] mm[m] ss[s]')}`) } diff --git a/tests/__data__/expected/api/channels.json b/tests/__data__/expected/api/channels.json index fffca454..a3593aa1 100644 --- a/tests/__data__/expected/api/channels.json +++ b/tests/__data__/expected/api/channels.json @@ -1 +1 @@ -[{"id":"BravoEast.us","name":["Bravo East"],"logo":"https://www.directv.com/images/logos/channels/dark/large/579.png","country":"US","guides":["https://iptv-org.github.io/epg/guides/us/directv.com.epg.xml"]},{"id":"CNNInternationalEurope.us","name":["CNN International Europe","CNN Int"],"logo":"https://proxymedia.woopic.com/api/v1/images/553%2Flogos%2Fv2%2Flogos%2Flivetv_cnn%2F20151026_092415%2FwebTVLogo%2Flogo_180x96.png","country":"US","guides":["https://iptv-org.github.io/epg/guides/fr/chaines-tv.orange.fr.epg.xml","https://iptv-org.github.io/epg/guides/ge/magticom.ge.epg.xml"]},{"id":"MNetMovies2.za","name":["M-Net Movies 2"],"logo":"https://rndcdn.dstv.com/dstvcms/2020/08/31/M-Net_Movies_2_Logo_4-3_lightbackground_xlrg.png","country":"ZA","guides":["https://iptv-org.github.io/epg/guides/zw/dstv.com.epg.xml"]}] \ No newline at end of file +[{"id":"BravoEast.us","name":["Bravo East"],"logo":"https://www.directv.com/images/logos/channels/dark/large/579.png","country":"US","guides":["https://iptv-org.github.io/epg/guides/us/directv.com.epg.xml"]},{"id":"CNNInternationalEurope.us","name":["CNN International Europe","CNN Int"],"logo":"https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg","country":"US","guides":["https://iptv-org.github.io/epg/guides/fr/chaines-tv.orange.fr.epg.xml","https://iptv-org.github.io/epg/guides/ge/magticom.ge.epg.xml"]},{"id":"MNetMovies2.za","name":["M-Net Movies 2"],"logo":"https://rndcdn.dstv.com/dstvcms/2020/08/31/M-Net_Movies_2_Logo_4-3_lightbackground_xlrg.png","country":"ZA","guides":["https://iptv-org.github.io/epg/guides/zw/dstv.com.epg.xml"]}] \ No newline at end of file diff --git a/tests/__data__/input/database/channels.db b/tests/__data__/input/database/channels.db index 1e2198ee..98d3979a 100644 --- a/tests/__data__/input/database/channels.db +++ b/tests/__data__/input/database/channels.db @@ -1,4 +1,4 @@ {"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","logo":"https://www.directv.com/images/logos/channels/dark/large/579.png","name":"Bravo East","site":"directv.com","channelsPath":"sites/directv.com/directv.com_us.channels.xml","configPath":"sites/directv.com/directv.com.config.js","gid":"us","cluster_id":84,"country":"US","_id":"00AluKCrCnfgrl8W"} -{"lang":"fr","country":"US","xmltv_id":"CNNInternationalEurope.us","site_id":"53","logo":"https://proxymedia.woopic.com/api/v1/images/553%2Flogos%2Fv2%2Flogos%2Flivetv_cnn%2F20151026_092415%2FwebTVLogo%2Flogo_180x96.png","name":"CNN International Europe","site":"chaines-tv.orange.fr","channelsPath":"sites/chaines-tv.orange.fr/chaines-tv.orange.fr_fr.channels.xml","configPath":"sites/chaines-tv.orange.fr/chaines-tv.orange.fr.config.js","gid":"fr","cluster_id":1,"_id":"0Wefq0oMR3feCcuY"} -{"lang":"ru","country":"US","xmltv_id":"CNNInternationalEurope.us","site_id":"140","logo":"https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg","name":"CNN Int","site":"magticom.ge","channelsPath":"sites/magticom.ge/magticom.ge_ge.channels.xml","configPath":"sites/magticom.ge/magticom.ge.config.js","gid":"ge","cluster_id":1,"_id":"1XzrxNkSF2AQNBrT"} +{"lang":"fr","country":"US","xmltv_id":"CNNInternationalEurope.us","site_id":"53","logo":null,"name":"CNN International Europe","site":"chaines-tv.orange.fr","channelsPath":"sites/chaines-tv.orange.fr/chaines-tv.orange.fr_fr.channels.xml","configPath":"tests/__data__/input/sites/example.com.config.js","gid":"fr","cluster_id":1,"_id":"0Wefq0oMR3feCcuY"} +{"lang":"ru","country":"US","xmltv_id":"CNNInternationalEurope.us","site_id":"140","logo":"https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg","name":"CNN Int","site":"magticom.ge","channelsPath":"sites/magticom.ge/magticom.ge_ge.channels.xml","configPath":"tests/__data__/input/sites/example.com.config.js","gid":"ge","cluster_id":1,"_id":"1XzrxNkSF2AQNBrT"} {"lang":"en","country":"ZA","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","logo":"https://rndcdn.dstv.com/dstvcms/2020/08/31/M-Net_Movies_2_Logo_4-3_lightbackground_xlrg.png","name":"M-Net Movies 2","site":"dstv.com","channelsPath":"sites/dstv.com/dstv.com_zw.channels.xml","configPath":"sites/dstv.com/dstv.com.config.js","gid":"zw","cluster_id":120,"_id":"1lnhXpN7g0ER5XwN"} diff --git a/tests/__data__/input/sites/example.com.config.js b/tests/__data__/input/sites/example.com.config.js index 20384029..3d181feb 100644 --- a/tests/__data__/input/sites/example.com.config.js +++ b/tests/__data__/input/sites/example.com.config.js @@ -3,6 +3,9 @@ module.exports = { url() { return `https://example.com` }, + logo() { + return 'https://example.com/logo.png' + }, parser() { return [] } diff --git a/tests/commands/load-cluster.test.js b/tests/commands/load-cluster.test.js index f7152cc9..6f4db1d7 100644 --- a/tests/commands/load-cluster.test.js +++ b/tests/commands/load-cluster.test.js @@ -3,6 +3,7 @@ const path = require('path') const { execSync } = require('child_process') beforeEach(() => { + fs.rmdirSync('tests/__data__/temp', { recursive: true }) fs.rmdirSync('tests/__data__/output', { recursive: true }) fs.mkdirSync('tests/__data__/output') fs.mkdirSync('tests/__data__/temp/database', { recursive: true }) @@ -12,15 +13,11 @@ beforeEach(() => { ) execSync( - 'DB_DIR=tests/__data__/temp/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1 --timeout=1', + 'DB_DIR=tests/__data__/temp/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1 --timeout=10000', { encoding: 'utf8' } ) }) -afterEach(() => { - fs.rmdirSync('tests/__data__/temp', { recursive: true }) -}) - it('can load cluster', () => { const output = content('tests/__data__/output/logs/load-cluster/cluster_1.log') @@ -37,6 +34,18 @@ it('can load cluster', () => { country: 'US', gid: 'ge' }) + + const database = content('tests/__data__/temp/database/channels.db') + + expect(database[1]).toMatchObject({ + _id: '0Wefq0oMR3feCcuY', + logo: 'https://example.com/logo.png' + }) + + expect(database[2]).toMatchObject({ + _id: '1XzrxNkSF2AQNBrT', + logo: 'https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg' + }) }) function content(filepath) {