Files
epg/sites/tvplus.com.tr/tvplus.com.tr.config.js
T

100 lines
3.0 KiB
JavaScript
Raw Normal View History

2024-12-15 22:49:55 +07:00
const cheerio = require('cheerio')
2023-10-15 14:08:23 +03:00
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
2024-12-15 22:49:55 +07:00
const debug = require('debug')('site:tvplus.com.tr')
2023-10-15 14:08:23 +03:00
dayjs.extend(utc)
dayjs.extend(customParseFormat)
2024-12-15 22:49:55 +07:00
const channelsUrl = 'https://tvplus.com.tr/canli-tv/yayin-akisi'
2023-10-15 14:08:23 +03:00
module.exports = {
site: 'tvplus.com.tr',
days: 2,
request: {
2024-12-15 22:49:55 +07:00
cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day
2023-10-15 14:08:23 +03:00
}
},
2024-12-15 22:49:55 +07:00
async url({ channel }) {
if (module.exports.buildId === undefined) {
module.exports.buildId = await module.exports.fetchBuildId()
debug('Got build id', module.exports.buildId)
}
const channelId = channel.site_id.replace('/', '--')
2025-01-01 12:27:22 +03:00
return `https://tvplus.com.tr/_next/data/${module.exports.buildId}/${channel.lang}/canli-tv/yayin-akisi/${channelId}.json?title=${channelId}`
2024-12-15 22:49:55 +07:00
},
parser({ content, date }) {
const programs = []
if (content) {
const data = JSON.parse(content)
if (Array.isArray(data?.pageProps?.allPlaybillList)) {
data.pageProps.allPlaybillList
.filter(i => i.length && i[0].starttime.startsWith(date.format('YYYY-MM-DD')))
.forEach(i => {
for (const schedule of i) {
2025-01-01 12:27:22 +03:00
const [, season, episode] = schedule.seasonInfo?.match(
/(\d+)\. Sezon - (\d+)\. Bölüm/
) || [null, null, null]
2024-12-15 22:49:55 +07:00
programs.push({
title: schedule.name,
description: schedule.introduce,
category: schedule.genres,
image: schedule.picture,
season: season ? parseInt(season) : null,
episode: episode ? parseInt(episode) : null,
start: dayjs.utc(schedule.starttime),
stop: dayjs.utc(schedule.endtime)
})
}
})
}
}
2023-10-15 14:08:23 +03:00
return programs
2023-12-01 21:28:49 +03:00
},
async channels() {
const channels = []
const data = await axios
2024-12-15 22:49:55 +07:00
.get(channelsUrl)
2023-12-01 21:28:49 +03:00
.then(r => r.data)
2024-12-15 22:49:55 +07:00
.catch(console.error)
2023-12-01 21:28:49 +03:00
const $ = cheerio.load(data)
2025-01-01 12:27:22 +03:00
$('.channel-list-item a')
.toArray()
2024-12-15 22:49:55 +07:00
.forEach(el => {
const a = $(el)
channels.push({
lang: 'tr',
2025-01-01 12:27:22 +03:00
name: a
.attr('title')
.replace(/Yayın Akışı/, '')
.trim(),
site_id: a
.attr('href')
.replace(/\/canli-tv\/yayin-akisi\//, '')
2024-12-15 22:49:55 +07:00
.replace('--', '/') // change -- to / as it used in xml comment
})
2023-12-01 21:28:49 +03:00
})
return channels
2024-12-15 22:49:55 +07:00
},
async fetchBuildId() {
const data = await axios
.get(channelsUrl)
.then(r => r.data)
.catch(console.error)
2023-10-15 14:08:23 +03:00
2024-12-15 22:49:55 +07:00
if (data) {
const $ = cheerio.load(data)
const nextData = JSON.parse($('#__NEXT_DATA__').text())
return nextData?.buildId || null
} else {
return null
}
}
2023-10-15 14:08:23 +03:00
}