mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,112 +1,112 @@
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const debug = require('debug')('site:startimestv.com')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
doFetch.setDebugger(debug).setMaxWorker(5)
|
||||
|
||||
module.exports = {
|
||||
site: 'startimestv.com',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.startimestv.com/channeldetail/${channel.site_id}/${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}.html`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
if (content) {
|
||||
const $ = cheerio.load(content)
|
||||
$('.box .mask')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
let title = parseText($(el).find('h4'))
|
||||
const [s, e] = title.substr(0, title.indexOf(' ')).split('-') || [null, null]
|
||||
const start = dayjs.utc(`${date.format('YYYY-MM-DD')} ${s}`, 'YYYY-MM-DD HH:nn')
|
||||
const stop = dayjs.utc(`${date.format('YYYY-MM-DD')} ${e}`, 'YYYY-MM-DD HH:nn')
|
||||
title = title.substr(title.indexOf(' ') + 1)
|
||||
const [, season, episode] = title.match(/ S(\d+) E(\d+)/) || [null, null, null]
|
||||
const description = parseText($(el).find('p'))
|
||||
programs.push({
|
||||
title,
|
||||
description: description !== 'NA' ? description : null,
|
||||
season: season ? parseInt(season) : season,
|
||||
episode: episode ? parseInt(episode) : episode,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const channels = {}
|
||||
const queues = [{ t: 'a', url: 'https://www.startimestv.com/tv_guide.html' }]
|
||||
await doFetch(queues, (queue, res) => {
|
||||
// process area-id
|
||||
if (queue.t === 'a') {
|
||||
const $ = cheerio.load(res)
|
||||
$('dd.update-areaID')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
const dd = $(el)
|
||||
const areaId = dd.attr('area-id')
|
||||
queues.push({
|
||||
t: 's',
|
||||
url: 'https://www.startimestv.com/tv_guide.html',
|
||||
params: {
|
||||
headers: {
|
||||
cookie: `default_areaID=${areaId}`
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// process channel
|
||||
if (queue.t === 's') {
|
||||
if (res) {
|
||||
const $ = cheerio.load(res)
|
||||
$('.channl .c')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
// only process channel with schedule only
|
||||
const clazz = $(el).attr('class')
|
||||
const [idx] = clazz.match(/\d+/) || [null]
|
||||
if (idx && $(`.item.item-${idx} .mask`).length) {
|
||||
const ch = $(el).find('.pic a[title]')
|
||||
const [site_id] = ch.attr('href').match(/\d+/) || [null]
|
||||
if (channels[site_id] === undefined) {
|
||||
channels[site_id] = {
|
||||
lang: 'en',
|
||||
name: ch.attr('title'),
|
||||
site_id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return Object.values(channels)
|
||||
}
|
||||
}
|
||||
|
||||
function parseText($item) {
|
||||
let text = $item.text().replace(/\t/g, '').replace(/\n/g, ' ').trim()
|
||||
while (true) {
|
||||
if (text.match(/\s\s/)) {
|
||||
text = text.replace(/\s\s/g, ' ')
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const debug = require('debug')('site:startimestv.com')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
doFetch.setDebugger(debug).setMaxWorker(5)
|
||||
|
||||
module.exports = {
|
||||
site: 'startimestv.com',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.startimestv.com/channeldetail/${channel.site_id}/${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}.html`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
if (content) {
|
||||
const $ = cheerio.load(content)
|
||||
$('.box .mask')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
let title = parseText($(el).find('h4'))
|
||||
const [s, e] = title.substr(0, title.indexOf(' ')).split('-') || [null, null]
|
||||
const start = dayjs.utc(`${date.format('YYYY-MM-DD')} ${s}`, 'YYYY-MM-DD HH:nn')
|
||||
const stop = dayjs.utc(`${date.format('YYYY-MM-DD')} ${e}`, 'YYYY-MM-DD HH:nn')
|
||||
title = title.substr(title.indexOf(' ') + 1)
|
||||
const [, season, episode] = title.match(/ S(\d+) E(\d+)/) || [null, null, null]
|
||||
const description = parseText($(el).find('p'))
|
||||
programs.push({
|
||||
title,
|
||||
description: description !== 'NA' ? description : null,
|
||||
season: season ? parseInt(season) : season,
|
||||
episode: episode ? parseInt(episode) : episode,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const channels = {}
|
||||
const queues = [{ t: 'a', url: 'https://www.startimestv.com/tv_guide.html' }]
|
||||
await doFetch(queues, (queue, res) => {
|
||||
// process area-id
|
||||
if (queue.t === 'a') {
|
||||
const $ = cheerio.load(res)
|
||||
$('dd.update-areaID')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
const dd = $(el)
|
||||
const areaId = dd.attr('area-id')
|
||||
queues.push({
|
||||
t: 's',
|
||||
url: 'https://www.startimestv.com/tv_guide.html',
|
||||
params: {
|
||||
headers: {
|
||||
cookie: `default_areaID=${areaId}`
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// process channel
|
||||
if (queue.t === 's') {
|
||||
if (res) {
|
||||
const $ = cheerio.load(res)
|
||||
$('.channl .c')
|
||||
.toArray()
|
||||
.forEach(el => {
|
||||
// only process channel with schedule only
|
||||
const clazz = $(el).attr('class')
|
||||
const [idx] = clazz.match(/\d+/) || [null]
|
||||
if (idx && $(`.item.item-${idx} .mask`).length) {
|
||||
const ch = $(el).find('.pic a[title]')
|
||||
const [site_id] = ch.attr('href').match(/\d+/) || [null]
|
||||
if (channels[site_id] === undefined) {
|
||||
channels[site_id] = {
|
||||
lang: 'en',
|
||||
name: ch.attr('title'),
|
||||
site_id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return Object.values(channels)
|
||||
}
|
||||
}
|
||||
|
||||
function parseText($item) {
|
||||
let text = $item.text().replace(/\t/g, '').replace(/\n/g, ' ').trim()
|
||||
while (true) {
|
||||
if (text.match(/\s\s/)) {
|
||||
text = text.replace(/\s\s/g, ' ')
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
const { parser, url } = require('./startimestv.com.config.js')
|
||||
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('2024-12-10', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1023102509',
|
||||
xmltv_id: 'ZeeOneAfrica.za'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.startimestv.com/channeldetail/1023102509/2024-12-10.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.html'))
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result.length).toBe(22)
|
||||
expect(result[0]).toMatchObject({
|
||||
start: '2024-12-10T00:00:00.000Z',
|
||||
stop: '2024-12-10T01:00:00.000Z',
|
||||
title: 'Deserted S1 E37',
|
||||
description:
|
||||
'Tora approaches Tubri for help, but she expresses her helplessness in seeking assistance from Arjun. Meanwhile, other family members are caught in the crossfire, trying to navigate their own positions within the household.',
|
||||
season: 1,
|
||||
episode: 37
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content:
|
||||
'<!DOCTYPE html><html> <body> <div id="body" class="page"> <div class="block"> <div class="channel"> <div class="title1"> <h3 style="text-transform:uppercase;"></h3> </div><div class="content"> <div class="des" style="background-color:#FFAB00"> <div class="sdw"></div><div class="inner clearfix"> <div class="pic"> <img src="" onerror="onerror=null;src=\'/Public/static/images/channellogo.png\'"> </div><div class="inf"> <h3 style="text-transform:uppercase;"></h3> <div class="num"> </div><div class="box"> <p class="rate" data="">Rate: <i></i><i></i><i></i><i></i><i></i></p><p>Category: </p><br/> </div></div><div class="txt"> <p></p></div></div></div></div></div></div></div></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./startimestv.com.config.js')
|
||||
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('2024-12-10', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1023102509',
|
||||
xmltv_id: 'ZeeOneAfrica.za'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.startimestv.com/channeldetail/1023102509/2024-12-10.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.html'))
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result.length).toBe(22)
|
||||
expect(result[0]).toMatchObject({
|
||||
start: '2024-12-10T00:00:00.000Z',
|
||||
stop: '2024-12-10T01:00:00.000Z',
|
||||
title: 'Deserted S1 E37',
|
||||
description:
|
||||
'Tora approaches Tubri for help, but she expresses her helplessness in seeking assistance from Arjun. Meanwhile, other family members are caught in the crossfire, trying to navigate their own positions within the household.',
|
||||
season: 1,
|
||||
episode: 37
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content:
|
||||
'<!DOCTYPE html><html> <body> <div id="body" class="page"> <div class="block"> <div class="channel"> <div class="title1"> <h3 style="text-transform:uppercase;"></h3> </div><div class="content"> <div class="des" style="background-color:#FFAB00"> <div class="sdw"></div><div class="inner clearfix"> <div class="pic"> <img src="" onerror="onerror=null;src=\'/Public/static/images/channellogo.png\'"> </div><div class="inf"> <h3 style="text-transform:uppercase;"></h3> <div class="num"> </div><div class="box"> <p class="rate" data="">Rate: <i></i><i></i><i></i><i></i><i></i></p><p>Category: </p><br/> </div></div><div class="txt"> <p></p></div></div></div></div></div></div></div></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user