mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10:07 -04:00
Merge pull request #411 from iptv-org/update-directv.com
Update directv.com
This commit is contained in:
commit
afc2d7b767
3 changed files with 83 additions and 21 deletions
2
sites/directv.com/.gitignore
vendored
2
sites/directv.com/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
channels.json
|
|
||||||
*.crawler.js
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
|
@ -13,26 +14,39 @@ module.exports = {
|
||||||
logo({ channel }) {
|
logo({ channel }) {
|
||||||
return channel.logo
|
return channel.logo
|
||||||
},
|
},
|
||||||
parser({ content }) {
|
async parser({ content }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
for (let item of items) {
|
||||||
if (item.programID === '-1') return
|
if (item.programID === '-1') continue
|
||||||
|
const detail = await loadProgramDetail(item.programID)
|
||||||
const start = parseStart(item)
|
const start = parseStart(item)
|
||||||
const stop = start.add(item.duration, 'm')
|
const stop = start.add(item.duration, 'm')
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
description: item.description,
|
description: parseDescription(detail),
|
||||||
category: item.subcategoryList,
|
category: item.subcategoryList,
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDescription(detail) {
|
||||||
|
return detail ? detail.description : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadProgramDetail(programID) {
|
||||||
|
return axios
|
||||||
|
.get(`https://www.directv.com/json/program/flip/${programID}`)
|
||||||
|
.then(r => r.data)
|
||||||
|
.then(d => d.programDetail)
|
||||||
|
.catch(console.err)
|
||||||
|
}
|
||||||
|
|
||||||
function parseStart(item) {
|
function parseStart(item) {
|
||||||
return dayjs.utc(item.airTime)
|
return dayjs.utc(item.airTime)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// npx epg-grabber --config=sites/directv.com/directv.com.config.js --channels=sites/directv.com/directv.com_us.channels.xml --days=1 --output=.gh-pages/guides/us/directv.com.epg.xml
|
// npx epg-grabber --config=sites/directv.com/directv.com.config.js --channels=sites/directv.com/directv.com_us.channels.xml --output=guide.xml --days=2
|
||||||
|
|
||||||
const { parser, url, logo } = require('./directv.com.config.js')
|
const { parser, url, logo } = require('./directv.com.config.js')
|
||||||
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
|
jest.mock('axios')
|
||||||
|
|
||||||
const date = dayjs.utc('2021-10-24', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2021-10-24', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '15',
|
site_id: '15',
|
||||||
|
@ -27,24 +30,71 @@ it('can get logo url', () => {
|
||||||
expect(result).toBe('https://www.directv.com/images/logos/channels/dark/large/875.png')
|
expect(result).toBe('https://www.directv.com/images/logos/channels/dark/large/875.png')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', done => {
|
||||||
const result = parser({ date, channel, content })
|
axios.get.mockImplementation(url => {
|
||||||
expect(result).toMatchObject([
|
if (url === 'https://www.directv.com/json/program/flip/EP039886740003') {
|
||||||
{
|
return Promise.resolve({
|
||||||
start: dayjs.utc('Sat, 30 Oct 2021 00:00:00 GMT'),
|
data: JSON.parse(
|
||||||
stop: dayjs.utc('Sat, 30 Oct 2021 01:00:00 GMT'),
|
`{"programDetail":{"title":"Home Sweet Home","episodeTitle":"Art Is My God","mainCategory":"TV","rating":"PG","runLength":"1 hr","runLengthOriginal":60,"tomatoScore":0,"tomatoImg":"","audienceScore":0,"popcornImg":"","price":0,"formats":["1080p"],"starRating":"","starRatingNum":0,"episodeNumber":3,"episodeSeason":1,"originalAirDate":"2021-10-29","airDate":"Friday, October 29th","progType":"Series","ltd":"","isInPlaylist":false,"historical":false,"detailsLinkUrl":"/tv/Home-Sweet-Home-bUdDOWFNWkFKQWlGby9GckxSaXJvUT09/Art-Is-My-God-QVZSbmFsVUNvK0pLL3JRTjl0OFNYUT09","seriesLinkUrl":"/tv/Home-Sweet-Home-bUdDOWFNWkFKQWlGby9GckxSaXJvUT09","description":"The Baltzers, a surfing Mormon family, and the Silversteins, an artistic Black and Latino family with Jewish heritage, discover that the struggle of living outside their comfort zones sparks rewarding moments.","primaryImageUrl":"/db_photos/default/TV/tv.jpg","isLiveStreaming":false,"tmsProgramID":"EP039886740003","firstRun":false,"seriesID":20584969},"reporting":{"flip":{"success":false,"reportingData":"reporting for app/shared/nodules/json/flip/flip not implemented yet"}},"messagekeys":null,"contingencies":[]}`
|
||||||
title: 'Home Sweet Home',
|
)
|
||||||
category: ['Series', 'Reality'],
|
})
|
||||||
description: null
|
} else {
|
||||||
|
return Promise.resolve({ data: '' })
|
||||||
}
|
}
|
||||||
])
|
})
|
||||||
|
|
||||||
|
parser({ date, channel, content })
|
||||||
|
.then(result => {
|
||||||
|
result = result.map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toMatchObject([
|
||||||
|
{
|
||||||
|
start: '2021-10-30T00:00:00.000Z',
|
||||||
|
stop: '2021-10-30T01:00:00.000Z',
|
||||||
|
title: 'Home Sweet Home',
|
||||||
|
description:
|
||||||
|
'The Baltzers, a surfing Mormon family, and the Silversteins, an artistic Black and Latino family with Jewish heritage, discover that the struggle of living outside their comfort zones sparks rewarding moments.',
|
||||||
|
category: ['Series', 'Reality']
|
||||||
|
}
|
||||||
|
])
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
.catch(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle missing details', done => {
|
||||||
const result = parser({
|
axios.get.mockImplementation(url => {
|
||||||
|
if (url === 'https://www.directv.com/json/program/flip/EP039886740003') {
|
||||||
|
return Promise.resolve({ data: '' })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
parser({ date, channel, content })
|
||||||
|
.then(result => {
|
||||||
|
expect(result).toMatchObject([
|
||||||
|
{
|
||||||
|
title: 'Home Sweet Home',
|
||||||
|
description: null
|
||||||
|
}
|
||||||
|
])
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
.catch(done)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', done => {
|
||||||
|
parser({
|
||||||
date,
|
date,
|
||||||
channel,
|
channel,
|
||||||
content: `{"errors":[{"text":"Service failure: see errors or BulkOperationErrors for details","field":"","reason":"INTERNAL_SERVER_ERROR"}],"statusCode":500,"apiResponse":{"messages":"NOTE: see res.contingencies for size-filtered message values"},"reporting":{"channelschedules":{"success":false,"reportingData":"reporting for app/json/channelschedules/channelschedules not implemented yet"}},"messagekeys":null,"contingencies":[{"key":"ent_ep_guide_backend_unavailable_error_message","value":"<!-- message: key=ent_ep_guide_backend_unavailable_error_message, deviceType=web -->Due to technical issues the guide is currently unavailable, please check back to soon.","level":"ERROR"}]}`
|
content: `{"errors":[{"text":"Service failure: see errors or BulkOperationErrors for details","field":"","reason":"INTERNAL_SERVER_ERROR"}],"statusCode":500,"apiResponse":{"messages":"NOTE: see res.contingencies for size-filtered message values"},"reporting":{"channelschedules":{"success":false,"reportingData":"reporting for app/json/channelschedules/channelschedules not implemented yet"}},"messagekeys":null,"contingencies":[{"key":"ent_ep_guide_backend_unavailable_error_message","value":"<!-- message: key=ent_ep_guide_backend_unavailable_error_message, deviceType=web -->Due to technical issues the guide is currently unavailable, please check back to soon.","level":"ERROR"}]}`
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
.then(result => {
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
.catch(done)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue