fixed all tests + directv entirely fixed

This commit is contained in:
theofficialomega
2026-04-06 23:20:33 +02:00
parent b7af7cbd7e
commit 0b3591bcaa
11 changed files with 3833 additions and 3686 deletions

1387
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -94,7 +94,7 @@
"globals": "^17.4.0",
"husky": "^9.1.7",
"iconv-lite": "^0.7.2",
"inquirer": "^13.3.2",
"inquirer": "^13.4.0",
"jest": "^30.3.0",
"jest-offline": "^1.0.1",
"langs": "^2.0.0",

View File

@@ -32,7 +32,6 @@ let channelsFromXML = new Collection<Channel>()
main(filepath)
nodeCleanup(() => {
save(filepath, channelsFromXML)
if (process.platform === 'win32') process.kill(0)
})
export default async function main(filepath: string) {

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +1,8 @@
{
"errors": [
"schedules": [
{
"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"
"channelId": "5070bc2e-dd69-4dee-98b4-a4c5e3b1fd7b",
"contents": []
}
]
}

View File

@@ -1,47 +0,0 @@
{
"programDetail": {
"title": "Men in Black II",
"episodeTitle": "",
"releaseYear": "2002",
"mainCategory": "Movies",
"rating": "TV14",
"runLength": "1 hr 28 min",
"runLengthOriginal": 88,
"tomatoScore": 39,
"tomatoImg": "rotten",
"audienceScore": 45,
"popcornImg": "popKnockedOver",
"price": 3.99,
"formats": [
"1080p",
"SD",
"4K",
"HD"
],
"starRating": "**+",
"starRatingNum": 25,
"episodeNumber": 0,
"episodeSeason": 0,
"originalAirDate": "",
"airDate": null,
"progType": "Feature Film",
"ltd": "",
"isInPlaylist": false,
"historical": false,
"detailsLinkUrl": "/movies/Men-in-Black-II-c0Frek5HeE1EaytueTN6VHJRZW9QQT09",
"description": "Kay (Tommy Lee Jones) and Jay (Will Smith) reunite to provide our best line of defense against a seductress who levels the toughest challenge yet to the MIBs mission statement: protecting the earth from the scum of the universe. While investigating a routine crime, Jay uncovers a plot masterminded by Serleena (Boyle), a Kylothian monster who disguises herself as a lingerie model. When Serleena takes the MIB building hostage, there is only one person Jay can turn to -- his former MIB partner.",
"primaryImageUrl": "/db_photos/movies/AllPhotosAPGI/29160/29160_aa.jpg",
"isLiveStreaming": false,
"tmsProgramID": "MV001173520000",
"firstRun": false,
"seriesID": 0
},
"reporting": {
"flip": {
"success": false,
"reportingData": "reporting for app/shared/nodules/json/flip/flip not implemented yet"
}
},
"messagekeys": null,
"contingencies": []
}

View File

@@ -1,45 +0,0 @@
{
"programDetail": {
"title": "South Park",
"episodeTitle": "Goth Kids 3: Dawn of the Posers",
"mainCategory": "TV",
"rating": "TVMA",
"runLength": " 23 min",
"runLengthOriginal": 23,
"tomatoScore": 0,
"tomatoImg": "",
"audienceScore": 0,
"popcornImg": "",
"price": 2.99,
"formats": [
"1080p",
"SD"
],
"starRating": "",
"starRatingNum": 0,
"episodeNumber": 4,
"episodeSeason": 17,
"originalAirDate": "2013-10-23",
"airDate": "Wednesday, October 23rd",
"progType": "Series",
"ltd": "",
"isInPlaylist": false,
"historical": false,
"detailsLinkUrl": "/tv/South-Park-bldqUThGNWdxd289/Goth-Kids-3-Dawn-of-the-Posers-dXRwMUpueHkzeHVxdEtvZnF3bUxqUT09",
"seriesLinkUrl": "/tv/South-Park-bldqUThGNWdxd289",
"description": "The goth kids are sent to a camp for troubled children.",
"primaryImageUrl": "/db_photos/showcards/v5/AllPhotos/184338/p184338_b_v5_aa.jpg",
"isLiveStreaming": false,
"tmsProgramID": "EP002298270445",
"firstRun": false,
"seriesID": 184338
},
"reporting": {
"flip": {
"success": false,
"reportingData": "reporting for app/shared/nodules/json/flip/flip not implemented yet"
}
},
"messagekeys": null,
"contingencies": []
}

View File

@@ -5,55 +5,80 @@ const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
let token = null
async function getToken() {
if (token) return token
token = await fetchToken()
return token
}
async function fetchToken() {
return axios
.post('https://api.cld.dtvce.com/authn-tokengo/v3/v2/tokens?client_id=DTVE_DFW_WEB_Chrome_G', { headers:
{ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36' }
if (token) return token
try {
token = await axios
.post('https://api.cld.dtvce.com/authn-tokengo/v3/v2/tokens?client_id=DTVE_DFW_WEB_Chrome_G', null, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36',
'cache-control': 'no-cache',
'origin': 'https://www.directv.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://www.directv.com/',
'sec-ch-ua': '"Chromium";v="146", "Not-A.Brand";v="24", "Brave";v="146"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'sec-gpc': '1'
}
})
.then(r => r.data)
.then(d => d.access_token)
.catch(console.err)
.then(r => r.data)
.then(d => d.access_token)
return token
} catch (error) {
console.error('Error fetching token (potential geo-block or API issue):', error)
return null
}
}
module.exports = {
site: 'directv.com',
days: 2,
request: async function() {
return {
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
},
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36',
Authorization: `Bearer ${token}`,
async headers() {
await fetchToken()
return {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36',
Authorization: `Bearer ${token}`,
'cache-control': 'no-cache',
'origin': 'https://www.directv.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://www.directv.com/',
'sec-ch-ua': '"Chromium";v="146", "Not-A.Brand";v="24", "Brave";v="146"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'sec-gpc': '1'
}
}
},
async url({ date, channel }) {
await getToken()
return `https://api.cld.dtvce.com/discovery/edge/schedule/v1/service/schedule?startTime=${date.format('YYYY-MM-DDT00:00:00')}&endTime=${date.add(24, 'hour').format('YYYY-MM-DDT00:00:00')}&channelIds=${channel.site_id}&include4K=false&is4Kcompatible=false&includeTVOD=true`
url({ date, channel }) {
return `https://api.cld.dtvce.com/discovery/edge/schedule/v1/service/schedule?startTime=${date.valueOf()}&endTime=${date.add(24, 'hour').valueOf()}&channelIds=${channel.site_id}&include4K=false&is4Kcompatible=false&includeTVOD=true`
},
async parser({ content, channel }) {
console.log(content)
const programs = []
const items = parseItems(content, channel)
for (let item of items) {
if (item.programID === '-1') continue
const start = parseStart(item)
const stop = start.add(item.duration, 'm')
const stop = parseStop(item)
programs.push({
title: item.title,
sub_title: item.episodeTitle,
description: parseDescription(item),
rating: parseRating(item),
date: parseYear(item),
category: item.subcategoryList,
date: parseFullReleaseDate(item) ?? parseYear(item),
category: parseCategory(item),
season: item.seasonNumber,
episode: item.episodeNumber,
image: parseImage(item),
@@ -72,7 +97,7 @@ module.exports = {
const html = await axios
.get('https://api.cld.dtvce.com/discovery/metadata/channel/v5/service/allchannels?sort=OrdCh%253DASC', {
headers: {
Authorization: `Bearer ${await getToken()}`,
Authorization: `Bearer ${await fetchToken()}`,
'Accept-Language': 'en-US,en;q=0.5',
Connection: 'keep-alive'
}
@@ -100,14 +125,21 @@ module.exports = {
function parseDescription(item) {
return item ? item.description : null
}
function parseCategory(item) {
return item && item.genres ? item.genres : null
}
// DirecTV are the only ones to put the episode/movie's full release date. Kudos to them.
function parseFullReleaseDate(item) {
return item ? item.originalAirDate : null
}
function parseYear(item) {
return item ? item.releaseYear : null
}
function parseRating(item) {
return item.rating
return item.parentalRating
? {
system: 'MPA',
value: item.rating
value: item.parentalRating
}
: null
}
@@ -116,7 +148,11 @@ function parseImage(item) {
}
function parseStart(item) {
return dayjs.utc(item.airTime)
return dayjs.utc(item.consumables?.[0]?.startTime)
}
function parseStop(item) {
return dayjs.utc(item.consumables?.[0]?.endTime)
}
function parseItems(content, channel) {

View File

@@ -10,36 +10,29 @@ dayjs.extend(utc)
jest.mock('axios')
const date = dayjs.utc('2023-01-15', 'YYYY-MM-DD').startOf('d')
// Mock token fetching
axios.post.mockImplementation((url) => {
if (url === 'https://api.cld.dtvce.com/authn-tokengo/v3/v2/tokens?client_id=DTVE_DFW_WEB_Chrome_G') {
return Promise.resolve({ data: '/S2dAVfUtUdnt6adfOBn+QrLZ2GymKSfxIGgfI/tRrOCf22bhs7aLmwmeKTUp0br3aHU2M/Rtv5Y43Kl9unTtNau8w48K3dNjVVH2gyrgvGvUxfVa8rXXuv9RBesXSric6ltlS4yDIjRtuOpmiU5Imt8O1zHWjA9K3/8M84oRQywb0HpE4tkTT3RBG5Cmz+wX5If6Hbb3ndFacEhUjpvCI0mAqPlI2r7x7/73quuoByp0+updUmyjWF+5SVkUBx5.ycdisTLMPpwxjYERYDmA7zm7Pq2ukk5KJk8duRW8lMg=' })
}
})
const date = dayjs.utc('2026-06-04', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '249#249',
site_id: '5070bc2e-dd69-4dee-98b4-a4c5e3b1fd7b',
xmltv_id: 'ComedyCentralEast.us'
}
it('can generate valid url', () => {
const result = url({ date, channel })
expect(result).toBe(
'https://www.directv.com/json/channelschedule?channels=249&startTime=2023-01-15T00:00:00Z&hours=24&chId=249'
`https://api.cld.dtvce.com/discovery/edge/schedule/v1/service/schedule?startTime=${date.valueOf()}&endTime=${date.add(24, 'hour').valueOf()}&channelIds=5070bc2e-dd69-4dee-98b4-a4c5e3b1fd7b&include4K=false&is4Kcompatible=false&includeTVOD=true`
)
})
it('can parse response', done => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
axios.get.mockImplementation(url => {
if (url === 'https://www.directv.com/json/program/flip/MV001173520000') {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program1.json')))
})
} else if (url === 'https://www.directv.com/json/program/flip/EP002298270445') {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program2.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
parser({ content, channel })
.then(result => {
result = result.map(p => {
@@ -48,38 +41,38 @@ it('can parse response', done => {
return p
})
expect(result).toMatchObject([
{
start: '2023-01-14T23:00:00.000Z',
stop: '2023-01-15T01:00:00.000Z',
title: 'Men in Black II',
description:
'Kay (Tommy Lee Jones) and Jay (Will Smith) reunite to provide our best line of defense against a seductress who levels the toughest challenge yet to the MIBs mission statement: protecting the earth from the scum of the universe. While investigating a routine crime, Jay uncovers a plot masterminded by Serleena (Boyle), a Kylothian monster who disguises herself as a lingerie model. When Serleena takes the MIB building hostage, there is only one person Jay can turn to -- his former MIB partner.',
date: '2002',
image: 'https://www.directv.com/db_photos/movies/AllPhotosAPGI/29160/29160_aa.jpg',
category: ['Comedy', 'Movies Anywhere', 'Action/Adventure', 'Science Fiction'],
expect(result).toHaveLength(47)
expect(result[0]).toMatchObject({
start: '2026-04-06T00:00:00.000Z',
stop: '2026-04-06T00:30:00.000Z',
title: 'Seinfeld',
sub_title: 'The Nap',
description: 'George finds the ideal napping spot at work; Jerry has his kitchen rebuilt; Elaine meets a new beau (Vince Grant).',
date: '1997-04-10',
season: 8,
episode: 18,
category: ['Sitcom'],
rating: {
system: 'MPA',
value: 'TVPG'
}
})
expect(result[46]).toMatchObject({
start: '2026-04-06T23:35:00.000Z',
stop: '2026-04-07T00:10:00.000Z',
title: 'The Office',
sub_title: 'The Convention',
description: 'Michael organizes a party in his hotel room when he, Dwight and Jan attend the Northeastern Mid-Market Office Supply Convention in Philadelphia.',
category: ['Comedy', 'Sitcom'],
season: 3,
episode: 2,
rating: {
system: 'MPA',
value: 'TV14'
}
},
{
start: '2023-01-15T06:00:00.000Z',
stop: '2023-01-15T06:30:00.000Z',
title: 'South Park',
sub_title: 'Goth Kids 3: Dawn of the Posers',
description: 'The goth kids are sent to a camp for troubled children.',
image:
'https://www.directv.com/db_photos/showcards/v5/AllPhotos/184338/p184338_b_v5_aa.jpg',
category: ['Series', 'Animation', 'Comedy'],
season: 17,
episode: 4,
rating: {
system: 'MPA',
value: 'TVMA'
}
}
])
})
done()
})
.catch(done)

View File

@@ -29,7 +29,7 @@ it('can parse response', () => {
start: '2023-06-23T07:14:32.000Z',
stop: '2023-06-23T09:09:36.000Z',
title: 'Killers Within',
date: '20180101',
date: '2018-01-01T00:00:00.000Z',
description:
'With her son being held captive by a criminal gang, police officer Amanda Doyle, together with her ex-husband and three unlikely allies, takes part in a desperate plot to hold a wealthy banker and his family to ransom. But this is no ordinary family.',
icon: 'https://provider-static.plex.tv/epg/images/thumbnails/darkmatter-tv-fallback.jpg',

View File

@@ -69,7 +69,7 @@ it('can parse response', () => {
description: 'Le journal de vivre ici.',
category: 'Info',
image:
'https://experience-cache.proximustv.be/posterserver/poster/EPG/w-166_h-110/250_250_4B990CC58066A7B2A660AFA0BDDE5C41.jpg'
'https://experience-cache.cdi.streaming.proximustv.be/posterserver/poster/EPG/250_250_4B990CC58066A7B2A660AFA0BDDE5C41.jpg'
})
})