Merge pull request #294 from iptv-org/update-turksatkablo-com-tr

Update turksatkablo.com.tr
This commit is contained in:
Aleksandr Statciuk 2021-11-25 00:57:56 +03:00 committed by GitHub
commit f10f72e72a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 28 deletions

View file

@ -9,26 +9,28 @@ dayjs.extend(customParseFormat)
module.exports = {
site: 'turksatkablo.com.tr',
ignore: true, // NOTE: server is not stable
url: function ({ date }) {
return `https://www.turksatkablo.com.tr/userUpload/EPG/y.json?_=${date.valueOf()}`
},
parser: function ({ content, channel, date }) {
let PM = false
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const prev = programs[programs.length - 1]
let start = parseStart(item, date)
if (start.hour() > 11) PM = true
if (start.hour() < 12 && PM) start = start.add(1, 'd')
if (prev && start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
let stop = parseStop(item, date)
if (stop.hour() > 11) PM = true
if (stop.hour() < 12 && PM) stop = stop.add(1, 'd')
if (prev && stop.isBefore(start)) {
stop = stop.add(1, 'd')
date = date.add(1, 'd')
}
programs.push({
title: item.b,
start: start.toString(),
stop: stop.toString()
start,
stop
})
})
@ -37,22 +39,24 @@ module.exports = {
}
function parseStart(item, date) {
const time = `${date.format('MM/DD/YYYY')} ${item.c}`
const time = `${date.format('YYYY-MM-DD')} ${item.c}`
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Istanbul')
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Europe/Istanbul')
}
function parseStop(item, date) {
const time = `${date.format('MM/DD/YYYY')} ${item.d}`
const time = `${date.format('YYYY-MM-DD')} ${item.d}`
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Istanbul')
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Europe/Istanbul')
}
function parseItems(content, channel) {
const parsed = JSON.parse(content)
const channels = parsed.k
if (!channels) return []
const data = channels.find(c => c.x == channel.site_id)
let parsed
try {
parsed = JSON.parse(content)
} catch (e) {}
if (!parsed || !parsed.k) return []
const data = parsed.k.find(c => c.x == channel.site_id)
return data ? data.p : []
}

View file

@ -1,4 +1,4 @@
// npx epg-grabber --config=sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js --channels=sites/turksatkablo.com.tr/turksatkablo.com.tr_tr.channels.xml --days=2 --output=.gh-pages/guides/tr/turksatkablo.com.tr.epg.xml
// npx epg-grabber --config=sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js --channels=sites/turksatkablo.com.tr/turksatkablo.com.tr_tr.channels.xml --output=.gh-pages/guides/tr/turksatkablo.com.tr.epg.xml --days=2
const { parser, url } = require('./turksatkablo.com.tr.config.js')
const dayjs = require('dayjs')
@ -17,15 +17,35 @@ it('can generate valid url', () => {
})
it('can parse response', () => {
const result = parser({ date, channel, content })
expect(result[0]).toMatchObject({
start: 'Sun, 24 Oct 2021 22:15:00 GMT',
stop: 'Mon, 25 Oct 2021 00:00:00 GMT',
const result = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-10-24T22:15:00.000Z',
stop: '2021-10-25T00:00:00.000Z',
title: 'Ölüm Ormanı'
})
expect(result[2]).toMatchObject({
start: 'Mon, 25 Oct 2021 20:45:00 GMT',
stop: 'Tue, 26 Oct 2021 00:45:00 GMT',
},
{
start: '2021-10-25T12:00:00.000Z',
stop: '2021-10-25T14:00:00.000Z',
title: 'Kızım'
},
{
start: '2021-10-25T20:45:00.000Z',
stop: '2021-10-26T00:45:00.000Z',
title: 'Kaçakçı'
})
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: `<!DOCTYPE html><html><head></head><body></body></html>`
})
expect(result).toMatchObject([])
})