aboutsummaryrefslogtreecommitdiff
path: root/src/getScheduleHtml.ts
blob: 327150bb22503eea28b299d16f318ae803e04ba0 (plain) (blame)
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
import https from 'https'

const OPTIONS = {
  hostname: 'schedule.hololive.tv',
  port: 443,
  path: '/',
  method: 'GET',
  headers: {
    Cookie: 'timezone=Asia/Tokyo',
  },
}

function getScheduleHtml(): Promise<string> {
  const chunks: Uint8Array[] = []

  return new Promise((resolve, reject) => {
    const req = https.request(OPTIONS, res => {
      res.on('data', chunk => {
        chunks.push(chunk)
      })

      res.on('end', () => {
        const html = Buffer.concat(chunks).toString('utf-8')
        resolve(html)
      })
    })

    req.on('error', error => {
      reject(error)
    })

    req.end()
  })
}

export default getScheduleHtml