Initial Commit

This commit is contained in:
2023-09-10 21:48:48 +02:00
commit 227cca7d31
791 changed files with 165200 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="tvmi.mt">
<channels>
<channel lang="mt" xmltv_id="TVM.mt" site_id="2">TVM</channel>
<channel lang="mt" xmltv_id="TVMnewsPlus.mt" site_id="3">TVMnews+</channel>
<channel lang="mt" xmltv_id="TVMsportPlus.mt" site_id="4">TVMsport+</channel>
</channels>
</site>

View File

@@ -0,0 +1,77 @@
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
module.exports = {
site: 'tvmi.mt',
days: 2,
url: function ({ date, channel }) {
return `https://tvmi.mt/schedule/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser: function ({ content, date }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
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),
icon: parseIcon($item),
start,
stop
})
})
return programs
}
}
function parseTitle($item) {
return $item('div > div:nth-child(2) > div:nth-child(2),a > div:nth-child(2) > div:nth-child(2)')
.text()
.trim()
}
function parseDescription($item) {
return $item('div > div:nth-child(2) > div:nth-child(3),a > div:nth-child(2) > div:nth-child(3)')
.text()
.trim()
}
function parseIcon($item) {
const bg = $item('div > div:nth-child(1) > div > div,a > div:nth-child(1) > div').data('bg')
return bg ? `https:${bg}` : null
}
function parseStart($item, date) {
const timeString = $item(
'div > div:nth-child(2) > div:nth-child(1),a > div:nth-child(2) > div:nth-child(1)'
)
.text()
.trim()
const [_, HH, mm] = timeString.match(/^(\d{2}):(\d{2})/) || [null, null, null]
if (!HH || !mm) return null
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm', 'Europe/Malta')
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('body > main > div.mt-8 > div').toArray()
}

View File

@@ -0,0 +1,53 @@
// npx epg-grabber --config=sites/tvmi.mt/tvmi.mt.config.js --channels=sites/tvmi.mt/tvmi.mt.channels.xml --output=guide.xml --days=2
const { parser, url } = require('./tvmi.mt.config.js')
const fs = require('fs')
const path = require('path')
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-10-29', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '2',
xmltv_id: 'TVM.mt'
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe('https://tvmi.mt/schedule/2/2022-10-29')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const results = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2022-10-29T03:30:00.000Z',
stop: '2022-10-29T04:00:00.000Z',
title: 'Bizzilla',
description:
'Storja ta tliet familji, tnejn minnhom miżżewġin bejniethom, u familja oħra li għalkemm mhijiex, bdaqshekk ma jfissirx li mhijiex parti ntegrali fil-kompliċitá li ilha għaddejja bejniethom għal dawn l-aħħar tletin sena.',
icon: 'https://dist4.tvmi.mt/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyNjEwNywiYXVkIjoiMTg4LjI0Mi40OC45MyIsImV4cCI6MTY2NzAxNjM1OH0.N4de761te_pRvWwSUnF6httRAzdukup5syejwXTUv8g/vod/663927/image.jpg'
})
expect(results[1]).toMatchObject({
start: '2022-10-29T04:00:00.000Z',
stop: '2022-10-29T04:30:00.000Z',
title: 'The Adventures of Puss in Boots',
icon: 'https://dist4.tvmi.mt/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyNjEwNywiYXVkIjoiMTg4LjI0Mi40OC45MyIsImV4cCI6MTY2NzAxNjM1OH0.N4de761te_pRvWwSUnF6httRAzdukup5syejwXTUv8g/vod/747336/image.jpg'
})
})
it('can handle empty guide', () => {
const result = parser({
content: `<!doctype html><html><head></head><body></body></html>`,
channel
})
expect(result).toMatchObject([])
})