mirror of
https://github.com/iptv-org/epg
synced 2026-09-07 04:20:08 -04:00
Merge pull request #3079 from iptv-org/be-deps
04/2026 Part 3 : additional changes
This commit is contained in:
+22
-38
@@ -1,57 +1,41 @@
|
||||
import typescriptEslint from '@typescript-eslint/eslint-plugin'
|
||||
import stylistic from '@stylistic/eslint-plugin'
|
||||
import globals from 'globals'
|
||||
import tsParser from '@typescript-eslint/parser'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import js from '@eslint/js'
|
||||
import { FlatCompat } from '@eslint/eslintrc'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
recommendedConfig: js.configs.recommended,
|
||||
allConfig: js.configs.all
|
||||
})
|
||||
import globals from 'globals'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import stylistic from '@stylistic/eslint-plugin'
|
||||
import prettier from 'eslint-config-prettier'
|
||||
|
||||
export default [
|
||||
...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/strict', 'plugin:@typescript-eslint/stylistic', 'prettier'),
|
||||
{
|
||||
plugins: {
|
||||
'@typescript-eslint': typescriptEslint,
|
||||
'@stylistic': stylistic
|
||||
},
|
||||
ignores: ['tests/__data__/']
|
||||
},
|
||||
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.strict,
|
||||
...tseslint.configs.stylistic,
|
||||
prettier,
|
||||
|
||||
{
|
||||
files: ['**/*.{js,mjs,cjs,ts}'],
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest
|
||||
},
|
||||
|
||||
parser: tsParser,
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module'
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
'@typescript-eslint': tseslint.plugin,
|
||||
'@stylistic': stylistic
|
||||
},
|
||||
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'no-case-declarations': 'off',
|
||||
'@stylistic/linebreak-style': ['error', 'windows'],
|
||||
|
||||
quotes: [
|
||||
'error',
|
||||
'single',
|
||||
{
|
||||
avoidEscape: true
|
||||
}
|
||||
],
|
||||
|
||||
quotes: ['error', 'single', { avoidEscape: true }],
|
||||
semi: ['error', 'never']
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: ['tests/__data__/']
|
||||
}
|
||||
]
|
||||
|
||||
Generated
+342
-317
File diff suppressed because it is too large
Load Diff
+9
-11
@@ -37,18 +37,18 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@eslint/eslintrc": "^3.3.5",
|
||||
"@eslint/js": "^9.39.4",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@freearhey/chronos": "^0.0.1",
|
||||
"@freearhey/core": "^0.15.2",
|
||||
"@freearhey/search-js": "^0.2.1",
|
||||
"@freearhey/storage-js": "^0.2.0",
|
||||
"@iptv-org/sdk": "^1.2.0",
|
||||
"@iptv-org/sdk": "^1.3.0",
|
||||
"@ntlab/sfetch": "^1.2.0",
|
||||
"@octokit/core": "^7.0.6",
|
||||
"@octokit/plugin-paginate-rest": "^14.0.0",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^17.0.0",
|
||||
"@stylistic/eslint-plugin": "^5.10.0",
|
||||
"@swc/core": "^1.15.24",
|
||||
"@swc/core": "^1.15.26",
|
||||
"@swc/jest": "^0.2.39",
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
@@ -60,10 +60,8 @@
|
||||
"@types/lodash.sortby": "^4.7.9",
|
||||
"@types/lodash.startcase": "^4.4.9",
|
||||
"@types/lodash.uniqby": "^4.7.9",
|
||||
"@types/node": "^25.5.2",
|
||||
"@types/node": "^25.6.0",
|
||||
"@types/pako": "^2.0.4",
|
||||
"@typescript-eslint/eslint-plugin": "^8.58.1",
|
||||
"@typescript-eslint/parser": "^8.58.1",
|
||||
"axios": "^1.15.0",
|
||||
"chalk": "^5.6.2",
|
||||
"cheerio": "^1.2.0",
|
||||
@@ -76,11 +74,11 @@
|
||||
"dayjs": "^1.11.20",
|
||||
"epg-grabber": "^0.46.1",
|
||||
"epg-parser": "^0.5.0",
|
||||
"eslint": "^10.2.0",
|
||||
"eslint": "^10.2.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"fs-extra": "^11.3.4",
|
||||
"glob": "^13.0.6",
|
||||
"globals": "^17.4.0",
|
||||
"globals": "^17.5.0",
|
||||
"husky": "^9.1.7",
|
||||
"iconv-lite": "^0.7.2",
|
||||
"inquirer": "^13.4.1",
|
||||
@@ -96,15 +94,15 @@
|
||||
"pako": "^2.1.0",
|
||||
"parse-duration": "^2.1.6",
|
||||
"pm2": "^6.0.14",
|
||||
"run-script-os": "^1.1.6",
|
||||
"serve": "^14.2.6",
|
||||
"socks-proxy-agent": "^10.0.0",
|
||||
"srcset": "^5.0.3",
|
||||
"table2array": "^0.0.2",
|
||||
"tabletojson": "^4.1.9",
|
||||
"tabletojson": "^4.1.10",
|
||||
"tough-cookie": "^6.0.1",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^6.0.2",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.58.2",
|
||||
"uuid": "^13.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ export async function loadIssues(props?: { labels: string[] | string }) {
|
||||
if (props && props.labels) {
|
||||
labels = Array.isArray(props.labels) ? props.labels.join(',') : props.labels
|
||||
}
|
||||
let issues: object[] = []
|
||||
let issues: object[]
|
||||
if (TESTING) {
|
||||
issues = (await import('../../tests/__data__/input/sites_update/issues.mjs')).default
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
parser({ content }) {
|
||||
let programs = []
|
||||
let programs
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(content)
|
||||
|
||||
+2948
-2885
File diff suppressed because it is too large
Load Diff
@@ -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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
+1156
-1043
File diff suppressed because it is too large
Load Diff
@@ -1,41 +1,84 @@
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
let token = null
|
||||
async function fetchToken() {
|
||||
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)
|
||||
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: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
},
|
||||
headers: {
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
Connection: 'keep-alive'
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
},
|
||||
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'
|
||||
}
|
||||
}
|
||||
},
|
||||
url({ date, channel }) {
|
||||
const [channelId, childId] = channel.site_id.split('#')
|
||||
return `https://www.directv.com/json/channelschedule?channels=${channelId}&startTime=${date.format()}&hours=24&chId=${childId}`
|
||||
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 }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, channel)
|
||||
for (let item of items) {
|
||||
if (item.programID === '-1') continue
|
||||
const detail = await loadProgramDetail(item.programID)
|
||||
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(detail),
|
||||
description: parseDescription(item),
|
||||
rating: parseRating(item),
|
||||
date: parseYear(detail),
|
||||
category: item.subcategoryList,
|
||||
date: parseFullReleaseDate(item) ?? parseYear(item),
|
||||
category: parseCategory(item),
|
||||
season: item.seasonNumber,
|
||||
episode: item.episodeNumber,
|
||||
image: parseImage(item),
|
||||
@@ -47,72 +90,81 @@ module.exports = {
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const codes = [10001]
|
||||
// alternate https://www.directv.com/dtvassets/dtv/dev/uf/CHLUP/chnlListingPageData.json
|
||||
// though i don't think you could fetch the schedule from the API with this
|
||||
|
||||
let channels = []
|
||||
for (let code of codes) {
|
||||
const html = await axios
|
||||
.get('https://www.directv.com/guide', {
|
||||
headers: {
|
||||
cookie: `dtve-prospect-zip=${code}`
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
const script = $('#dtvClientData').html()
|
||||
const [, json] = script.match(/var dtvClientData = (.*);/) || [null, null]
|
||||
const data = JSON.parse(json)
|
||||
|
||||
data.guideData.channels.forEach(item => {
|
||||
channels.push({
|
||||
lang: 'en',
|
||||
site_id: item.chNum,
|
||||
name: item.chName
|
||||
})
|
||||
const html = await axios
|
||||
.get('https://api.cld.dtvce.com/discovery/metadata/channel/v5/service/allchannels?sort=OrdCh%253DASC', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${await fetchToken()}`,
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
Connection: 'keep-alive'
|
||||
}
|
||||
})
|
||||
}
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const data = html?.channelInfoList
|
||||
|
||||
if (data && Array.isArray(data)) {
|
||||
data.forEach(item => {
|
||||
channels.push({
|
||||
lang: 'en',
|
||||
site_id: item.resourceId,
|
||||
name: item.channelName,
|
||||
icon: item.imageList && item.imageList.length > 0 ? item.imageList[0].imageUrl : null
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseDescription(detail) {
|
||||
return detail ? detail.description : null
|
||||
function parseDescription(item) {
|
||||
return item ? item.description : null
|
||||
}
|
||||
function parseYear(detail) {
|
||||
return detail ? detail.releaseYear : 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
|
||||
}
|
||||
function parseImage(item) {
|
||||
return item.primaryImageUrl ? `https://www.directv.com${item.primaryImageUrl}` : 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)
|
||||
return item.images?.length > 0 ? item.images[0].defaultImageUrl : null
|
||||
}
|
||||
|
||||
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) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data) return []
|
||||
if (!Array.isArray(data.schedule)) return []
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
if (!data) return []
|
||||
if (!Array.isArray(data.schedules)) return []
|
||||
|
||||
const [, childId] = channel.site_id.split('#')
|
||||
const channelData = data.schedule.find(i => i.chId == childId)
|
||||
return channelData.schedules && Array.isArray(channelData.schedules) ? channelData.schedules : []
|
||||
const channelData = data.schedules.find(i => i.channelId === channel.site_id)
|
||||
return channelData?.contents && Array.isArray(channelData.contents) ? channelData.contents : []
|
||||
} catch (error) {
|
||||
console.error('Error parsing content:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -44,7 +44,7 @@ module.exports = {
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const axios = require('axios')
|
||||
let data = ''
|
||||
let data
|
||||
try {
|
||||
const res = await axios.get(`https://elcinema.com/${lang}/tvguide/`, {
|
||||
headers: headers
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channels>
|
||||
<channel site="france.tv" site_id="arte" lang="fr" xmltv_id="Arte.de@France">Arté</channel>
|
||||
<channel site="france.tv" site_id="documentaire" lang="fr" xmltv_id="">France Télévisions Docs</channel>
|
||||
<channel site="france.tv" site_id="france-2" lang="fr" xmltv_id="France2.fr">France 2</channel>
|
||||
<channel site="france.tv" site_id="france-3" lang="fr" xmltv_id="France3.fr">France 3</channel>
|
||||
<channel site="france.tv" site_id="france-4" lang="fr" xmltv_id="France4.fr">France 4</channel>
|
||||
<channel site="france.tv" site_id="france-5" lang="fr" xmltv_id="France5.fr">France 5</channel>
|
||||
<channel site="france.tv" site_id="france-24" lang="fr" xmltv_id="France24.fr">France 24</channel>
|
||||
<channel site="france.tv" site_id="franceinfo" lang="fr" xmltv_id="FranceInfo.fr">Franceinfo</channel>
|
||||
<channel site="france.tv" site_id="francetv" lang="fr" xmltv_id="">France TV</channel>
|
||||
<channel site="france.tv" site_id="ina" lang="fr" xmltv_id="">INA (Institut National de l&#x27;Audiovisuel)</channel>
|
||||
<channel site="france.tv" site_id="lcp-public-senat" lang="fr" xmltv_id="LCPPublicSenat.fr">LCP Public Sénat</channel>
|
||||
<channel site="france.tv" site_id="mieux" lang="fr" xmltv_id="">Mieux</channel>
|
||||
<channel site="france.tv" site_id="serie" lang="fr" xmltv_id="">France Télévisions Séries</channel>
|
||||
<channel site="france.tv" site_id="sport" lang="fr" xmltv_id="">France Télévisions Sport</channel>
|
||||
<channel site="france.tv" site_id="tv5-monde" lang="fr" xmltv_id="">TV5 Monde Plus</channel>
|
||||
</channels>
|
||||
@@ -0,0 +1,159 @@
|
||||
const dayjs = require('dayjs')
|
||||
const axios = require('axios')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.tz.setDefault('Europe/Paris')
|
||||
|
||||
// Because France is excellent at pointing hours, their programs ALL start at 5/6 am,
|
||||
// so we need to keep track of the earlier day's program to get the midnight programming. How... odd.
|
||||
module.exports = {
|
||||
site: 'france.tv',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
return `https://www.france.tv/api/epg/videos/?date=${date.format('YYYY-MM-DD')}&channel=${channel.site_id}`
|
||||
},
|
||||
parser: async function ({ channel, content, date }) {
|
||||
const programs = []
|
||||
let items = []
|
||||
|
||||
const dayBefore = date.subtract(1, 'd').format('YYYY-MM-DD')
|
||||
const linkDayBefore = `https://www.france.tv/api/epg/videos/?date=${dayBefore}&channel=${channel.site_id}`
|
||||
|
||||
try {
|
||||
const responseDayBefore = await axios.get(linkDayBefore)
|
||||
const programmingDayBefore = responseDayBefore.data || []
|
||||
|
||||
// The broadcast day starts at ~6 AM. Programs with hour < 6 in the day-before API
|
||||
// are actually early morning programs (00:00-05:59) of our target date.
|
||||
if (Array.isArray(programmingDayBefore)) {
|
||||
programmingDayBefore.forEach(item => {
|
||||
const time = item?.content?.broadcastBeginDate
|
||||
if (!time) return
|
||||
const hour = parseInt(time.split('h')[0])
|
||||
|
||||
if (hour < 6) {
|
||||
items.push(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
// Day before data unavailable, continue with current day only
|
||||
}
|
||||
|
||||
// From the current day's API, only include programs starting from 6h onwards.
|
||||
// Programs with hour < 6 belong to the next calendar day's schedule.
|
||||
try {
|
||||
const currentDayItems = JSON.parse(content) || []
|
||||
if (Array.isArray(currentDayItems)) {
|
||||
currentDayItems.forEach(item => {
|
||||
const time = item?.content?.broadcastBeginDate
|
||||
if (!time) return
|
||||
const hour = parseInt(time.split('h')[0])
|
||||
|
||||
if (hour >= 6) {
|
||||
items.push(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
return programs
|
||||
}
|
||||
|
||||
items.forEach(item => {
|
||||
const { start, stop } = parseDuration(date, item)
|
||||
if (!start.isValid() || !stop.isValid()) return
|
||||
// Can contain Season and Episode in title, but not always. If title is missing, skip the program
|
||||
if (!item?.content?.title) return
|
||||
|
||||
let title = item.content.title
|
||||
let season = null
|
||||
let episode = null
|
||||
|
||||
const seMatch = title.match(/\s*-?\s*S(\d+)\s+E(\d+)\s*-?\s*/)
|
||||
if (seMatch) {
|
||||
season = parseInt(seMatch[1])
|
||||
episode = parseInt(seMatch[2])
|
||||
title = title.replace(seMatch[0], ' ').replace(/^\s+/, '').replace(/\s+$/, '').trim()
|
||||
}
|
||||
|
||||
const fullTitle = (item.content.titleLeading ? item.content.titleLeading + (title ? ' - ' : '') : '') + title
|
||||
|
||||
programs.push({
|
||||
title: fullTitle,
|
||||
description: item.content.description,
|
||||
image: getImageUrl(item),
|
||||
icon: getImageUrl(item),
|
||||
start,
|
||||
stop,
|
||||
season: season,
|
||||
episode: episode,
|
||||
rating: item.content.csa
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
try {
|
||||
const response = await axios.get('https://www.france.tv/chaines/')
|
||||
const data = response.data || ''
|
||||
const channels = []
|
||||
|
||||
const channelRegex =
|
||||
/<button[^>]+aria-controls="[^"]*content-([a-z0-9-]+)"[\s\S]*?<title>([^<]+)<\/title>/gi
|
||||
|
||||
let match
|
||||
while ((match = channelRegex.exec(data)) !== null) {
|
||||
channels.push({
|
||||
lang: 'fr',
|
||||
site_id: match[1],
|
||||
name: match[2].trim()
|
||||
})
|
||||
}
|
||||
|
||||
return [...new Map(channels.map(channel => [channel.site_id, channel])).values()]
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch channels list:', error.message)
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseDuration(date, item) {
|
||||
const current_date = date.format('YYYY-MM-DD')
|
||||
const time = item.content?.broadcastBeginDate
|
||||
const duration = item.content?.duration // e.g. "11 min 45 s", "1 h 30 min", "30 min"
|
||||
|
||||
if (!time) return { start: dayjs(null), stop: dayjs(null) }
|
||||
|
||||
const timeParts = time.split('h')
|
||||
|
||||
let durationInSeconds = 0
|
||||
if (duration) {
|
||||
const durationParts = duration.split(' ')
|
||||
for (let i = 0; i < durationParts.length; i++) {
|
||||
const part = durationParts[i]
|
||||
if (part === 'h' && i > 0) {
|
||||
durationInSeconds += parseInt(durationParts[i - 1]) * 3600
|
||||
} else if (part === 'min' && i > 0) {
|
||||
durationInSeconds += parseInt(durationParts[i - 1]) * 60
|
||||
} else if (part === 's' && i > 0) {
|
||||
durationInSeconds += parseInt(durationParts[i - 1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const start = dayjs.utc(`${current_date} ${timeParts[0]}:${timeParts[1]}`, 'YYYY-MM-DD HH:mm')
|
||||
const stop = start.add(durationInSeconds, 'second')
|
||||
return { start, stop }
|
||||
}
|
||||
|
||||
function getImageUrl(item) {
|
||||
const url = item.content?.thumbnail?.x1
|
||||
return url
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
const { parser, url } = require('./france.tv.config.js')
|
||||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2026-02-19', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'france-2',
|
||||
xmltv_id: 'France2.fr@HD'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe('https://www.france.tv/api/epg/videos/?date=2026-02-19&channel=france-2')
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
axios.get.mockResolvedValue({ data: [] })
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const results = (await parser({ content, date, channel })).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(18)
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Le 6h info - Émission du jeudi 19 février 2026',
|
||||
description: "Un rendez-vous réveil-matin, avec un point sur l'actualité assorti de différentes rubriques qui permettent d'en explorer certains aspects plus en profondeur.",
|
||||
image: 'https://medias.france.tv/S9p5NdAs4OR2UbyC1NIQWsYV-K4/240x0/filters:quality(85):format(webp)/b/f/3/e85c2e8fed4a4955965dfff63c3843fb.jpg',
|
||||
start: '2026-02-19T06:00:00.000Z',
|
||||
stop: '2026-02-19T06:30:00.000Z'
|
||||
})
|
||||
expect(results[17]).toMatchObject({
|
||||
title: 'JO Club - Émission du jeudi 19 février 2026',
|
||||
description: "Tous les soirs, tout au long de ces Jeux olympiques d'hiver de Milan-Cortina, Laurent Luyat revient, avec les journalistes et consultants de France Télévisions, sur les épreuves de la journée. Il accueille les athlètes et les médaillés du jour. La journée a été marquée par du combiné nordique, avec l'épreuve par équipes messieurs, les demi-final...",
|
||||
image: 'https://medias.france.tv/xuxaBPNFyhMiVB5eeYrZV_1nPj4/240x0/filters:quality(85):format(webp)/v/p/h/phpmhbhpv.jpg',
|
||||
start: '2026-02-19T23:00:00.000Z',
|
||||
stop: '2026-02-20T00:00:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
axios.get.mockResolvedValue({ data: [] })
|
||||
const results = await parser({ content: [], date, channel })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
# france.tv
|
||||
|
||||
https://www.france.tv/
|
||||
|
||||
### Download the guide
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=france.tv
|
||||
```
|
||||
|
||||
### Update channel list
|
||||
|
||||
```sh
|
||||
npm run channels:parse --- --config=./sites/france.tv/france.tv.config.js --output=./sites/france.tv/france.tv.channels.xml
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
```sh
|
||||
npm test --- france.tv
|
||||
```
|
||||
@@ -21,7 +21,7 @@ module.exports = {
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
const programs = []
|
||||
let items = []
|
||||
let items
|
||||
|
||||
try {
|
||||
items = JSON.parse(content)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const url = require('url')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
@@ -44,24 +43,36 @@ module.exports = {
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://www.gatotv.com/guia_tv/completa')
|
||||
.get('https://www.gatotv.com/canales_de_tv')
|
||||
.then(response => response.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray()
|
||||
const items = $('table.tbl_tv_guide tr.tbl_EPG_row, table.tbl_tv_guide tr.tbl_EPG_rowAlternate').toArray()
|
||||
|
||||
return items.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const link = $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').attr('href')
|
||||
const parsed = url.parse(link)
|
||||
return items
|
||||
.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const link = $item('a[href*="/canal/"]').first().attr('href')
|
||||
if (!link) return null
|
||||
|
||||
return {
|
||||
lang: 'es',
|
||||
site_id: path.basename(parsed.pathname),
|
||||
name: $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').text()
|
||||
}
|
||||
})
|
||||
let pathname
|
||||
try {
|
||||
pathname = new URL(link, 'https://www.gatotv.com').pathname
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
const name = $item('td:nth-child(2) a').text().trim() || $item('a[href*="/canal/"]').last().text().trim()
|
||||
if (!name) return null
|
||||
|
||||
return {
|
||||
lang: 'es',
|
||||
site_id: path.basename(pathname),
|
||||
name
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user