mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Create tv.dir.bg.config.js
This commit is contained in:
parent
6e0717cbb0
commit
70a1d9819b
1 changed files with 95 additions and 0 deletions
95
sites/tv.dir.bg/tv.dir.bg.config.js
Normal file
95
sites/tv.dir.bg/tv.dir.bg.config.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
module.exports = {
|
||||
site: 'tv.dir.bg',
|
||||
url({ channel, date }) {
|
||||
return `https://tv.dir.bg/tv_channel.php?id=${channel.site_id}&dd=${date.format('DD.MM')}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const requests = [
|
||||
axios.get(`https://tv.dir.bg/programata.php?t=0`),
|
||||
axios.get(`https://tv.dir.bg/programata.php?t=1`)
|
||||
]
|
||||
|
||||
const items = await Promise.all(requests)
|
||||
.then(r => {
|
||||
return r
|
||||
.map(i => {
|
||||
const html = i.data
|
||||
const $ = cheerio.load(html)
|
||||
return $('#programa-left > div > div > div > a').toArray()
|
||||
})
|
||||
.reduce((acc, curr) => {
|
||||
acc = acc.concat(curr)
|
||||
return acc
|
||||
}, [])
|
||||
})
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load('')
|
||||
return items.map(item => {
|
||||
const $item = $(item)
|
||||
return {
|
||||
lang: 'bg',
|
||||
site_id: $item.attr('href').replace('tv_channel.php?id=', ''),
|
||||
name: $item.find('div.thumbnail > img').attr('alt'),
|
||||
logo: $item.find('div.thumbnail > img').data('src')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('i').text()
|
||||
if (!time) return null
|
||||
const dateString = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
|
||||
return dayjs.tz(dateString, 'MM/DD/YYYY HH.mm', 'Europe/Sofia')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item
|
||||
.text()
|
||||
.replace(/^\d{2}.\d{2}/, '')
|
||||
.trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#events > li').toArray()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue