mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
tvtv.us re-write
This commit is contained in:
parent
40020356a5
commit
f2fd02454c
4 changed files with 40 additions and 165 deletions
|
@ -1,4 +1,3 @@
|
||||||
const axios = require('axios')
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
|
@ -7,144 +6,31 @@ dayjs.extend(utc)
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'tvtv.us',
|
site: 'tvtv.us',
|
||||||
url: function ({ date, channel }) {
|
url: function ({ date, channel }) {
|
||||||
return `https://www.tvtv.us/gn/d/v1.1/stations/${
|
return `https://www.tvtv.us/api/v1/lineup/USA-NY71652-DEFAULT/grid/${date.toJSON()}/${date.add(1, 'd').toJSON()}/${channel.site_id}`
|
||||||
channel.site_id
|
|
||||||
}/airings?startDateTime=${date.format()}&endDateTime=${date.add(1, 'd').format()}`
|
|
||||||
},
|
},
|
||||||
parser: function ({ content }) {
|
parser: function ({ content }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
|
|
||||||
const items = parseItems(content)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
|
const start = dayjs.utc(item.startTime)
|
||||||
|
const stop = start.add(item.runTime, 'm')
|
||||||
programs.push({
|
programs.push({
|
||||||
title: parseTitle(item),
|
title: item.title,
|
||||||
sub_title: parseSubtitle(item),
|
description: item.subtitle,
|
||||||
description: parseDescription(item),
|
start,
|
||||||
category: parseCategory(item),
|
stop
|
||||||
season: parseSeason(item),
|
|
||||||
episode: parseEpisode(item),
|
|
||||||
directors: parseDirectors(item),
|
|
||||||
actors: parseActors(item),
|
|
||||||
date: parseDate(item),
|
|
||||||
start: parseStart(item),
|
|
||||||
stop: parseStop(item),
|
|
||||||
icon: parseIcon(item)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
|
||||||
async channels({ country }) {
|
|
||||||
const channels = []
|
|
||||||
|
|
||||||
const data = await axios
|
|
||||||
.get(`https://www.tvtv.${country}/api/stations`)
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
|
|
||||||
const stations = data.data.filter(i => !['Radio Station'].includes(i.type))
|
|
||||||
for (const station of stations) {
|
|
||||||
const stationData = await axios
|
|
||||||
.get(`https://www.tvtv.us/gn/d/v1.1/stations/${station.id}`)
|
|
||||||
.then(r => r.data[0] || {})
|
|
||||||
.catch(console.log)
|
|
||||||
if (!stationData) continue
|
|
||||||
|
|
||||||
let channel
|
|
||||||
switch (stationData.type) {
|
|
||||||
case 'Low Power Broadcast':
|
|
||||||
case 'Full Power Broadcast':
|
|
||||||
channel = {
|
|
||||||
site_id: station.id,
|
|
||||||
name: stationData.name,
|
|
||||||
xmltv_id: parseChannelId(stationData),
|
|
||||||
logo: parseChannelIcon(item)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
channel = {
|
|
||||||
site_id: station.id,
|
|
||||||
name: stationData.name,
|
|
||||||
logo: parseChannelIcon(item)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel) {
|
|
||||||
channels.push(channel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return channels
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseChannelId(data) {
|
|
||||||
if (!data.callSign) return null
|
|
||||||
if (/^((CB|C[F-K]|V[A-G]|VO|VX|VY|X[J-O])[0-9A-Z-]+)/.test(data.callSign))
|
|
||||||
return `${data.callSign}.ca`
|
|
||||||
if (/^((XH|XE)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.mx`
|
|
||||||
if (/^((K|N|W)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.us`
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(content) {
|
function parseItems(content) {
|
||||||
return JSON.parse(content)
|
const json = JSON.parse(content)
|
||||||
|
if (!json.length) return []
|
||||||
|
return json[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item) {
|
|
||||||
return dayjs(item.startTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStop(item) {
|
|
||||||
return dayjs(item.endTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseTitle(item) {
|
|
||||||
return item.program.title
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseSubtitle(item) {
|
|
||||||
return item.program.episodeTitle
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseDescription(item) {
|
|
||||||
return item.program.longDescription
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCategory(item) {
|
|
||||||
return item.program.genres || []
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseSeason(item) {
|
|
||||||
return item.program.seasonNum || null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseEpisode(item) {
|
|
||||||
return item.program.episodeNum || null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseDirectors(item) {
|
|
||||||
return item.program.directors || []
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseDate(item) {
|
|
||||||
return item.program.releaseDate
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseActors(item) {
|
|
||||||
return item.program.topCast || []
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseIcon(item) {
|
|
||||||
return item.program.preferredImage && item.program.preferredImage.uri
|
|
||||||
? `https://tvtv.us/gn/i/${item.program.preferredImage.uri}`
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseChannelIcon(item) {
|
|
||||||
return item.station.preferredImage && item.station.preferredImage.uri
|
|
||||||
? `https://tvtv.us/gn/i/${item.station.preferredImage.uri}`
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const date = dayjs.utc('2022-01-17', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2022-09-20', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '62670',
|
site_id: '62670',
|
||||||
xmltv_id: 'AMITV.ca',
|
xmltv_id: 'AMITV.ca',
|
||||||
|
@ -17,12 +17,12 @@ const channel = {
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ channel, date })).toBe(
|
expect(url({ channel, date })).toBe(
|
||||||
'https://www.tvtv.us/gn/d/v1.1/stations/62670/airings?startDateTime=2022-01-17T00:00:00Z&endDateTime=2022-01-18T00:00:00Z'
|
'https://www.tvtv.us/api/v1/lineup/USA-NY71652-DEFAULT/grid/2022-09-20T00:00:00.000Z/2022-09-21T00:00:00.000Z/62670'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = `[{"startTime":"2022-01-20T00:00Z","endTime":"2022-01-20T00:30Z","duration":30,"qualifiers":["CC","DVS"],"program":{"tmsId":"EP031727440006","rootId":"16777148","seriesId":"16640522","subType":"Series","title":"Reflect and Renew With Kevin Naidoo","episodeTitle":"Empowerment","releaseYear":2019,"releaseDate":"2019-04-20","origAirDate":"2019-04-20","titleLang":"en","descriptionLang":"en","entityType":"Episode","genres":["Health"],"longDescription":"Kevin demonstrates a meditation and yoga practice to reclaim his courage and confidence.","shortDescription":"Kevin demonstrates a meditation and yoga practice to reclaim his courage and confidence.","episodeNum":6,"seasonNum":1,"ratings":[{"body":"Régie du cinéma","code":"G"},{"body":"USA Parental Rating","code":"TVG"},{"body":"Canadian Parental Rating","code":"G"}],"preferredImage":{"width":"240","height":"360","uri":"assets/p16640522_b_v9_aa.jpg?w=240&h=360","category":"Banner-L2","text":"yes","primary":"true","tier":"Series"}},"station":{"stationId":"62670","callSign":"AMITV","videoQuality":{"signalType":"Digital","videoType":"SDTV"},"preferredImage":{"width":"360","height":"270","uri":"assets/s62670_ll_h15_ab.png?w=360&h=270","category":"Logo","primary":"true"}}},{"startTime":"2022-01-20T00:30Z","endTime":"2022-01-20T01:00Z","duration":30,"qualifiers":["CC","DVS"],"program":{"tmsId":"EP018574900040","rootId":"12448902","seriesId":"10464580","subType":"Series","title":"Four Senses","episodeTitle":"Sizzled & Seared","releaseYear":2016,"releaseDate":"2016-01-14","origAirDate":"2016-01-14","titleLang":"en","descriptionLang":"en","entityType":"Episode","genres":["House/garden"],"longDescription":"Everything is sizzled and seared as chef Corbin Tomaszeski joins Christine and Carl in the kitchen.","shortDescription":"Everything is sizzled and seared as chef Corbin Tomaszeski joins Christine and Carl in the kitchen.","topCast":["Carl Heinrich","Christine Ha"],"ratings":[{"body":"Canadian Parental Rating","code":"G"},{"body":"USA Parental Rating","code":"TVG"},{"body":"Régie du cinéma","code":"G"}],"preferredImage":{"width":"240","height":"360","uri":"assets/p10464580_b_v7_aa.jpg?w=240&h=360","category":"Banner-L1","text":"yes","primary":"true","tier":"Series"}},"station":{"stationId":"62670","callSign":"AMITV","videoQuality":{"signalType":"Digital","videoType":"SDTV"},"preferredImage":{"width":"360","height":"270","uri":"assets/s62670_ll_h15_ab.png?w=360&h=270","category":"Logo","primary":"true"}}}]`
|
const content = `[[{"programId":"EP039131940001","title":"Beyond the Field","subtitle":"Diversity in Sport","flags":["CC","DVS"],"type":"O","startTime":"2022-09-20T00:00Z","start":0,"duration":30,"runTime":30},{"programId":"EP032368970002","title":"IGotThis","subtitle":"Listen to Dis","flags":["CC","DVS"],"type":"O","startTime":"2022-09-20T00:30Z","start":120,"duration":30,"runTime":30}]]`
|
||||||
|
|
||||||
const result = parser({ content }).map(p => {
|
const result = parser({ content }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
|
@ -32,27 +32,16 @@ it('can parse response', () => {
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(result).toMatchObject([
|
||||||
{
|
{
|
||||||
start: '2022-01-20T00:00:00.000Z',
|
start: '2022-09-20T00:00:00.000Z',
|
||||||
stop: '2022-01-20T00:30:00.000Z',
|
stop: '2022-09-20T00:30:00.000Z',
|
||||||
title: 'Reflect and Renew With Kevin Naidoo',
|
title: 'Beyond the Field',
|
||||||
sub_title: 'Empowerment',
|
description: `Diversity in Sport`
|
||||||
description: `Kevin demonstrates a meditation and yoga practice to reclaim his courage and confidence.`,
|
|
||||||
category: ['Health'],
|
|
||||||
season: 1,
|
|
||||||
episode: 6,
|
|
||||||
date: '2019-04-20',
|
|
||||||
icon: 'https://tvtv.us/gn/i/assets/p16640522_b_v9_aa.jpg?w=240&h=360'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2022-01-20T00:30:00.000Z',
|
start: '2022-09-20T00:30:00.000Z',
|
||||||
stop: '2022-01-20T01:00:00.000Z',
|
stop: '2022-09-20T01:00:00.000Z',
|
||||||
title: 'Four Senses',
|
title: 'IGotThis',
|
||||||
sub_title: 'Sizzled & Seared',
|
description: `Listen to Dis`
|
||||||
description: `Everything is sizzled and seared as chef Corbin Tomaszeski joins Christine and Carl in the kitchen.`,
|
|
||||||
category: ['House/garden'],
|
|
||||||
actors: ['Carl Heinrich','Christine Ha'],
|
|
||||||
date: '2016-01-14',
|
|
||||||
icon: 'https://tvtv.us/gn/i/assets/p10464580_b_v7_aa.jpg?w=240&h=360'
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue