mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
commit
2d3ab1ca5b
4 changed files with 1400 additions and 52 deletions
1342
sites/tvmi.mt/__data__/content.html
Normal file
1342
sites/tvmi.mt/__data__/content.html
Normal file
File diff suppressed because it is too large
Load diff
|
@ -8,20 +8,30 @@ dayjs.extend(timezone)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'tvmi.mt',
|
site: 'tvmi.mt',
|
||||||
url: function ({ date }) {
|
url: function ({ date, channel }) {
|
||||||
return `https://www.tvmi.mt/mt/tvmi/skeda/?sd-date=${date.format('YYYY-MM-DD')}`
|
return `https://tvmi.mt/schedule/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel, date }) {
|
parser: function ({ content, date }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const $item = cheerio.load(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({
|
programs.push({
|
||||||
title: parseTitle($item),
|
title: parseTitle($item),
|
||||||
description: parseDescription($item),
|
description: parseDescription($item),
|
||||||
icon: parseIcon($item),
|
icon: parseIcon($item),
|
||||||
start: parseStart($item, date),
|
start,
|
||||||
stop: parseStop($item, date)
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -30,41 +40,37 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle($item) {
|
function parseTitle($item) {
|
||||||
return $item('.programme-title').text().trim()
|
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) {
|
function parseDescription($item) {
|
||||||
return $item('.description').text().trim()
|
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) {
|
function parseIcon($item) {
|
||||||
return $item('.image').attr('src')
|
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) {
|
function parseStart($item, date) {
|
||||||
const times = $item('.title-time > .times').text().trim()
|
const timeString = $item(
|
||||||
const [_, HH, mm] = times.match(/^(\d{2}):(\d{2}) \-/) || [null, null, null]
|
'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
|
if (!HH || !mm) return null
|
||||||
|
|
||||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm', 'Europe/Malta')
|
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm', 'Europe/Malta')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop($item, date) {
|
function parseItems(content) {
|
||||||
const times = $item('.title-time > .times').text().trim()
|
|
||||||
const [_, HH, mm] = times.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, channel) {
|
|
||||||
const $ = cheerio.load(content)
|
const $ = cheerio.load(content)
|
||||||
const channelSchedules = $(
|
|
||||||
'#content > div.schedule > div.content > div.schedule-bottom > div.schedules > .channel-schedule'
|
|
||||||
).toArray()
|
|
||||||
if (!Array.isArray(channelSchedules)) return []
|
|
||||||
const index = parseInt(channel.site_id) - 1
|
|
||||||
if (!channelSchedules[index]) return []
|
|
||||||
|
|
||||||
return $(channelSchedules[index], '.programmes').find('.remodal').toArray()
|
return $('body > main > div.mt-8 > div').toArray()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,47 @@
|
||||||
// npx epg-grabber --config=sites/tvmi.mt/tvmi.mt.config.js --channels=sites/tvmi.mt/tvmi.mt_mt.channels.xml --output=guide.xml --days=2
|
// npx epg-grabber --config=sites/tvmi.mt/tvmi.mt.config.js --channels=sites/tvmi.mt/tvmi.mt_mt.channels.xml --output=guide.xml --days=2
|
||||||
|
|
||||||
const { parser, url } = require('./tvmi.mt.config.js')
|
const { parser, url } = require('./tvmi.mt.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const date = dayjs.utc('2022-04-21', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2022-10-29', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '1',
|
site_id: '2',
|
||||||
xmltv_id: 'TVM.mt'
|
xmltv_id: 'TVM.mt'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ date })).toBe('https://www.tvmi.mt/mt/tvmi/skeda/?sd-date=2022-04-21')
|
expect(url({ date, channel })).toBe('https://tvmi.mt/schedule/2/2022-10-29')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = `<!doctype html><html lang="en-US" xmlns:fb="https://www.facebook.com/2008/fbml" xmlns:addthis="https://www.addthis.com/help/api-spec" > <head></head> <body class="page-template page-template-page-templates page-template-new-schedule page-template-page-templatesnew-schedule-php page page-id-457931 page-child parent-pageid-554693 blog-1 tvmi-page"> <div id="page" class="site relative "> <div id="content" class="site-content relative"> <div class="schedule"> <div class="content"> <div class="schedule-bottom"> <div class="schedules"> <div class="channel-schedule"> <div class="programmes"> <a href="#sorelle8211ittieletstaun" class="programme-wrapper" style="left: 300px; min-width: 300px; max-width: 300px;"> <div class="programme " style="min-width: 294px; max-width: 294px;"> <div class="programme-info"> <p class="title">Sorelle – It-Tielet Staġun </p><p class="times">06:30 - 07:00</p></div></div></a> <div class="remodal" data-remodal-id="sorelle8211ittieletstaun" data-remodal-options="modifier: skeda-programme-popup"> <button data-remodal-action="close" class="remodal-close"></button> <img class="image" src="https://www.tvmi.mt/mt/wp-content/uploads/sites/1/2019/09/pink-leather-11-for-Airing.png" alt=""> <div class="bottom-modal"> <div class="modal-top"> <div class="title-time"> <p class="programme-title">Sorelle – It-Tielet Staġun</p><p class="times">06:30 - 07:00</p></div><img class="logo" src="https://www.tvmi.mt/mt/wp-content/themes/tvm/dist/images/tvm-logo-2021.png" alt=""> </div><p class="description">Fit-tielet staġun ta’ <em>Sorelle</em> se naraw lill-aħwa, flimkien ma’ dawk kollha li sofrew taħt idejn Leo, inklużi martu Bella u bintu Janice, ikomplu jagħmlu minn kollox biex jeħilsu darba għal dejjem minnu. Il-fatti se juruna li dan mhu se jkun faċli xejn għax Leo għandu għeruq fil-fond u għalhekk għad baqagħlu ħafna sorpriżi għalihom ilkoll. Dan waqt li flimkien ikomplu jaraw kif jesponu lil dawk li b’xi mod jew ieħor ikun qed jirnexxilhom jaħarbu mill-awtoritajiet.</p><div class="flex" style="margin-left: -10px; margin-right: -10px;"> <a class="more-button" href="https://www.tvmi.mt/mt/tvmi/programmes/sorelle-it-tielet-stagun/"> ARA IKTAR </a> </div></div></div><a href="#ta8217filgodu" class="programme-wrapper" style="left: 600px; min-width: 1200px; max-width: 1200px;"> <div class="programme " style="min-width: 1194px; max-width: 1194px;"> <div class="programme-info"> <p class="title">Ta’ Filgħodu </p><p class="times">07:00 - 09:00</p></div></div></a> <div class="remodal" data-remodal-id="ta8217filgodu" data-remodal-options="modifier: skeda-programme-popup"> <button data-remodal-action="close" class="remodal-close"></button> <img class="image" src="https://www.tvmi.mt/mt/wp-content/uploads/sites/1/2021/09/ta-Filghodu-02.jpeg" alt=""> <div class="bottom-modal"> <div class="modal-top"> <div class="title-time"> <p class="programme-title">Ta’ Filgħodu</p><p class="times">07:00 - 09:00</p></div><img class="logo" src="https://www.tvmi.mt/mt/wp-content/themes/tvm/dist/images/tvm-logo-2021.png" alt=""> </div><p class="description"><strong><em>Ta' Filgħodu</em></strong> se jkun qed jibda jum ġdid fuq nota pożittiva; b'informazzjoni u aġġornamenti regolari dwar it-traffiku, it-temp u l-ewwel faċċati tal-gazzetti mal-ewwel tazza cafè. Dan iwassalna biex flimkien ma’ Ray Attard niltaqgħu mal-protagonisti li minn wara l-kwinti jkunu qed jagħmlu l-ġurnata ta’ kulħadd waħda isbaħ fl-oqsma rispettivi tagħhom. <em>Ta' Filgħodu</em> se jkun kurrenti imma din id-darba minn angoli oħra ta’ interess, li bis-sewwa se jkunu qed jgħarrfu lit-telespettaturi b'dak kollu li jkun qed jiġri madwarna. Preżentazzjoni ta’ Ray Attard.</p><div class="flex" style="margin-left: -10px; margin-right: -10px;"> <a class="more-button" href="https://www.tvmi.mt/mt/tvmi/programmes/ta-filghodu/"> ARA IKTAR </a> </div></div></div></div></div><div class="channel-schedule"> <div class="programmes"> <a href="#euronews" class="programme-wrapper" style="left: -3600px; min-width: 150px; max-width: 150px;"> <div class="programme " style="min-width: 144px; max-width: 144px;"> <div class="programme-info"> <p class="title">EuroNews </p><p class="times">00:00 - 00:15</p></div></div></a> </div></div></div></div></div></div></div></div></body></html>`
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||||
const result = parser({ content, channel, date }).map(p => {
|
const results = parser({ content, date }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(results[0]).toMatchObject({
|
||||||
{
|
start: '2022-10-29T03:30:00.000Z',
|
||||||
start: '2022-04-21T04:30:00.000Z',
|
stop: '2022-10-29T04:00:00.000Z',
|
||||||
stop: '2022-04-21T05:00:00.000Z',
|
title: 'Bizzilla',
|
||||||
title: 'Sorelle – It-Tielet Staġun',
|
|
||||||
description:
|
description:
|
||||||
'Fit-tielet staġun ta’ Sorelle se naraw lill-aħwa, flimkien ma’ dawk kollha li sofrew taħt idejn Leo, inklużi martu Bella u bintu Janice, ikomplu jagħmlu minn kollox biex jeħilsu darba għal dejjem minnu. Il-fatti se juruna li dan mhu se jkun faċli xejn għax Leo għandu għeruq fil-fond u għalhekk għad baqagħlu ħafna sorpriżi għalihom ilkoll. Dan waqt li flimkien ikomplu jaraw kif jesponu lil dawk li b’xi mod jew ieħor ikun qed jirnexxilhom jaħarbu mill-awtoritajiet.',
|
'Storja ta’ tliet familji, tnejn minnhom miżżewġin bejniethom, u familja oħra li għalkemm mhijiex, b’daqshekk ma jfissirx li mhijiex parti ntegrali fil-kompliċitá li ilha għaddejja bejniethom għal dawn l-aħħar tletin sena.',
|
||||||
icon: 'https://www.tvmi.mt/mt/wp-content/uploads/sites/1/2019/09/pink-leather-11-for-Airing.png'
|
icon: 'https://dist4.tvmi.mt/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyNjEwNywiYXVkIjoiMTg4LjI0Mi40OC45MyIsImV4cCI6MTY2NzAxNjM1OH0.N4de761te_pRvWwSUnF6httRAzdukup5syejwXTUv8g/vod/663927/image.jpg'
|
||||||
},
|
})
|
||||||
{
|
|
||||||
start: '2022-04-21T05:00:00.000Z',
|
expect(results[1]).toMatchObject({
|
||||||
stop: '2022-04-21T07:00:00.000Z',
|
start: '2022-10-29T04:00:00.000Z',
|
||||||
title: 'Ta’ Filgħodu',
|
stop: '2022-10-29T04:30:00.000Z',
|
||||||
description:
|
title: 'The Adventures of Puss in Boots',
|
||||||
"Ta' Filgħodu se jkun qed jibda jum ġdid fuq nota pożittiva; b'informazzjoni u aġġornamenti regolari dwar it-traffiku, it-temp u l-ewwel faċċati tal-gazzetti mal-ewwel tazza cafè. Dan iwassalna biex flimkien ma’ Ray Attard niltaqgħu mal-protagonisti li minn wara l-kwinti jkunu qed jagħmlu l-ġurnata ta’ kulħadd waħda isbaħ fl-oqsma rispettivi tagħhom. Ta' Filgħodu se jkun kurrenti imma din id-darba minn angoli oħra ta’ interess, li bis-sewwa se jkunu qed jgħarrfu lit-telespettaturi b'dak kollu li jkun qed jiġri madwarna. Preżentazzjoni ta’ Ray Attard.",
|
icon: 'https://dist4.tvmi.mt/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMyNjEwNywiYXVkIjoiMTg4LjI0Mi40OC45MyIsImV4cCI6MTY2NzAxNjM1OH0.N4de761te_pRvWwSUnF6httRAzdukup5syejwXTUv8g/vod/747336/image.jpg'
|
||||||
icon: 'https://www.tvmi.mt/mt/wp-content/uploads/sites/1/2021/09/ta-Filghodu-02.jpeg'
|
})
|
||||||
}
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<site site="tvmi.mt">
|
<site site="tvmi.mt">
|
||||||
<channels>
|
<channels>
|
||||||
<channel lang="mt" xmltv_id="TVM.mt" site_id="1">TVM</channel>
|
<channel lang="mt" xmltv_id="TVM.mt" site_id="2">TVM</channel>
|
||||||
<channel lang="mt" xmltv_id="TVMNewsPlus.mt" site_id="2">TVMNews+</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>
|
</channels>
|
||||||
</site>
|
</site>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue