mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 02:16:40 -05:00
Fixes linter errors
This commit is contained in:
@@ -1,134 +1,134 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = {
|
||||
site: 'foxtel.com.au',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.foxtel.com.au/tv-guide/channel/${channel.site_id}/${date.format(
|
||||
'YYYY/MM/DD'
|
||||
)}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
}
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
for (let item of items) {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item)
|
||||
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({
|
||||
title: parseTitle($item),
|
||||
sub_title: parseSubTitle($item),
|
||||
icon: parseIcon($item),
|
||||
rating: parseRating($item),
|
||||
season: parseSeason($item),
|
||||
episode: parseEpisode($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://www.foxtel.com.au/webepg/ws/foxtel/channels?regionId=8336', {
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.forEach(item => {
|
||||
let name = item.name.replace(/\+/g, '-').replace(/&/g, '')
|
||||
const slug = name.replace(/[^a-z0-9\s]/gi, '').replace(/[^a-z0-9]/i, '-')
|
||||
|
||||
return {
|
||||
name: item.name.replace(/&/g, '&'),
|
||||
site_id: `${slug}/${item.channelTag}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseSeason($item) {
|
||||
let seasonString = $item('.epg-event-description > div > abbr:nth-child(1)').attr('title')
|
||||
if (!seasonString) return null
|
||||
let [, season] = seasonString.match(/^Season: (\d+)/) || [null, null]
|
||||
|
||||
return season ? parseInt(season) : null
|
||||
}
|
||||
|
||||
function parseEpisode($item) {
|
||||
let episodeString = $item('.epg-event-description > div > abbr:nth-child(2)').attr('title')
|
||||
if (!episodeString) return null
|
||||
let [, episode] = episodeString.match(/^Episode: (\d+)/) || [null, null]
|
||||
|
||||
return episode ? parseInt(episode) : null
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.epg-event-thumbnail > img').attr('src')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.epg-event-description').clone().children().remove().end().text().trim()
|
||||
}
|
||||
|
||||
function parseSubTitle($item) {
|
||||
let subtitle = $item('.epg-event-description > div')
|
||||
.clone()
|
||||
.children()
|
||||
.remove()
|
||||
.end()
|
||||
.text()
|
||||
.trim()
|
||||
.split(',')
|
||||
|
||||
subtitle = subtitle.pop()
|
||||
const [, rating] = subtitle.match(/\(([^)]+)\)$/) || [null, null]
|
||||
|
||||
return subtitle.replace(`(${rating})`, '').trim()
|
||||
}
|
||||
|
||||
function parseRating($item) {
|
||||
const subtitle = $item('.epg-event-description > div').text().trim()
|
||||
const [, rating] = subtitle.match(/\(([^)]+)\)$/) || [null, null]
|
||||
|
||||
return rating
|
||||
? {
|
||||
system: 'ACB',
|
||||
value: rating
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const unix = $item('*').data('scheduled-date')
|
||||
|
||||
return dayjs(parseInt(unix))
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#epg-channel-events > a').toArray()
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = {
|
||||
site: 'foxtel.com.au',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.foxtel.com.au/tv-guide/channel/${channel.site_id}/${date.format(
|
||||
'YYYY/MM/DD'
|
||||
)}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
}
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
for (let item of items) {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item)
|
||||
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({
|
||||
title: parseTitle($item),
|
||||
sub_title: parseSubTitle($item),
|
||||
icon: parseIcon($item),
|
||||
rating: parseRating($item),
|
||||
season: parseSeason($item),
|
||||
episode: parseEpisode($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://www.foxtel.com.au/webepg/ws/foxtel/channels?regionId=8336', {
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.forEach(item => {
|
||||
let name = item.name.replace(/\+/g, '-').replace(/&/g, '')
|
||||
const slug = name.replace(/[^a-z0-9\s]/gi, '').replace(/[^a-z0-9]/i, '-')
|
||||
|
||||
return {
|
||||
name: item.name.replace(/&/g, '&'),
|
||||
site_id: `${slug}/${item.channelTag}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseSeason($item) {
|
||||
let seasonString = $item('.epg-event-description > div > abbr:nth-child(1)').attr('title')
|
||||
if (!seasonString) return null
|
||||
let [, season] = seasonString.match(/^Season: (\d+)/) || [null, null]
|
||||
|
||||
return season ? parseInt(season) : null
|
||||
}
|
||||
|
||||
function parseEpisode($item) {
|
||||
let episodeString = $item('.epg-event-description > div > abbr:nth-child(2)').attr('title')
|
||||
if (!episodeString) return null
|
||||
let [, episode] = episodeString.match(/^Episode: (\d+)/) || [null, null]
|
||||
|
||||
return episode ? parseInt(episode) : null
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.epg-event-thumbnail > img').attr('src')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.epg-event-description').clone().children().remove().end().text().trim()
|
||||
}
|
||||
|
||||
function parseSubTitle($item) {
|
||||
let subtitle = $item('.epg-event-description > div')
|
||||
.clone()
|
||||
.children()
|
||||
.remove()
|
||||
.end()
|
||||
.text()
|
||||
.trim()
|
||||
.split(',')
|
||||
|
||||
subtitle = subtitle.pop()
|
||||
const [, rating] = subtitle.match(/\(([^)]+)\)$/) || [null, null]
|
||||
|
||||
return subtitle.replace(`(${rating})`, '').trim()
|
||||
}
|
||||
|
||||
function parseRating($item) {
|
||||
const subtitle = $item('.epg-event-description > div').text().trim()
|
||||
const [, rating] = subtitle.match(/\(([^)]+)\)$/) || [null, null]
|
||||
|
||||
return rating
|
||||
? {
|
||||
system: 'ACB',
|
||||
value: rating
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const unix = $item('*').data('scheduled-date')
|
||||
|
||||
return dayjs(parseInt(unix))
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#epg-channel-events > a').toArray()
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
// npm run channels:parse -- --config=./sites/foxtel.com.au/foxtel.com.au.config.js --output=./sites/foxtel.com.au/foxtel.com.au.channels.xml
|
||||
// npm run grab -- --site=foxtel.com.au
|
||||
|
||||
const { parser, url, request } = require('./foxtel.com.au.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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-11-08', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'Channel-9-Sydney/NIN',
|
||||
xmltv_id: 'Channel9Sydney.au'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.foxtel.com.au/tv-guide/channel/Channel-9-Sydney/NIN/2022/11/08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-07T12:40:00.000Z',
|
||||
stop: '2022-11-07T13:30:00.000Z',
|
||||
title: 'The Equalizer',
|
||||
sub_title: 'Glory',
|
||||
icon: 'https://images1.resources.foxtel.com.au/store2/mount1/16/3/69e0v.jpg?maxheight=90&limit=91aa1c7a2c485aeeba0706941f79f111adb35830',
|
||||
rating: {
|
||||
system: 'ACB',
|
||||
value: 'M'
|
||||
},
|
||||
season: 1,
|
||||
episode: 2
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html'))
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/foxtel.com.au/foxtel.com.au.config.js --output=./sites/foxtel.com.au/foxtel.com.au.channels.xml
|
||||
// npm run grab -- --site=foxtel.com.au
|
||||
|
||||
const { parser, url, request } = require('./foxtel.com.au.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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-11-08', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'Channel-9-Sydney/NIN',
|
||||
xmltv_id: 'Channel9Sydney.au'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.foxtel.com.au/tv-guide/channel/Channel-9-Sydney/NIN/2022/11/08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|6'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-07T12:40:00.000Z',
|
||||
stop: '2022-11-07T13:30:00.000Z',
|
||||
title: 'The Equalizer',
|
||||
sub_title: 'Glory',
|
||||
icon: 'https://images1.resources.foxtel.com.au/store2/mount1/16/3/69e0v.jpg?maxheight=90&limit=91aa1c7a2c485aeeba0706941f79f111adb35830',
|
||||
rating: {
|
||||
system: 'ACB',
|
||||
value: 'M'
|
||||
},
|
||||
season: 1,
|
||||
episode: 2
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html'))
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user