mirror of
https://github.com/iptv-org/epg
synced 2026-05-09 19:07:03 -04:00
Merge pull request #3077 from iptv-org/update-foxtel.com.au
Update foxtel.com.au
This commit is contained in:
File diff suppressed because one or more lines are too long
1
sites/foxtel.com.au/__data__/program_1.json
Normal file
1
sites/foxtel.com.au/__data__/program_1.json
Normal file
File diff suppressed because one or more lines are too long
@@ -14,10 +14,11 @@ module.exports = {
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;',
|
||||
Cookie: 'AAMC_foxtel_0=REGION|7',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
}
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
async parser({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
for (let item of items) {
|
||||
@@ -32,9 +33,18 @@ module.exports = {
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
|
||||
const programId = parseProgramId($item)
|
||||
const details = await loadProgramDetails(programId)
|
||||
let description
|
||||
if (details) {
|
||||
description = parseDescription(details)
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
sub_title: parseSubTitle($item),
|
||||
description,
|
||||
image: parseImage($item),
|
||||
rating: parseRating($item),
|
||||
season: parseSeason($item),
|
||||
@@ -72,6 +82,34 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
function parseProgramId($item) {
|
||||
const href = $item('*').attr('href')
|
||||
|
||||
return href.split('/')[1]
|
||||
}
|
||||
|
||||
async function loadProgramDetails(programId) {
|
||||
if (!programId) return {}
|
||||
|
||||
return await axios
|
||||
.get(
|
||||
`https://www.foxtel.com.au/webepg/ws/foxtel/event/${programId}?movieHeight=213&tvShowHeight=213®ionId=8336`,
|
||||
{
|
||||
headers: {
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
'User-Agent': 'insomnia/2022.7.5'
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
}
|
||||
|
||||
function parseDescription(details) {
|
||||
return details?.event?.shortSynopsis
|
||||
}
|
||||
|
||||
function parseSeason($item) {
|
||||
let seasonString = $item('.epg-event-description > div > abbr:nth-child(1)').attr('title')
|
||||
if (!seasonString) return null
|
||||
@@ -118,9 +156,9 @@ function parseRating($item) {
|
||||
|
||||
return rating
|
||||
? {
|
||||
system: 'ACB',
|
||||
value: rating
|
||||
}
|
||||
system: 'ACB',
|
||||
value: rating
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const axios = require('axios')
|
||||
const { parser, url, request } = require('./foxtel.com.au.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
@@ -7,6 +8,23 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://www.foxtel.com.au/webepg/ws/foxtel/event/174868153?movieHeight=213&tvShowHeight=213®ionId=8336'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_1.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
data: '{}'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const date = dayjs.utc('2022-11-08', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'Channel-9-Sydney/NIN',
|
||||
@@ -26,10 +44,10 @@ it('can generate valid request headers', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
let results = parser({ content })
|
||||
let results = await parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
@@ -41,6 +59,8 @@ it('can parse response', () => {
|
||||
stop: '2022-11-07T13:30:00.000Z',
|
||||
title: 'The Equalizer',
|
||||
sub_title: 'Glory',
|
||||
description:
|
||||
"While Danny chaperones Grace's winter formal, terrorists seize the venue and hold everyone hostage in order to kidnap a diplomat's son.",
|
||||
image:
|
||||
'https://images1.resources.foxtel.com.au/store2/mount1/16/3/69e0v.jpg?maxheight=90&limit=91aa1c7a2c485aeeba0706941f79f111adb35830',
|
||||
rating: {
|
||||
@@ -52,8 +72,8 @@ it('can parse response', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
it('can handle empty guide', async () => {
|
||||
const result = await parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html'))
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
|
||||
Reference in New Issue
Block a user