mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
commit
ae8dca6c55
4 changed files with 131 additions and 0 deletions
4
sites/chada.ma/chada.ma.channels.xml
Normal file
4
sites/chada.ma/chada.ma.channels.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<channels>
|
||||||
|
<channel site="chada.ma" lang="fr" xmltv_id="ChadaTV.ma" site_id="1">Chada TV</channel>
|
||||||
|
</channels>
|
54
sites/chada.ma/chada.ma.config.js
Normal file
54
sites/chada.ma/chada.ma.config.js
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
const axios = require('axios');
|
||||||
|
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: 'chada.ma',
|
||||||
|
channels: 'chada.ma.channels.xml',
|
||||||
|
days: 1,
|
||||||
|
request: {
|
||||||
|
cache: {
|
||||||
|
ttl: 60 * 60 * 1000 // 1 hour
|
||||||
|
}
|
||||||
|
},
|
||||||
|
url() {
|
||||||
|
return 'https://chada.ma/fr/chada-tv/grille-tv/';
|
||||||
|
},
|
||||||
|
parser: function ({ content }) {
|
||||||
|
const $ = cheerio.load(content);
|
||||||
|
const programs = [];
|
||||||
|
|
||||||
|
$('#stopfix .posts-area h2').each((i, element) => {
|
||||||
|
const timeRange = $(element).text().trim();
|
||||||
|
const [start, stop] = timeRange.split(' - ').map(t => parseProgramTime(t.trim()));
|
||||||
|
|
||||||
|
const titleElement = $(element).next('div').next('h3');
|
||||||
|
const title = titleElement.text().trim();
|
||||||
|
|
||||||
|
const description = titleElement.next('div').text().trim() || 'No description available';
|
||||||
|
|
||||||
|
programs.push({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
start,
|
||||||
|
stop
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return programs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function parseProgramTime(timeStr) {
|
||||||
|
const timeZone = 'Africa/Casablanca';
|
||||||
|
const currentDate = dayjs().format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
return dayjs.tz(`${currentDate} ${timeStr}`, 'YYYY-MM-DD HH:mm', timeZone).format('YYYY-MM-DDTHH:mm:ssZ');
|
||||||
|
}
|
60
sites/chada.ma/chada.ma.test.js
Normal file
60
sites/chada.ma/chada.ma.test.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
const { parser, url } = require('./chada.ma.config.js')
|
||||||
|
const axios = require('axios')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
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)
|
||||||
|
|
||||||
|
jest.mock('axios')
|
||||||
|
|
||||||
|
const mockHtmlContent = `
|
||||||
|
<div class="pm0 col-md-8" id="stopfix">
|
||||||
|
<h2 class="posts-date">Programmes d'Aujourd'hui</h2>
|
||||||
|
<div class="posts-area">
|
||||||
|
<h2> <i class="fas fa-circle"></i>00:00 - 09:00</h2>
|
||||||
|
<div class="relativeme">
|
||||||
|
<a href="https://chada.ma/fr/emissions/bloc-prime-clips/">
|
||||||
|
<img class="programthumb" src="https://chada.ma/wp-content/uploads/2023/11/Autres-slides-clips-la-couverture.jpg">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<h3>Bloc Prime + Clips</h3>
|
||||||
|
<div class="authorbox"></div>
|
||||||
|
<div class="ssprogramme row"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url()).toBe('https://chada.ma/fr/chada-tv/grille-tv/')
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const content = mockHtmlContent
|
||||||
|
|
||||||
|
const result = parser({ content }).map(p => {
|
||||||
|
p.start = dayjs(p.start).tz('Africa/Casablanca').format('YYYY-MM-DDTHH:mm:ssZ')
|
||||||
|
p.stop = dayjs(p.stop).tz('Africa/Casablanca').format('YYYY-MM-DDTHH:mm:ssZ')
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toMatchObject([
|
||||||
|
{
|
||||||
|
title: "Bloc Prime + Clips",
|
||||||
|
description: "No description available",
|
||||||
|
start: dayjs.tz('00:00', 'HH:mm', 'Africa/Casablanca').format('YYYY-MM-DDTHH:mm:ssZ'),
|
||||||
|
stop: dayjs.tz('09:00', 'HH:mm', 'Africa/Casablanca').format('YYYY-MM-DDTHH:mm:ssZ')
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const result = parser({
|
||||||
|
content: '<div class="pm0 col-md-8" id="stopfix"><div class="posts-area"></div></div>'
|
||||||
|
})
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
13
sites/chada.ma/readme.md
Normal file
13
sites/chada.ma/readme.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# chada.ma
|
||||||
|
|
||||||
|
https://chada.ma/fr/chada-tv/grille-tv/
|
||||||
|
|
||||||
|
### Download the guide
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run grab --- --site=chada.ma
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test
|
||||||
|
|
||||||
|
npm test --- chada.ma
|
Loading…
Add table
Add a link
Reference in a new issue