mirror of
https://github.com/iptv-org/epg
synced 2026-05-05 08:56:59 -04:00
Update sky.com guide.
Test: ```sh npm test -- /sky.com > test > run-script-os /sky.com > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand /sky.com PASS sites/sky.com/sky.com.test.js √ can generate valid url (3 ms) √ can parse response (11 ms) √ can handle empty guide Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 3.533 s, estimated 4 s Ran all test suites matching /\\sky.com/i. ``` Grab: ```sh npm run grab -- --site=sky.com > grab > npx tsx scripts/commands/epg/grab.ts --site=sky.com starting... config: output: guide.xml maxConnections: 1 gzip: false site: sky.com loading channels... found 558 channel(s) run #1: [1/1116] sky.com (en) - 1009 - Dec 14, 2024 (35 programs) [2/1116] sky.com (en) - 1009 - Dec 15, 2024 (34 programs) ... [1115/1116] sky.com (en) - SkySportsNews.uk - Dec 15, 2024 (26 programs) [1116/1116] sky.com (en) - TLCHD.uk - Dec 14, 2024 (30 programs) saving to "guide.xml"... done in 00h 04m 32s ``` Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -1,58 +1,141 @@
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const debug = require('debug')('site:sky.com')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
const nworker = 10
|
||||
|
||||
module.exports = {
|
||||
site: 'sky.com',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
return `https://epgservices.sky.com/5.2.2/api/2.0/channel/json/${
|
||||
url({ date, channel }) {
|
||||
return `https://awk.epgsky.com/hawk/linear/schedule/${
|
||||
date.format('YYYYMMDD')
|
||||
}/${
|
||||
channel.site_id
|
||||
}/${date.unix()}/86400/4`
|
||||
}`
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
parser({ content, channel }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, channel)
|
||||
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.t,
|
||||
description: item.d,
|
||||
start: dayjs.unix(item.s),
|
||||
stop: dayjs.unix(item.s + item.m[1]),
|
||||
image: item.img ? `http://epgstatic.sky.com/epgdata/1.0/paimage/46/1/${item.img}` : null
|
||||
})
|
||||
})
|
||||
if (content) {
|
||||
const items = JSON.parse(content) || null
|
||||
if (Array.isArray(items.schedule)) {
|
||||
items.schedule
|
||||
.filter(schedule => schedule.sid === channel.site_id)
|
||||
.forEach(schedule => {
|
||||
if (Array.isArray(schedule.events)) {
|
||||
schedule.events
|
||||
.forEach(event => {
|
||||
const start = dayjs.utc(event.st * 1000)
|
||||
const stop = start.add(event.d, 's')
|
||||
programs.push({
|
||||
title: event.t,
|
||||
description: event.sy,
|
||||
season: event.seasonnumber,
|
||||
episode: event.episodenumber,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
const data = await axios
|
||||
.get(`https://www.sky.com/tv-guide/`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let channels = []
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
let initialData = $('#initialData').text()
|
||||
initialData = JSON.parse(decodeURIComponent(initialData))
|
||||
|
||||
initialData.state.epgData.channelsForRegion.forEach(item => {
|
||||
channels.push({
|
||||
lang: 'en',
|
||||
site_id: item.sid,
|
||||
name: item.t
|
||||
})
|
||||
const channels = {}
|
||||
const queues = [{ t: 'r', u: 'https://www.sky.com/tv-guide' }]
|
||||
await doFetch(queues, (queue, res) => {
|
||||
// process regions
|
||||
if (queue.t === 'r') {
|
||||
const $ = cheerio.load(res)
|
||||
const initialData = JSON.parse(decodeURIComponent($('#initialData').text()))
|
||||
initialData.state.epgData.regions
|
||||
.forEach(region => {
|
||||
queues.push({ t: 'c', u: `https://awk.epgsky.com/hawk/linear/services/${region.bouquet}/${region.subBouquet}` })
|
||||
})
|
||||
}
|
||||
// process channels
|
||||
if (queue.t === 'c') {
|
||||
if (Array.isArray(res.services)) {
|
||||
for (const ch of res.services) {
|
||||
if (channels[ch.sid] === undefined) {
|
||||
channels[ch.sid] = {
|
||||
lang: 'en',
|
||||
site_id: ch.sid,
|
||||
name: ch.t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return channels
|
||||
return Object.values(channels)
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const data = JSON.parse(content)
|
||||
|
||||
return data && data.listings ? data.listings[channel.site_id] : []
|
||||
async function doFetch(queues, cb) {
|
||||
const axios = require('axios')
|
||||
let n = Math.min(nworker, queues.length)
|
||||
const workers = []
|
||||
const adjustWorker = () => {
|
||||
if (queues.length > workers.length && workers.length < nworker) {
|
||||
let nw = Math.min(nworker, queues.length)
|
||||
if (n < nw) {
|
||||
n = nw
|
||||
createWorker()
|
||||
}
|
||||
}
|
||||
}
|
||||
const createWorker = () => {
|
||||
while (workers.length < n) {
|
||||
startWorker()
|
||||
}
|
||||
}
|
||||
const startWorker = () => {
|
||||
const worker = () => {
|
||||
if (queues.length) {
|
||||
const queue = queues.shift()
|
||||
const done = (res, headers) => {
|
||||
if (res) {
|
||||
cb(queue, res, headers)
|
||||
adjustWorker()
|
||||
}
|
||||
worker()
|
||||
}
|
||||
const url = typeof queue === 'string' ? queue : queue.u
|
||||
const params = typeof queue === 'object' && queue.params ? queue.params : {}
|
||||
const method = typeof queue === 'object' && queue.m ? queue.m : 'get'
|
||||
if (typeof debug === 'function') {
|
||||
debug(`fetch %s with %s`, url, JSON.stringify(params))
|
||||
}
|
||||
axios[method](url, params)
|
||||
.then(response => {
|
||||
done(response.data, response.headers)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(`Unable to fetch ${url}: ${err.message}!`)
|
||||
done()
|
||||
})
|
||||
} else {
|
||||
workers.splice(workers.indexOf(worker), 1)
|
||||
}
|
||||
}
|
||||
workers.push(worker)
|
||||
worker()
|
||||
}
|
||||
createWorker()
|
||||
await new Promise(resolve => {
|
||||
const interval = setInterval(() => {
|
||||
if (workers.length === 0) {
|
||||
clearInterval(interval)
|
||||
resolve()
|
||||
}
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user