mirror of
https://github.com/iptv-org/epg
synced 2026-04-29 14:06:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,69 +1,69 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'nowplayer.now.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
const diff = date.diff(dayjs.utc().startOf('d'), 'd') + 1
|
||||
|
||||
return `https://nowplayer.now.com/tvguide/epglist?channelIdList[]=${channel.site_id}&day=${diff}`
|
||||
},
|
||||
request: {
|
||||
headers({ channel }) {
|
||||
return {
|
||||
Cookie: `LANG=${channel.lang}; Expires=null; Path=/; Domain=nowplayer.now.com`
|
||||
}
|
||||
}
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const html = await axios
|
||||
.get('https://nowplayer.now.com/channels', { headers: { Accept: 'text/html' } })
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
const channels = $('body > div.container > .tv-guide-s-g > div > div').toArray()
|
||||
|
||||
return channels.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
return {
|
||||
lang,
|
||||
site_id: $item('.guide-g-play > p.channel').text().replace('CH', ''),
|
||||
name: $item('.thumbnail > a > span.image > p').text()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return dayjs(item.start)
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs(item.end)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data)) return []
|
||||
|
||||
return Array.isArray(data[0]) ? data[0] : []
|
||||
}
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'nowplayer.now.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
const diff = date.diff(dayjs.utc().startOf('d'), 'd') + 1
|
||||
|
||||
return `https://nowplayer.now.com/tvguide/epglist?channelIdList[]=${channel.site_id}&day=${diff}`
|
||||
},
|
||||
request: {
|
||||
headers({ channel }) {
|
||||
return {
|
||||
Cookie: `LANG=${channel.lang}; Expires=null; Path=/; Domain=nowplayer.now.com`
|
||||
}
|
||||
}
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const html = await axios
|
||||
.get('https://nowplayer.now.com/channels', { headers: { Accept: 'text/html' } })
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
const channels = $('body > div.container > .tv-guide-s-g > div > div').toArray()
|
||||
|
||||
return channels.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
return {
|
||||
lang,
|
||||
site_id: $item('.guide-g-play > p.channel').text().replace('CH', ''),
|
||||
name: $item('.thumbnail > a > span.image > p').text()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return dayjs(item.start)
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs(item.end)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data)) return []
|
||||
|
||||
return Array.isArray(data[0]) ? data[0] : []
|
||||
}
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
// npm run channels:parse -- --config=./sites/nowplayer.now.com/nowplayer.now.com.config.js --output=./sites/nowplayer.now.com/nowplayer.now.com.channels.xml --set=lang:zh
|
||||
// npm run grab -- --site=nowplayer.now.com
|
||||
|
||||
const { parser, url, request } = require('./nowplayer.now.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 channel = {
|
||||
lang: 'zh',
|
||||
site_id: '096',
|
||||
xmltv_id: 'ViuTVsix.hk'
|
||||
}
|
||||
|
||||
it('can generate valid url for today', () => {
|
||||
const date = dayjs.utc().startOf('d')
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=1'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
const date = dayjs.utc().startOf('d').add(1, 'd')
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=2'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers({ channel })).toMatchObject({
|
||||
Cookie: 'LANG=zh; Expires=null; Path=/; Domain=nowplayer.now.com'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content =
|
||||
'[[{"key":"key_202111174524739","vimProgramId":"202111174524739","name":"ViuTVsix Station Closing","start":1637690400000,"end":1637715600000,"date":"20211124","startTime":"02:00AM","endTime":"09:00AM","duration":420,"recordable":false,"restartTv":false,"npvrProg":false,"npvrStartTime":0,"npvrEndTime":0,"cid":"viutvsix station closing","cc":"","isInWatchlist":false}]]'
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-23T18:00:00.000Z',
|
||||
stop: '2021-11-24T01:00:00.000Z',
|
||||
title: 'ViuTVsix Station Closing'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: '[[]]'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/nowplayer.now.com/nowplayer.now.com.config.js --output=./sites/nowplayer.now.com/nowplayer.now.com.channels.xml --set=lang:zh
|
||||
// npm run grab -- --site=nowplayer.now.com
|
||||
|
||||
const { parser, url, request } = require('./nowplayer.now.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 channel = {
|
||||
lang: 'zh',
|
||||
site_id: '096',
|
||||
xmltv_id: 'ViuTVsix.hk'
|
||||
}
|
||||
|
||||
it('can generate valid url for today', () => {
|
||||
const date = dayjs.utc().startOf('d')
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=1'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
const date = dayjs.utc().startOf('d').add(1, 'd')
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=2'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers({ channel })).toMatchObject({
|
||||
Cookie: 'LANG=zh; Expires=null; Path=/; Domain=nowplayer.now.com'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content =
|
||||
'[[{"key":"key_202111174524739","vimProgramId":"202111174524739","name":"ViuTVsix Station Closing","start":1637690400000,"end":1637715600000,"date":"20211124","startTime":"02:00AM","endTime":"09:00AM","duration":420,"recordable":false,"restartTv":false,"npvrProg":false,"npvrStartTime":0,"npvrEndTime":0,"cid":"viutvsix station closing","cc":"","isInWatchlist":false}]]'
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-23T18:00:00.000Z',
|
||||
stop: '2021-11-24T01:00:00.000Z',
|
||||
title: 'ViuTVsix Station Closing'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: '[[]]'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user