diff --git a/.github/workflows/zuragt.mn.yml b/.github/workflows/zuragt.mn.yml new file mode 100644 index 00000000..088b1353 --- /dev/null +++ b/.github/workflows/zuragt.mn.yml @@ -0,0 +1,17 @@ +name: zuragt.mn +on: + schedule: + - cron: '0 3 * * *' + 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 }} diff --git a/sites/zuragt.mn/__data__/content.html b/sites/zuragt.mn/__data__/content.html new file mode 100644 index 00000000..8e3e4b96 --- /dev/null +++ b/sites/zuragt.mn/__data__/content.html @@ -0,0 +1,234 @@ + + + + + + + + + + + +МҮОНТ | ZURAGT + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + + +
+
+
+
+ +

Энэ хувилбар нь гар утас болон таблетад илүү тохиромжтой. Хэрвээ та том дэлгэцээр зочилж байгаа бол десктоп хувилбардээр дарна уу.

+
+
+
    +
  • +
    +
    +
    07:00
    +
    “Цагийн хүрд” мэдээллийн хөтөлбөр
    +
  • +
  • +
    +
    +
    08:00
    +
    Бидний дуртай кино: “Ромд өнгөрүүлсэн гэрэлт өдрүүд” УСК
    +
  • +
  • +
    +
    +
    10:10
    +
    “Шинжлэх ухааны цаг” хөтөлбөр
    +
  • +
  • +
    +
    +
    11:00
    +
    “Мэдээ” /шууд/
    +
  • +
  • +
    +
    +
    11:20
    +
    Дэлхийн Брайль үсгийн өдөр
    +
  • +
  • +
    +
    +
    11:40
    +
    “Болорцом-40” яруу найргийн наадам 3-р хэсэг
    +
  • +
  • +
    +
    +
    12:40
    +
    “Шинэ ажилтан” Зорилтот цуврал нэвтрүүлэг /6/
    +
  • +
  • +
    +
    +
    13:40
    +
    “Буржгар үст” УСК
    +
  • +
  • +
    +
    +
    15:00
    +
    “Монголын баялаг 330” Дундговь аймаг. Говь-Угтаал сум
    +
  • +
  • +
    +
    +
    15:40
    +
    Хайрлаарай: Үл хайхрал
    +
  • +
  • +
    +
    +
    16:40
    +
    Охин нь байна...
    +
  • +
  • +
    +
    +
    17:10
    +
    Ардын эрх
    +
  • +
  • +
    +
    +
    18:10
    +
    “Хатагины уг сурвалж, үр сад” 4-р хэсэг
    +
  • +
  • +
    +
    +
    18:40
    +
    “Ном хож” Уралдаант цэнгээнт нэвтрүүлэг
    +
  • +
  • +
    +
    +
    19:40
    +
    Жайка Монголд
    +
  • +
  • +
    +
    +
    19:55
    +
    MNB энэ 7 хоногт
    +
  • +
  • +
    +
    +
    20:00
    +
    “Цагийн хүрд ” мэдээллийн хөтөлбөр
    +
  • +
  • +
    +
    +
    21:00
    +
    MNB энэ 7 хоногт
    +
  • +
  • +
    +
    +
    21:10
    +
    Зүрхэнд мөнхөрсөн аялгуу
    +
  • +
  • +
    +
    +
    22:40
    +
    “Гарах гарцгүй” УСК
    +
  • +
  • +
    +
    +
    00:40
    +
    Эфир завсарлав
    +
  • +
+
+ +
+
+ + \ No newline at end of file diff --git a/sites/zuragt.mn/__data__/no_content.html b/sites/zuragt.mn/__data__/no_content.html new file mode 100644 index 00000000..6738e9ad --- /dev/null +++ b/sites/zuragt.mn/__data__/no_content.html @@ -0,0 +1,110 @@ + + + + + + + + + + + +МҮОНТ | ZURAGT + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + + +
+
+
+
+ +

Энэ хувилбар нь гар утас болон таблетад илүү тохиромжтой. Хэрвээ та том дэлгэцээр зочилж байгаа бол десктоп хувилбардээр дарна уу.

+
+
+
+ +

Уучлаарай, ямар нэг хөтөлбөр олдсонгүй.

