Update tvplus.com.tr.config.js

This commit is contained in:
freearhey
2026-04-19 07:25:54 +03:00
parent 4a237acef8
commit 415dfb5c7f

View File

@@ -1,102 +1,72 @@
const cheerio = require('cheerio')
const axios = require('axios')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
const debug = require('debug')('site:tvplus.com.tr')
dayjs.extend(utc)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
const baseUrl = 'https://tvplus.com.tr/canli-tv/yayin-akisi'
module.exports = { module.exports = {
site: 'tvplus.com.tr', site: 'tvplus.com.tr',
days: 2, days: 2,
url: 'https://izmaottvsc14.tvplus.com.tr:33207/EPG/JSON/PlayBillList',
request: { request: {
method: 'POST',
headers: {
cookie: 'JSESSIONID=05DH3LSUA0W04YMLSYEWK3TRYY1QMBMY;'
},
data({ channel, date }) {
return {
type: '2',
channelid: channel.site_id,
begintime: date.format('YYYYMMDDHHmmss'),
endtime: date.add(1, 'd').format('YYYYMMDDHHmmss'),
isFillProgram: 1
}
},
cache: { cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day ttl: 24 * 60 * 60 * 1000 // 1 day
} }
}, },
async url({ channel }) { parser({ content }) {
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('/', '--')
return `https://tvplus.com.tr/_next/data/${module.exports.buildId}/${channel.lang}/canli-tv/yayin-akisi/${channelId}.json?title=${channelId}`
},
parser({ content, date }) {
const programs = [] const programs = []
if (content) {
const data = JSON.parse(content) const items = parseItems(content)
if (Array.isArray(data?.pageProps?.allPlaybillList)) {
data.pageProps.allPlaybillList items.forEach(schedule => {
.filter(i => i.length && i[0].starttime.startsWith(date.format('YYYY-MM-DD')))
.forEach(i => {
for (const schedule of i) {
const [, season, episode] = schedule.seasonInfo?.match(
/(\d+)\. Sezon - (\d+)\. Bölüm/
) || [null, null, null]
programs.push({ programs.push({
title: schedule.name, title: schedule.name,
description: schedule.introduce, description: schedule.introduce,
category: schedule.genres, category: schedule.genres,
image: schedule.picture, icon: parseIcon(schedule),
season: season ? parseInt(season) : null, image: parseImage(schedule),
episode: episode ? parseInt(episode) : null, start: parseTime(schedule.starttime),
start: dayjs.utc(schedule.starttime), stop: parseTime(schedule.endtime)
stop: dayjs.utc(schedule.endtime)
}) })
}
}) })
}
}
return programs return programs
}, }
async channels() { }
if (module.exports.buildId === undefined) {
module.exports.buildId = await module.exports.fetchBuildId() function parseTime(time) {
debug('Got build id', module.exports.buildId) return dayjs(time, 'YYYY-MM-DD HH:mm:ss [UTC]Z')
} }
const channels = []
const data = await axios function parseImage(schedule) {
.get(`https://tvplus.com.tr/_next/data/${module.exports.buildId}/canli-tv/yayin-akisi.json`) return schedule?.picture?.still || null
.then(r => r.data) }
.catch(console.error)
function parseIcon(schedule) {
const channels_json = data.pageProps.channelListSsr if (typeof schedule?.picture?.icon !== 'string') return null
channels_json.forEach(channel => { return schedule.picture.icon.split(',')[0]
channels.push({ }
lang: 'tr',
name: channel.name, function parseItems(content) {
site_id: channel.name.normalize('NFD') // Decompose accented characters try {
.replace(/[\u0300-\u036f]/g, '') // Remove accent marks const data = JSON.parse(content)
.toLowerCase() if (!data || !Array.isArray(data.playbilllist)) return []
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/[^a-zA-Z0-9-]/g, '') // Remove special chars but keep hyphens return data.playbilllist
.replace(/^-+|-+$/g, '') // Remove leading/trailing hyphens } catch {
+ '/' + channel.id, return []
logo: channel.channelLogo
})
})
return channels
},
async fetchBuildId() {
const data = await axios
.get(baseUrl)
.then(r => r.data)
.catch(console.error)
if (data) {
const $ = cheerio.load(data)
const nextData = JSON.parse($('#__NEXT_DATA__').text())
return nextData?.buildId || null
} else {
return null
}
} }
} }