mirror of
https://github.com/iptv-org/epg
synced 2026-04-27 13:06:58 -04:00
crlf fix?
This commit is contained in:
@@ -1,71 +1,71 @@
|
|||||||
const axios = require('axios')
|
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')
|
||||||
|
|
||||||
const HEADERS = {
|
const HEADERS = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
||||||
'Referer': 'https://distro.tv/',
|
'Referer': 'https://distro.tv/',
|
||||||
'Origin': 'https://distro.tv'
|
'Origin': 'https://distro.tv'
|
||||||
}
|
}
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'distro.tv',
|
site: 'distro.tv',
|
||||||
days: 2,
|
days: 2,
|
||||||
request: {
|
request: {
|
||||||
headers: HEADERS
|
headers: HEADERS
|
||||||
},
|
},
|
||||||
url({ channel }) {
|
url({ channel }) {
|
||||||
const days = module.exports.days || 2
|
const days = module.exports.days || 2
|
||||||
const hours = days * 24
|
const hours = days * 24
|
||||||
return `https://tv.jsrdn.com/epg/query.php?range=now,${hours}h&id=${channel.site_id},`
|
return `https://tv.jsrdn.com/epg/query.php?range=now,${hours}h&id=${channel.site_id},`
|
||||||
},
|
},
|
||||||
parser({ content, channel }) {
|
parser({ content, channel }) {
|
||||||
if (!content || !channel) return []
|
if (!content || !channel) return []
|
||||||
let programs = []
|
let programs = []
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
if (!data.epg || !data.epg[channel.site_id] || !Array.isArray(data.epg[channel.site_id].slots)) {
|
if (!data.epg || !data.epg[channel.site_id] || !Array.isArray(data.epg[channel.site_id].slots)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
programs = data.epg[channel.site_id].slots.map(program => ({
|
programs = data.epg[channel.site_id].slots.map(program => ({
|
||||||
title: program.title,
|
title: program.title,
|
||||||
description: program.description || null,
|
description: program.description || null,
|
||||||
icon: program.img_thumbh || null,
|
icon: program.img_thumbh || null,
|
||||||
start: dayjs.utc(program.start, 'YYYY-MM-DD HH:mm:ss'),
|
start: dayjs.utc(program.start, 'YYYY-MM-DD HH:mm:ss'),
|
||||||
stop: dayjs.utc(program.end, 'YYYY-MM-DD HH:mm:ss')
|
stop: dayjs.utc(program.end, 'YYYY-MM-DD HH:mm:ss')
|
||||||
}))
|
}))
|
||||||
} catch {
|
} catch {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
return programs.filter(p => p.title && p.start.isValid() && p.stop.isValid())
|
return programs.filter(p => p.title && p.start.isValid() && p.stop.isValid())
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
const { data } = await axios.get('https://tv.jsrdn.com/tv_v5/getfeed.php?type=live', {
|
const { data } = await axios.get('https://tv.jsrdn.com/tv_v5/getfeed.php?type=live', {
|
||||||
headers: HEADERS
|
headers: HEADERS
|
||||||
})
|
})
|
||||||
|
|
||||||
const channels = []
|
const channels = []
|
||||||
if (data && data.shows) {
|
if (data && data.shows) {
|
||||||
Object.values(data.shows).forEach(show => {
|
Object.values(data.shows).forEach(show => {
|
||||||
const episode = show.seasons?.[0]?.episodes?.[0]
|
const episode = show.seasons?.[0]?.episodes?.[0]
|
||||||
if (episode && episode.id) {
|
if (episode && episode.id) {
|
||||||
channels.push({
|
channels.push({
|
||||||
lang: 'en',
|
lang: 'en',
|
||||||
// lang: show.language || 'en',
|
// lang: show.language || 'en',
|
||||||
site_id: episode.id.toString(),
|
site_id: episode.id.toString(),
|
||||||
name: show.title,
|
name: show.title,
|
||||||
// logo: show.img_logo,
|
// logo: show.img_logo,
|
||||||
// url: episode.content?.url || null
|
// url: episode.content?.url || null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,70 +1,70 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { parser, url, channels } = require('./distro.tv.config.js')
|
const { parser, url, channels } = require('./distro.tv.config.js')
|
||||||
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)
|
||||||
|
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
|
|
||||||
const date = dayjs.utc('2026-02-10', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2026-02-10', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '45143'
|
site_id: '45143'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ channel, date })).toBe(
|
expect(url({ channel, date })).toBe(
|
||||||
'https://tv.jsrdn.com/epg/query.php?range=now,48h&id=45143,'
|
'https://tv.jsrdn.com/epg/query.php?range=now,48h&id=45143,'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'), 'utf8')
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'), 'utf8')
|
||||||
const results = parser({ content, channel })
|
const results = parser({ content, channel })
|
||||||
|
|
||||||
expect(results[0]).toMatchObject({
|
expect(results[0]).toMatchObject({
|
||||||
title: 'News',
|
title: 'News',
|
||||||
description: 'The leading news stories of the moment.',
|
description: 'The leading news stories of the moment.',
|
||||||
start: dayjs.utc('2026-02-10 10:17:05'),
|
start: dayjs.utc('2026-02-10 10:17:05'),
|
||||||
stop: dayjs.utc('2026-02-10 10:30:00')
|
stop: dayjs.utc('2026-02-10 10:30:00')
|
||||||
})
|
})
|
||||||
expect(results[1]).toMatchObject({
|
expect(results[1]).toMatchObject({
|
||||||
title: 'Euronews Now',
|
title: 'Euronews Now',
|
||||||
description: 'Breaking News. In depth analysis on the biggest stories making headlines in Europe and across the world.',
|
description: 'Breaking News. In depth analysis on the biggest stories making headlines in Europe and across the world.',
|
||||||
start: dayjs.utc('2026-02-10 10:30:00'),
|
start: dayjs.utc('2026-02-10 10:30:00'),
|
||||||
stop: dayjs.utc('2026-02-10 10:46:00')
|
stop: dayjs.utc('2026-02-10 10:46:00')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
const results = parser({
|
const results = parser({
|
||||||
content: '{"epg":{"45143":{"title":"Euronews","slots":[]}}}',
|
content: '{"epg":{"45143":{"title":"Euronews","slots":[]}}}',
|
||||||
channel
|
channel
|
||||||
})
|
})
|
||||||
expect(results).toMatchObject([])
|
expect(results).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can fetch channels', async () => {
|
it('can fetch channels', async () => {
|
||||||
axios.get.mockResolvedValue({
|
axios.get.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
shows: {
|
shows: {
|
||||||
414: {
|
414: {
|
||||||
title: 'Titanic TV',
|
title: 'Titanic TV',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
img_logo: 'logo.png',
|
img_logo: 'logo.png',
|
||||||
seasons: [{ episodes: [{ id: 10953 }] }]
|
seasons: [{ episodes: [{ id: 10953 }] }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const result = await channels()
|
const result = await channels()
|
||||||
expect(result[0]).toMatchObject({
|
expect(result[0]).toMatchObject({
|
||||||
lang: 'en',
|
lang: 'en',
|
||||||
site_id: '10953',
|
site_id: '10953',
|
||||||
name: 'Titanic TV'
|
name: 'Titanic TV'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user