+
+
+ +
+
+ + \ No newline at end of file diff --git a/sites/zuragt.mn/zuragt.mn.channels.xml b/sites/zuragt.mn/zuragt.mn.channels.xml new file mode 100644 index 00000000..deadc105 --- /dev/null +++ b/sites/zuragt.mn/zuragt.mn.channels.xml @@ -0,0 +1,41 @@ + + + + AsianBox + Bloomberg TV MGL + C1 + Central TV + Dream + Eco Channel + Боловсрол ТВ + ETV HD + МҮОНТ + MNB Sport + MNC + Монгол ТВ + MovieBox + NTN + NTV + SBN + SPS Global + SPS National + NBA TV SPS + SPS Plus + SPS Prime + Star TV + Сүлд ТВ + Суваг 1 + TenGer + TM + MN25 + TV5 + TV8 + TV9 + UBS-1 + + + + + + + diff --git a/sites/zuragt.mn/zuragt.mn.config.js b/sites/zuragt.mn/zuragt.mn.config.js new file mode 100644 index 00000000..54382711 --- /dev/null +++ b/sites/zuragt.mn/zuragt.mn.config.js @@ -0,0 +1,89 @@ +const dayjs = require('dayjs') +const axios = require('axios') +const cheerio = require('cheerio') +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: 'zuragt.mn', + days: 2, + url: function ({ channel, date }) { + return `https://m.zuragt.mn/channel/${channel.site_id}/?date=${date.format('YYYY-MM-DD')}` + }, + request: { + maxRedirects: 0, + validateStatus: function (status) { + return status >= 200 && status < 303 + } + }, + parser: async function ({ content, date }) { + let programs = [] + const items = parseItems(content) + for (let item of items) { + const prev = programs[programs.length - 1] + const $item = cheerio.load(item) + let start = parseStart($item, date) + if (prev) { + if (start.isBefore(prev.start)) { + start = start.add(1, 'd') + date = date.add(1, 'd') + } + prev.stop = start + } + const stop = start.add(30, 'm') + programs.push({ + title: parseTitle($item), + start, + stop + }) + } + + return programs + }, + async channels() { + let html = await axios + .get(`https://www.zuragt.mn/`) + .then(r => r.data) + .catch(console.log) + let $ = cheerio.load(html) + + const items = $('.tv-box > ul > li').toArray() + return items + .map(item => { + const name = $(item).text().trim() + const link = $(item).find('a').attr('href') + + if (!link) return null + + const [_, site_id] = link.match(/\/channel\/(.*)\//) || [null, null] + + return { + lang: 'mn', + site_id, + name + } + }) + .filter(Boolean) + } +} + +function parseTitle($item) { + return $item('.program').text().trim() +} + +function parseStart($item, date) { + const time = $item('.time') + + return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Asia/Ulaanbaatar') +} + +function parseItems(content) { + const $ = cheerio.load(content) + + return $('body > div > div > div > ul > li').toArray() +} diff --git a/sites/zuragt.mn/zuragt.mn.test.js b/sites/zuragt.mn/zuragt.mn.test.js new file mode 100644 index 00000000..839ca115 --- /dev/null +++ b/sites/zuragt.mn/zuragt.mn.test.js @@ -0,0 +1,50 @@ +// npm run channels:parse -- --config=./sites/zuragt.mn/zuragt.mn.config.js --output=./sites/zuragt.mn/zuragt.mn.channels.xml +// npx epg-grabber --config=sites/zuragt.mn/zuragt.mn.config.js --channels=sites/zuragt.mn/zuragt.mn.channels.xml --output=guide.xml --days=2 + +const { parser, url, request } = require('./zuragt.mn.config.js') +const fs = require('fs') +const path = require('path') +const axios = require('axios') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +jest.mock('axios') + +const date = dayjs.utc('2023-01-15', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'mnb', + xmltv_id: 'MNB.mn' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://m.zuragt.mn/channel/mnb/?date=2023-01-15') +}) + +it('can generate valid request object', () => { + expect(request.maxRedirects).toBe(0) + expect(request.validateStatus(302)).toBe(true) +}) + +it('can parse response', async () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html')) + let results = await parser({ content, date }) + results = results.map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results[0]).toMatchObject({ + start: '2023-01-14T23:00:00.000Z', + stop: '2023-01-15T00:00:00.000Z', + title: '“Цагийн хүрд” мэдээллийн хөтөлбөр' + }) +}) + +it('can handle empty guide', async () => { + const result = await parser({ content: '' }) + expect(result).toMatchObject([]) +})