mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update dishtv.in.config.js
This commit is contained in:
parent
db94809828
commit
d027e0072f
1 changed files with 122 additions and 118 deletions
|
@ -1,163 +1,167 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const cheerio = require('cheerio')
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
||||||
|
|
||||||
dayjs.extend(utc)
|
let authToken
|
||||||
dayjs.extend(timezone)
|
|
||||||
dayjs.extend(customParseFormat)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'dishtv.in',
|
site: 'dishtv.in',
|
||||||
days: 2,
|
days: 2,
|
||||||
url: 'https://www.dishtv.in/WhatsonIndiaWebService.asmx/LoadPagginResultDataForProgram',
|
url: 'https://epg.mysmartstick.com/dishtv/api/v1/epg/entities/programs',
|
||||||
request: {
|
request: {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
async headers() {
|
||||||
|
await fetchToken()
|
||||||
|
|
||||||
|
return {
|
||||||
|
Authorization: authToken
|
||||||
|
}
|
||||||
|
},
|
||||||
data({ channel, date }) {
|
data({ channel, date }) {
|
||||||
return {
|
return {
|
||||||
Channelarr: channel.site_id,
|
allowPastEvents: true,
|
||||||
fromdate: date.format('YYYYMMDDHHmm'),
|
channelid: channel.site_id,
|
||||||
todate: date.add(1, 'd').format('YYYYMMDDHHmm')
|
date: date.format('DD/MM/YYYY')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parser: function ({ content, date }) {
|
parser: ({ content }) => {
|
||||||
let programs = []
|
const programs = []
|
||||||
const data = parseContent(content)
|
const items = parseItems(content)
|
||||||
const items = parseItems(data)
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
|
||||||
const start = parseStart(item, date)
|
|
||||||
const stop = parseStop(item, start)
|
|
||||||
if (title === 'No Information Available') return
|
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title: parseTitle(item),
|
||||||
start: start.toString(),
|
description: parseDescription(item),
|
||||||
stop: stop.toString()
|
category: parseCategory(item),
|
||||||
|
actors: item.credits.actors,
|
||||||
|
directors: item.credits.directors,
|
||||||
|
producers: item.credits.producers,
|
||||||
|
date: item.productionyear,
|
||||||
|
icon: parseIcon(item),
|
||||||
|
image: parseImage(item),
|
||||||
|
episode: parseEpisode(item),
|
||||||
|
start: dayjs(item.start),
|
||||||
|
stop: dayjs(item.stop)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
let channels = []
|
await fetchToken()
|
||||||
|
|
||||||
const pages = await loadPageList()
|
const totalPages = await fetchPages()
|
||||||
for (let page of pages) {
|
|
||||||
const data = await axios
|
const queue = Array.from(Array(totalPages).keys()).map(i => {
|
||||||
.post(
|
const data = new FormData()
|
||||||
'https://www.dishtv.in/WhatsonIndiaWebService.asmx/LoadPagginResultDataForProgram',
|
data.append('pageNum', i + 1)
|
||||||
page,
|
|
||||||
{ timeout: 30000 }
|
return {
|
||||||
)
|
method: 'post',
|
||||||
|
url: 'https://www.dishtv.in/services/epg/channels',
|
||||||
|
data,
|
||||||
|
headers: {
|
||||||
|
'authorization-token': authToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const channels = []
|
||||||
|
for (let item of queue) {
|
||||||
|
const data = await axios(item)
|
||||||
.then(r => r.data)
|
.then(r => r.data)
|
||||||
.catch(console.log)
|
.catch(console.error)
|
||||||
|
|
||||||
const $ = cheerio.load(data.d)
|
|
||||||
$('.pgrid').each((i, el) => {
|
|
||||||
const onclick = $(el).find('.chnl-logo').attr('onclick')
|
|
||||||
const number = $(el).find('.cnl-fav > a > span').text().trim()
|
|
||||||
const [, , site_id] = onclick.match(/ShowChannelGuid\('([^']+)','([^']+)'/) || [
|
|
||||||
null,
|
|
||||||
'',
|
|
||||||
''
|
|
||||||
]
|
|
||||||
|
|
||||||
|
data.programDetailsByChannel.forEach(channel => {
|
||||||
channels.push({
|
channels.push({
|
||||||
lang: 'en',
|
lang: 'en',
|
||||||
number,
|
site_id: channel.channelid,
|
||||||
site_id
|
name: channel.channelname
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const names = await loadChannelNames()
|
|
||||||
channels = channels
|
|
||||||
.map(channel => {
|
|
||||||
channel.name = names[channel.number]
|
|
||||||
|
|
||||||
return channel
|
|
||||||
})
|
|
||||||
.filter(channel => channel.name)
|
|
||||||
|
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPageList() {
|
function parseTitle(item) {
|
||||||
const data = await axios
|
return Object.values(item.regional)
|
||||||
.get('https://www.dishtv.in/channelguide/')
|
.map(region => ({
|
||||||
.then(r => r.data)
|
lang: region.languagecode,
|
||||||
.catch(console.log)
|
value: region.title
|
||||||
|
}))
|
||||||
let pages = []
|
.filter(i => Boolean(i.value))
|
||||||
const $ = cheerio.load(data)
|
|
||||||
$('#MainContent_recordPagging li').each((i, el) => {
|
|
||||||
const onclick = $(el).find('a').attr('onclick')
|
|
||||||
const [, Channelarr, fromdate, todate] = onclick.match(
|
|
||||||
/ShowNextPageResult\('([^']+)','([^']+)','([^']+)'/
|
|
||||||
) || [null, '', '', '']
|
|
||||||
|
|
||||||
pages.push({ Channelarr, fromdate, todate })
|
|
||||||
})
|
|
||||||
|
|
||||||
return pages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadChannelNames() {
|
function parseDescription(item) {
|
||||||
const names = {}
|
return Object.values(item.regional)
|
||||||
|
.map(region => ({
|
||||||
|
lang: region.languagecode,
|
||||||
|
value: region.desc
|
||||||
|
}))
|
||||||
|
.filter(i => Boolean(i.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory(item) {
|
||||||
|
return Object.values(item.regional)
|
||||||
|
.map(region => ({
|
||||||
|
lang: region.languagecode,
|
||||||
|
value: region.genre
|
||||||
|
}))
|
||||||
|
.filter(i => Boolean(i.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseEpisode(item) {
|
||||||
|
return item['episode-num'] ? parseInt(item['episode-num']) : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIcon(item) {
|
||||||
|
return item.programmeurl || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseImage(item) {
|
||||||
|
return item?.images?.landscape?.['1280x720'] ? item.images.landscape['1280x720'] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
|
||||||
|
return Array.isArray(data) ? data : []
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchToken() {
|
||||||
|
if (authToken) return
|
||||||
|
|
||||||
const data = await axios
|
const data = await axios
|
||||||
.post('https://www.dishtv.in/WebServiceMethod.aspx/GetChannelListFromMobileAPI', {
|
.post('https://www.dishtv.in/services/epg/signin', null, {
|
||||||
strChannel: ''
|
headers: {
|
||||||
|
'sec-fetch-dest': 'empty',
|
||||||
|
'sec-fetch-mode': 'cors',
|
||||||
|
'sec-fetch-site': 'same-origin',
|
||||||
|
'x-requested-with': 'XMLHttpRequest',
|
||||||
|
Referer: 'https://www.dishtv.in/channel-guide.html'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(r => r.data)
|
.then(r => r.data)
|
||||||
.catch(console.log)
|
.catch(console.error)
|
||||||
|
|
||||||
const $ = cheerio.load(data.d)
|
authToken = data.token
|
||||||
$('#tblpackChnl > div').each((i, el) => {
|
|
||||||
const num = $(el).find('p:nth-child(2)').text().trim()
|
|
||||||
const name = $(el).find('p').first().text().trim()
|
|
||||||
|
|
||||||
if (num === '') return
|
|
||||||
|
|
||||||
names[num] = name
|
|
||||||
})
|
|
||||||
|
|
||||||
return names
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
async function fetchPages() {
|
||||||
const $ = cheerio.load(item)
|
const formData = new FormData()
|
||||||
|
formData.append('pageNum', 1)
|
||||||
|
|
||||||
return $('a').text()
|
const data = await axios
|
||||||
}
|
.post('https://www.dishtv.in/services/epg/channels', formData, {
|
||||||
|
headers: { 'authorization-token': authToken }
|
||||||
function parseStart(item) {
|
})
|
||||||
const $ = cheerio.load(item)
|
.then(r => r.data)
|
||||||
const onclick = $('i.fa-circle').attr('onclick')
|
.catch(console.error)
|
||||||
const [, time] = onclick.match(/RecordingEnteryOpen\('.*','.*','(.*)','.*',.*\)/)
|
|
||||||
|
return data.totalPages ? parseInt(data.totalPages) : 0
|
||||||
return dayjs.tz(time, 'YYYYMMDDHHmm', 'Asia/Kolkata')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStop(item, start) {
|
|
||||||
const $ = cheerio.load(item)
|
|
||||||
const duration = $('*').data('time')
|
|
||||||
|
|
||||||
return start.add(duration, 'm')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseContent(content) {
|
|
||||||
const data = JSON.parse(content)
|
|
||||||
|
|
||||||
return data.d
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(data) {
|
|
||||||
const $ = cheerio.load(data)
|
|
||||||
|
|
||||||
return $('.datatime').toArray()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue