mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #2537 from fraudiay79/snrt.ma
Add SNRT (Moroccan National TV)
This commit is contained in:
commit
24a90462a5
6 changed files with 23064 additions and 0 deletions
3500
sites/snrt.ma/__data__/content.html
Normal file
3500
sites/snrt.ma/__data__/content.html
Normal file
File diff suppressed because it is too large
Load diff
19391
sites/snrt.ma/_data_/content.html
Normal file
19391
sites/snrt.ma/_data_/content.html
Normal file
File diff suppressed because it is too large
Load diff
21
sites/snrt.ma/readme.md
Normal file
21
sites/snrt.ma/readme.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# snrt.ma
|
||||||
|
|
||||||
|
https://www.snrt.ma/ar/node/1208
|
||||||
|
|
||||||
|
### Download the guide
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run grab --- --site=snrt.ma
|
||||||
|
```
|
||||||
|
|
||||||
|
### Update channel list
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run channels:parse --- --config=./sites/snrt.ma/snrt.ma.config.js --output=./sites/snrt.ma/snrt.ma.channels.xml
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm test --- snrt.ma
|
||||||
|
```
|
10
sites/snrt.ma/snrt.ma.channels.xml
Normal file
10
sites/snrt.ma/snrt.ma.channels.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<channels>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="AlAoula.ma" site_id="1208">Al Aoula</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="Laayoune.ma" site_id="4069">Laâyoune</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="Arryadia.ma" site_id="4070">Arryadia</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="Athaqafia.ma" site_id="4071">Athaqafia</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="AlMaghribia.ma" site_id="4072">Al Maghribia</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="Assadissa.ma" site_id="4073">Assadissa</channel>
|
||||||
|
<channel site="snrt.ma" lang="ar" xmltv_id="Tamazight.ma" site_id="4075">Tamazight</channel>
|
||||||
|
</channels>
|
97
sites/snrt.ma/snrt.ma.config.js
Normal file
97
sites/snrt.ma/snrt.ma.config.js
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
const cheerio = require('cheerio')
|
||||||
|
const { DateTime } = require('luxon')
|
||||||
|
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)
|
||||||
|
|
||||||
|
const channel = [{ site_id: '1208', xmltv_id: 'AlAoula.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4069', xmltv_id: 'Laayoune.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4070', xmltv_id: 'Arryadia.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4071', xmltv_id: 'Athaqafia.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4072', xmltv_id: 'AlMaghribia.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4073', xmltv_id: 'Assadissa.ma', lang: 'ar' },
|
||||||
|
{ site_id: '4075', xmltv_id: 'Tamazight.ma', lang: 'ar' }]
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
site: 'snrt.ma',
|
||||||
|
channels: 'snrt.ma.channels.xml',
|
||||||
|
days: 2,
|
||||||
|
url: function ({ channel }) {
|
||||||
|
return `https://www.snrt.ma/ar/node/${channel.site_id}`
|
||||||
|
},
|
||||||
|
request: {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
},
|
||||||
|
data: function ({ date }) {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.append('_method', 'POST')
|
||||||
|
params.append('data-date', date.format('YYYYMMDD'))
|
||||||
|
params.append('current_date', date.format('YYYYMMDD'))
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
},
|
||||||
|
parser: function ({ content, date }) {
|
||||||
|
const programs = []
|
||||||
|
const items = parseItems(content)
|
||||||
|
items.forEach(item => {
|
||||||
|
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),
|
||||||
|
description: parseDescription($item),
|
||||||
|
category: parseCategory($item),
|
||||||
|
start,
|
||||||
|
stop
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return programs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart($item, date) {
|
||||||
|
const timeString = $item('.grille-time').text().trim()
|
||||||
|
const [hours, minutes] = timeString.split('H').map(Number)
|
||||||
|
const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:00`
|
||||||
|
|
||||||
|
const dateString = `${date.format('YYYY-MM-DD')} ${formattedTime}`
|
||||||
|
|
||||||
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm:ss', 'Africa/Casablanca')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function parseTitle($item) {
|
||||||
|
return $item('.program-title-sm').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseDescription($item) {
|
||||||
|
return $item('.program-description-sm').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory($item) {
|
||||||
|
return $item('.genre-first').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
|
return $('.grille-line').toArray()
|
||||||
|
}
|
45
sites/snrt.ma/snrt.ma.test.js
Normal file
45
sites/snrt.ma/snrt.ma.test.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
const { parser, url } = require('./snrt.ma.config.js')
|
||||||
|
const cheerio = require('cheerio')
|
||||||
|
const { DateTime } = require('luxon')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
|
||||||
|
const date = dayjs.utc('2024-12-19', 'YYYY-MM-DD').startOf('d')
|
||||||
|
const channel = { site_id: '1208', xmltv_id: 'AlAoula.ma', lang: 'ar' }
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url({ channel })).toBe('https://www.snrt.ma/ar/node/1208')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||||
|
const results = parser({ date, content }).map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(results[0]).toMatchObject({
|
||||||
|
"category": "القرآن الكريم",
|
||||||
|
"description": "",
|
||||||
|
"start": "2024-12-19T06:00:00.000Z",
|
||||||
|
"stop": "2024-12-19T06:10:00.000Z",
|
||||||
|
"stop": "2024-12-19T06:30:00.000Z",
|
||||||
|
"title": "ﺍﻟﺴﻼﻡ ﺍﻟﻮﻃﻨﻲ + ﺍﻟﻘﺮﺁﻥ ﺍﻟﻜﺮﻳﻢ"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const result = parser({
|
||||||
|
date,
|
||||||
|
channel: channel,
|
||||||
|
content: '<!DOCTYPE html><html lang="ar" dir="rtl"><head></head><body></body></html>'
|
||||||
|
})
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue