mirror of
https://github.com/iptv-org/epg
synced 2026-05-05 17:07:03 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,115 +1,115 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'startimestv.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
return `https://www.startimestv.com/channeldetail/${channel.site_id}/${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}.html`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
season: parseSeason($item),
|
||||
episode: parseEpisode($item),
|
||||
description: parseDescription($item),
|
||||
start: parseStart($item, date),
|
||||
stop: parseStop($item, date)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ country }) {
|
||||
const area = {
|
||||
ke: 6,
|
||||
ng: 2,
|
||||
tz: 3,
|
||||
ug: 4,
|
||||
rw: 5,
|
||||
gh: 32,
|
||||
mw: 14,
|
||||
ci: 22,
|
||||
gn: 12,
|
||||
bi: 9,
|
||||
cg: 16,
|
||||
cd: 11,
|
||||
mg: 13,
|
||||
mz: 15,
|
||||
cm: 20,
|
||||
ga: 19
|
||||
}
|
||||
const data = await axios
|
||||
.get('https://www.startimestv.com/tv_guide.html', {
|
||||
headers: {
|
||||
Cookie: `default_areaID=${area[country]}`
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
const script = $('body > script:nth-child(10)').html()
|
||||
let [, json] = script.match(/var obj = eval\( '(.*)' \);/) || [null, null]
|
||||
json = json.replace(/\\'/g, '')
|
||||
const items = JSON.parse(json)
|
||||
|
||||
return items.map(i => ({
|
||||
name: i.name,
|
||||
site_id: i.id
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.in > .t').text()
|
||||
const [, HH, mm] = time.match(/^(\d{2}):(\d{2})/) || [null, null, null]
|
||||
|
||||
return HH && mm ? dayjs.utc(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm') : null
|
||||
}
|
||||
|
||||
function parseStop($item, date) {
|
||||
const time = $item('.in > .t').text()
|
||||
const [, HH, mm] = time.match(/(\d{2}):(\d{2})$/) || [null, null, null]
|
||||
|
||||
return HH && mm ? dayjs.utc(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm') : null
|
||||
}
|
||||
|
||||
function parseSeason($item) {
|
||||
const title = parseTitle($item)
|
||||
const [, season] = title.match(/ S(\d+)/) || [null, null]
|
||||
|
||||
return season ? parseInt(season) : null
|
||||
}
|
||||
|
||||
function parseEpisode($item) {
|
||||
const title = parseTitle($item)
|
||||
const [, episode] = title.match(/ E(\d+)/) || [null, null]
|
||||
|
||||
return episode ? parseInt(episode) : null
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.in > h3').text()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.in > p').text()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('div.tv_gui > div.list > div > div').toArray()
|
||||
}
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'startimestv.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
return `https://www.startimestv.com/channeldetail/${channel.site_id}/${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}.html`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
season: parseSeason($item),
|
||||
episode: parseEpisode($item),
|
||||
description: parseDescription($item),
|
||||
start: parseStart($item, date),
|
||||
stop: parseStop($item, date)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ country }) {
|
||||
const area = {
|
||||
ke: 6,
|
||||
ng: 2,
|
||||
tz: 3,
|
||||
ug: 4,
|
||||
rw: 5,
|
||||
gh: 32,
|
||||
mw: 14,
|
||||
ci: 22,
|
||||
gn: 12,
|
||||
bi: 9,
|
||||
cg: 16,
|
||||
cd: 11,
|
||||
mg: 13,
|
||||
mz: 15,
|
||||
cm: 20,
|
||||
ga: 19
|
||||
}
|
||||
const data = await axios
|
||||
.get('https://www.startimestv.com/tv_guide.html', {
|
||||
headers: {
|
||||
Cookie: `default_areaID=${area[country]}`
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
const script = $('body > script:nth-child(10)').html()
|
||||
let [, json] = script.match(/var obj = eval\( '(.*)' \);/) || [null, null]
|
||||
json = json.replace(/\\'/g, '')
|
||||
const items = JSON.parse(json)
|
||||
|
||||
return items.map(i => ({
|
||||
name: i.name,
|
||||
site_id: i.id
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.in > .t').text()
|
||||
const [, HH, mm] = time.match(/^(\d{2}):(\d{2})/) || [null, null, null]
|
||||
|
||||
return HH && mm ? dayjs.utc(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm') : null
|
||||
}
|
||||
|
||||
function parseStop($item, date) {
|
||||
const time = $item('.in > .t').text()
|
||||
const [, HH, mm] = time.match(/(\d{2}):(\d{2})$/) || [null, null, null]
|
||||
|
||||
return HH && mm ? dayjs.utc(`${date.format('YYYY-MM-DD')} ${HH}:${mm}`, 'YYYY-MM-DD HH:mm') : null
|
||||
}
|
||||
|
||||
function parseSeason($item) {
|
||||
const title = parseTitle($item)
|
||||
const [, season] = title.match(/ S(\d+)/) || [null, null]
|
||||
|
||||
return season ? parseInt(season) : null
|
||||
}
|
||||
|
||||
function parseEpisode($item) {
|
||||
const title = parseTitle($item)
|
||||
const [, episode] = title.match(/ E(\d+)/) || [null, null]
|
||||
|
||||
return episode ? parseInt(episode) : null
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.in > h3').text()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.in > p').text()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('div.tv_gui > div.list > div > div').toArray()
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
// npm run channels:parse -- --config=./sites/startimestv.com/startimestv.com.config.js --output=./sites/startimestv.com/startimestv.com.channels.xml --set=country:ke
|
||||
// npm run grab -- --site=startimestv.com
|
||||
|
||||
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('2022-04-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/2022-04-10.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content =
|
||||
'<!DOCTYPE html><html> <body> <div id="body" class="page"> <div class="block"> <div class="channel"> <div class="content"> <div class="tv_gui"> <div class="list"> <div class="inner wap-list"> <div class="box" style="width:157.6px"> <div class="in"> <h3>Guddan S2 E77</h3> <div class="t">00:00-01:00</div><p>Vickrant is overjoyed to see Akshat in pain and not knowing what to do.</p></div><div class="mask"> <h4>00:00-01:00 Guddan S2 E77</h4> <p>Vickrant is overjoyed to see Akshat in pain and not knowing what to do.</p></div></div></div></div></div></div></div></div></div></body></html>'
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2022-04-10T00:00:00.000Z',
|
||||
stop: '2022-04-10T01:00:00.000Z',
|
||||
title: 'Guddan S2 E77',
|
||||
season: 2,
|
||||
episode: 77,
|
||||
description: 'Vickrant is overjoyed to see Akshat in pain and not knowing what to do.'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
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([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/startimestv.com/startimestv.com.config.js --output=./sites/startimestv.com/startimestv.com.channels.xml --set=country:ke
|
||||
// npm run grab -- --site=startimestv.com
|
||||
|
||||
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('2022-04-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/2022-04-10.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content =
|
||||
'<!DOCTYPE html><html> <body> <div id="body" class="page"> <div class="block"> <div class="channel"> <div class="content"> <div class="tv_gui"> <div class="list"> <div class="inner wap-list"> <div class="box" style="width:157.6px"> <div class="in"> <h3>Guddan S2 E77</h3> <div class="t">00:00-01:00</div><p>Vickrant is overjoyed to see Akshat in pain and not knowing what to do.</p></div><div class="mask"> <h4>00:00-01:00 Guddan S2 E77</h4> <p>Vickrant is overjoyed to see Akshat in pain and not knowing what to do.</p></div></div></div></div></div></div></div></div></div></body></html>'
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2022-04-10T00:00:00.000Z',
|
||||
stop: '2022-04-10T01:00:00.000Z',
|
||||
title: 'Guddan S2 E77',
|
||||
season: 2,
|
||||
episode: 77,
|
||||
description: 'Vickrant is overjoyed to see Akshat in pain and not knowing what to do.'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
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