diff --git a/sites/tvtv.us/tvtv.us.config.js b/sites/tvtv.us/tvtv.us.config.js index 83c14931..e5b88903 100644 --- a/sites/tvtv.us/tvtv.us.config.js +++ b/sites/tvtv.us/tvtv.us.config.js @@ -1,3 +1,4 @@ +const axios = require('axios') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') @@ -5,38 +6,78 @@ dayjs.extend(utc) module.exports = { site: 'tvtv.us', + ignore: true, // NOTE: site_id of most channels must be re-mapped url: function ({ date, channel }) { - return `https://tvtv.us/tvm/t/tv/v4/stations/${ + return `https://www.tvtv.us/gn/d/v1.1/stations/${ channel.site_id - }/listings?start=${date.format()}&end=${date.add(1, 'd').format()}` + }/airings?startDateTime=${date.format()}&endDateTime=${date.add(1, 'd').format()}` }, logo({ channel }) { return channel.logo }, parser: function ({ content }) { let programs = [] - const items = JSON.parse(content) - if (!items.length) return programs + + const items = parseItems(content) items.forEach(item => { - const start = dayjs.utc(item.listDateTime) - const stop = start.add(item.duration, 'm') - const icon = item.showPicture - ? `https://cdn.tvpassport.com/image/show/480x720/${item.showPicture}` - : null - let title = item.showName - if (title === 'Movie') { - title = item.episodeTitle - } programs.push({ - title: title, - description: item.description, - category: item.showType, - start: start.toString(), - stop: stop.toString(), - icon + title: parseTitle(item), + description: parseDescription(item), + category: parseCategory(item), + start: parseStart(item), + stop: parseStop(item), + icon: parseIcon(item) }) }) return programs + }, + async channels({ country }) { + const data = await axios + .get(`https://www.tvtv.${country}/api/stations`) + .then(r => r.data) + .catch(console.log) + + return data.data + .filter(i => ['Satellite'].includes(i.type)) + .map(item => { + return { + lang: 'en', + site_id: item.id, + xmltv_id: item.shortName, + name: item.name, + logo: item.logo + } + }) } } + +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 +} + +function parseDescription(item) { + return item.program.longDescription +} + +function parseCategory(item) { + return item.program.genres || [] +} + +function parseIcon(item) { + return item.program.preferredImage && item.program.preferredImage.uri + ? `http://tvtv.tmsimg.com/${item.program.preferredImage.uri}` + : null +}