From 02a20770ae880b3a5944f9a340a1959458bf25ad Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 6 Mar 2022 17:26:12 +0300 Subject: [PATCH 1/5] Create 9tv.co.il_il.channels.xml --- sites/9tv.co.il/9tv.co.il_il.channels.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 sites/9tv.co.il/9tv.co.il_il.channels.xml diff --git a/sites/9tv.co.il/9tv.co.il_il.channels.xml b/sites/9tv.co.il/9tv.co.il_il.channels.xml new file mode 100644 index 00000000..509a2f5e --- /dev/null +++ b/sites/9tv.co.il/9tv.co.il_il.channels.xml @@ -0,0 +1,6 @@ + + + + 9 канал + + From bedd4c08589fb8a30330ae5cfbaae38c8c18264e Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 6 Mar 2022 17:26:18 +0300 Subject: [PATCH 2/5] Create 9tv.co.il.test.js --- sites/9tv.co.il/9tv.co.il.test.js | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sites/9tv.co.il/9tv.co.il.test.js diff --git a/sites/9tv.co.il/9tv.co.il.test.js b/sites/9tv.co.il/9tv.co.il.test.js new file mode 100644 index 00000000..862194e5 --- /dev/null +++ b/sites/9tv.co.il/9tv.co.il.test.js @@ -0,0 +1,56 @@ +// npx epg-grabber --config=sites/9tv.co.il/9tv.co.il.config.js --channels=sites/9tv.co.il/9tv.co.il_il.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./9tv.co.il.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2022-03-06', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '#', + xmltv_id: 'Channel9.il' +} + +it('can generate valid url', () => { + expect(url({ date })).toBe( + 'https://www.9tv.co.il/BroadcastSchedule/getBrodcastSchedule?date=06/03/2022 00:00:00' + ) +}) + +it('can parse response', () => { + const content = `
  • 06:30

    Слепая

    Она не очень любит говорить о себе или о том, кто и зачем к ней обращается. Живет уединенно, в глуши. Но тех, кто приходит -принимает. Она видит судьбы. 
  • 09:10

    Орел и решка. Морской сезон

    Орел и решка. Морской сезон. Ведущие -Алина Астровская и Коля Серга.
  • ` + const result = parser({ content, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-06T04:30:00.000Z', + stop: '2022-03-06T07:10:00.000Z', + title: `Слепая`, + icon: 'https://www.9tv.co.il/download/pictures/img_id=8484.jpg', + description: + 'Она не очень любит говорить о себе или о том, кто и зачем к ней обращается. Живет уединенно, в глуши. Но тех, кто приходит -принимает. Она видит судьбы.' + }, + { + start: '2022-03-06T07:10:00.000Z', + stop: '2022-03-06T08:10:00.000Z', + icon: 'https://www.9tv.co.il/download/pictures/img_id=23694.jpg', + title: `Орел и решка. Морской сезон`, + description: 'Орел и решка. Морской сезон. Ведущие -Алина Астровская и Коля Серга.' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `` + }) + expect(result).toMatchObject([]) +}) From 288d0916f9fd279036bc0e39c58e4cc3fee7e20a Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 6 Mar 2022 17:27:52 +0300 Subject: [PATCH 3/5] Create 9tv.co.il.config.js --- sites/9tv.co.il/9tv.co.il.config.js | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sites/9tv.co.il/9tv.co.il.config.js diff --git a/sites/9tv.co.il/9tv.co.il.config.js b/sites/9tv.co.il/9tv.co.il.config.js new file mode 100644 index 00000000..32c77e37 --- /dev/null +++ b/sites/9tv.co.il/9tv.co.il.config.js @@ -0,0 +1,68 @@ +const cheerio = require('cheerio') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') +const customParseFormat = require('dayjs/plugin/customParseFormat') + +dayjs.extend(utc) +dayjs.extend(timezone) +dayjs.extend(customParseFormat) + +module.exports = { + site: '9tv.co.il', + url: function ({ date }) { + return `https://www.9tv.co.il/BroadcastSchedule/getBrodcastSchedule?date=${date.format( + 'DD/MM/YYYY 00:00:00' + )}` + }, + parser: function ({ content, date }) { + const programs = [] + const items = parseItems(content) + items.forEach(item => { + const prev = programs[programs.length - 1] + const $item = cheerio.load(item) + const start = parseStart($item, date) + if (prev) prev.stop = start + const stop = start.add(1, 'h') + programs.push({ + title: parseTitle($item), + icon: parseIcon($item), + description: parseDescription($item), + start, + stop + }) + }) + + return programs + } +} + +function parseStart($item, date) { + let time = $item('a > div.guide_list_time').text().trim() + + return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Asia/Jerusalem') +} + +function parseIcon($item) { + const backgroundImage = $item('a > div.guide_info_group > div.guide_info_pict').css( + 'background-image' + ) + if (!backgroundImage) return null + const [_, relativePath] = backgroundImage.match(/url\((.*)\)/) || [null, null] + + return relativePath ? `https://www.9tv.co.il${relativePath}` : null +} + +function parseDescription($item) { + return $item('a > div.guide_info_group > div.guide_txt_group > div').text().trim() +} + +function parseTitle($item) { + return $item('a > div.guide_info_group > div.guide_txt_group > h3').text().trim() +} + +function parseItems(content) { + const $ = cheerio.load(content) + + return $('li').toArray() +} From bae90edaaa2536df3307672bafb4f5fbde30a34b Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 6 Mar 2022 17:27:56 +0300 Subject: [PATCH 4/5] Create 9tv.co.il.yml --- .github/workflows/9tv.co.il.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/9tv.co.il.yml diff --git a/.github/workflows/9tv.co.il.yml b/.github/workflows/9tv.co.il.yml new file mode 100644 index 00000000..07fbd82f --- /dev/null +++ b/.github/workflows/9tv.co.il.yml @@ -0,0 +1,17 @@ +name: 9tv.co.il +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + workflow_run: + workflows: [_trigger] + types: + - completed +jobs: + load: + uses: ./.github/workflows/_load.yml + with: + site: ${{github.workflow}} + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} From d687ba7af9a0b658a89001a1cdc87370679e407d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 6 Mar 2022 17:33:11 +0300 Subject: [PATCH 5/5] Update lint.js --- scripts/commands/channels/lint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/commands/channels/lint.js b/scripts/commands/channels/lint.js index c14453a9..0436f6a4 100644 --- a/scripts/commands/channels/lint.js +++ b/scripts/commands/channels/lint.js @@ -10,7 +10,7 @@ const xsd = ` - +