Files
epg/sites/tvtv.us/tvtv.us.config.js
T

151 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-01-17 23:13:36 +03:00
const axios = require('axios')
2021-04-10 03:52:10 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
module.exports = {
site: 'tvtv.us',
url: function ({ date, channel }) {
2022-01-17 23:13:36 +03:00
return `https://www.tvtv.us/gn/d/v1.1/stations/${
2021-04-10 03:52:10 +03:00
channel.site_id
2022-01-17 23:13:36 +03:00
}/airings?startDateTime=${date.format()}&endDateTime=${date.add(1, 'd').format()}`
2021-04-10 03:52:10 +03:00
},
parser: function ({ content }) {
let programs = []
2022-01-17 23:13:36 +03:00
const items = parseItems(content)
2021-04-10 03:52:10 +03:00
items.forEach(item => {
programs.push({
2022-01-17 23:13:36 +03:00
title: parseTitle(item),
2022-07-01 09:05:29 -04:00
sub_title: parseSubtitle(item),
2022-01-17 23:13:36 +03:00
description: parseDescription(item),
category: parseCategory(item),
2022-01-20 21:00:58 +03:00
season: parseSeason(item),
episode: parseEpisode(item),
2022-08-17 21:24:07 -04:00
directors: parseDirectors(item),
actors: parseActors(item),
date: parseDate(item),
2022-01-17 23:13:36 +03:00
start: parseStart(item),
stop: parseStop(item),
icon: parseIcon(item)
2021-04-10 03:52:10 +03:00
})
})
return programs
2022-01-17 23:13:36 +03:00
},
async channels({ country }) {
2022-01-23 15:06:03 +03:00
const channels = []
2022-01-17 23:13:36 +03:00
const data = await axios
.get(`https://www.tvtv.${country}/api/stations`)
.then(r => r.data)
.catch(console.log)
2022-01-23 15:06:03 +03:00
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,
2022-07-07 03:47:27 -04:00
xmltv_id: parseChannelId(stationData),
2022-07-07 03:34:36 -04:00
logo: parseChannelIcon(item)
2022-01-23 15:06:03 +03:00
}
break
default:
channel = {
site_id: station.id,
2022-07-07 03:47:27 -04:00
name: stationData.name,
logo: parseChannelIcon(item)
2022-01-23 15:06:03 +03:00
}
break
}
if (channel) {
channels.push(channel)
}
}
return channels
2021-04-10 03:52:10 +03:00
}
}
2022-01-17 23:13:36 +03:00
2022-01-23 15:06:03 +03:00
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
}
2022-01-17 23:13:36 +03:00
function parseItems(content) {
return JSON.parse(content)
}
function parseStart(item) {
return dayjs(item.startTime)
}
function parseStop(item) {
return dayjs(item.endTime)
}
function parseTitle(item) {
return item.program.title
}
2022-07-01 09:05:29 -04:00
function parseSubtitle(item) {
2022-07-07 03:50:20 -04:00
return item.program.episodeTitle
2022-07-01 09:05:29 -04:00
}
2022-01-17 23:13:36 +03:00
function parseDescription(item) {
return item.program.longDescription
}
function parseCategory(item) {
return item.program.genres || []
}
2022-01-20 21:00:58 +03:00
function parseSeason(item) {
return item.program.seasonNum || null
}
function parseEpisode(item) {
return item.program.episodeNum || null
}
2022-08-17 21:24:07 -04:00
function parseDirectors(item) {
return item.program.directors || []
}
function parseDate(item) {
2022-08-23 22:13:34 -04:00
return item.program.releaseDate
2022-08-17 21:24:07 -04:00
}
function parseActors(item) {
return item.program.topCast || []
}
2022-01-17 23:13:36 +03:00
function parseIcon(item) {
2022-08-17 21:24:07 -04:00
return item.program.preferredImage && item.program.preferredImage.uri
? `https://tvtv.us/gn/i/${item.program.preferredImage.uri}`
2022-01-17 23:13:36 +03:00
: null
}
2022-07-07 03:34:36 -04:00
function parseChannelIcon(item) {
return item.station.preferredImage && item.station.preferredImage.uri
? `https://tvtv.us/gn/i/${item.station.preferredImage.uri}`
: null
}