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