mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00

Test: ```sh npm test --- digiturk.com.tr > test > run-script-os digiturk.com.tr > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand digiturk.com.tr PASS sites/digiturk.com.tr/digiturk.com.tr.test.js √ can generate valid url (3 ms) √ can parse response (167 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 0.918 s, estimated 1 s Ran all test suites matching /digiturk.com.tr/i. ``` Grab: ```sh npm run grab --- --site=digiturk.com.tr > grab > npx tsx scripts/commands/epg/grab.ts --site=digiturk.com.tr starting... config: output: guide.xml maxConnections: 1 gzip: false site: digiturk.com.tr loading channels... found 108 channel(s) run #1: [1/216] digiturk.com.tr (tr) - 212 - Jan 12, 2025 (56 programs) [2/216] digiturk.com.tr (tr) - 212 - Jan 13, 2025 (58 programs) ... [215/216] digiturk.com.tr (tr) - VavTV.tr - Jan 13, 2025 (18 programs) [216/216] digiturk.com.tr (tr) - TVNET.tr - Jan 13, 2025 (32 programs) saving to "guide.xml"... done in 00h 02m 10s ``` Signed-off-by: Toha <tohenk@yahoo.com>
86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
const cheerio = require('cheerio')
|
|
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)
|
|
dayjs.extend(timezone)
|
|
dayjs.extend(customParseFormat)
|
|
|
|
const tz = 'Europe/Istanbul'
|
|
|
|
module.exports = {
|
|
site: 'digiturk.com.tr',
|
|
days: 2,
|
|
url({ date }) {
|
|
return `https://www.digiturk.com.tr/Ajax/GetTvGuideFromDigiturk?Day=${
|
|
encodeURIComponent(date.format('MM/DD/YYYY'))
|
|
}+00%3A00%3A00`
|
|
},
|
|
request: {
|
|
cache: {
|
|
ttl: 24 * 60 * 60 * 1000 // 1 day
|
|
}
|
|
},
|
|
parser({ content, channel, date }) {
|
|
const programs = []
|
|
if (content) {
|
|
const $ = cheerio.load(content)
|
|
$('.channelDetail').toArray()
|
|
.forEach(item => {
|
|
const $item = $(item)
|
|
const title = $item.find('.tvGuideResult-box-wholeDates-title')
|
|
if (title.length) {
|
|
const channelId = title.attr('onclick')
|
|
if (channelId) {
|
|
const site_id = channelId.match(/\s(\d+)\)/)[1]
|
|
if (channel.site_id === site_id) {
|
|
const startTime = $item.find('.tvGuideResult-box-wholeDates-time-hour').text().trim()
|
|
const duration = $item.find('.tvGuideResult-box-wholeDates-time-totalMinute')
|
|
.text().trim().match(/\d+/)[0]
|
|
const start = dayjs.tz(`${date.format('YYYY-MM-DD')} ${startTime}`, 'YYYY-MM-DD HH:mm', tz)
|
|
const stop = start.add(parseInt(duration), 'm')
|
|
programs.push({
|
|
title: title.text().trim(),
|
|
start,
|
|
stop
|
|
})
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
return programs
|
|
},
|
|
async channels() {
|
|
const channels = {}
|
|
const axios = require('axios')
|
|
const data = await axios
|
|
.get(this.url({ date: dayjs() }))
|
|
.then(r => r.data)
|
|
.catch(console.error)
|
|
|
|
const $ = cheerio.load(data)
|
|
$('.channelContent').toArray()
|
|
.forEach(el => {
|
|
const item = $(el)
|
|
const channelId = item.find('.channelDetail .tvGuideResult-box-wholeDates-title')
|
|
.first()
|
|
.attr('onclick')
|
|
if (channelId) {
|
|
const site_id = channelId.match(/\s(\d+)\)/)[1]
|
|
if (channels[site_id] === undefined) {
|
|
channels[site_id] = {
|
|
lang: 'tr',
|
|
site_id,
|
|
name: item.find('#channelID').val()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
return Object.values(channels)
|
|
}
|
|
}
|