-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
digiturk.com.tr.config.js
107 lines (96 loc) · 2.73 KB
/
digiturk.com.tr.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const _ = require('lodash')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
// category list is not complete
// const categories = {
// '00': 'Diğer',
// E0: 'Romantik Komedi',
// E1: 'Aksiyon',
// E4: 'Macera',
// E5: 'Dram',
// E6: 'Fantastik',
// E7: 'Komedi',
// E8: 'Korku',
// EB: 'Polisiye',
// EF: 'Western',
// FA: 'Macera',
// FB: 'Yarışma',
// FC: 'Eğlence',
// F0: 'Reality-Show',
// F2: 'Haberler',
// F4: 'Belgesel',
// F6: 'Eğitim',
// F7: 'Sanat ve Kültür',
// F9: 'Life Style'
// }
module.exports = {
site: 'digiturk.com.tr',
days: 2,
delay: 1000, // NOTE: under heavy load the server starts blocking requests
url: function ({ date, channel }) {
return `https://www.digiturk.com.tr/_Ajax/getBroadcast.aspx?channelNo=${
channel.site_id
}&date=${date.format('DD.MM.YYYY')}&tomorrow=false&primetime=false`
},
request: {
method: 'GET',
headers: {
Referer: 'https://www.digiturk.com.tr/'
}
},
parser: function ({ content }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
programs.push({
title: item.PName,
// description: item.LongDescription,
// category: parseCategory(item),
start: parseTime(item.PStartTime),
stop: parseTime(item.PEndTime)
})
})
programs = _.sortBy(programs, 'start')
return programs
},
async channels() {
const axios = require('axios')
const cheerio = require('cheerio')
const data = await axios
.get(`https://www.digiturk.com.tr/`, {
headers: {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}
})
.then(r => r.data)
.catch(console.log)
let channels = []
const $ = cheerio.load(data)
$('#chosen-select-channel > option').each((i, el) => {
const site_id = $(el).attr('value')
const name = $(el).text().trim()
channels.push({
lang: 'tr',
site_id,
name
})
})
return channels
}
}
function parseTime(time) {
let timestamp = parseInt(time.replace('/Date(', '').replace('+0300)/', ''))
return dayjs(timestamp)
}
// function parseCategory(item) {
// return (item.PGenre) ? categories[item.PGenre] : null
// }
function parseItems(content) {
if (!content) return []
const data = JSON.parse(content)
return data && data.BChannels && data.BChannels[0].CPrograms ? data.BChannels[0].CPrograms : []
}