mirror of
https://github.com/iptv-org/epg
synced 2026-05-02 23:46:59 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,93 +1,93 @@
|
||||
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)
|
||||
|
||||
dayjs.Ls.en.weekStart = 1
|
||||
|
||||
module.exports = {
|
||||
site: 'berrymedia.co.kr',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `http://www.berrymedia.co.kr/schedule_proc${channel.site_id}.php`
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
data({ date }) {
|
||||
let params = new URLSearchParams()
|
||||
let startOfWeek = date.startOf('week').format('YYYY-MM-DD')
|
||||
let endOfWeek = date.endOf('week').format('YYYY-MM-DD')
|
||||
|
||||
params.append('week', `${startOfWeek}~${endOfWeek}`)
|
||||
params.append('day', date.format('YYYY-MM-DD'))
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
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 (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),
|
||||
category: parseCategory($item),
|
||||
rating: parseRating($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('span:nth-child(1)').text().trim()
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Asia/Seoul')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('span.sdfsdf').clone().children().remove().end().text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('span:nth-child(2) > p').text().trim()
|
||||
}
|
||||
|
||||
function parseRating($item) {
|
||||
const rating = $item('span:nth-child(5) > p:nth-child(1)').text().trim()
|
||||
|
||||
return rating
|
||||
? {
|
||||
system: 'KMRB',
|
||||
value: rating
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.sc_time dd').toArray()
|
||||
}
|
||||
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)
|
||||
|
||||
dayjs.Ls.en.weekStart = 1
|
||||
|
||||
module.exports = {
|
||||
site: 'berrymedia.co.kr',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `http://www.berrymedia.co.kr/schedule_proc${channel.site_id}.php`
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
data({ date }) {
|
||||
let params = new URLSearchParams()
|
||||
let startOfWeek = date.startOf('week').format('YYYY-MM-DD')
|
||||
let endOfWeek = date.endOf('week').format('YYYY-MM-DD')
|
||||
|
||||
params.append('week', `${startOfWeek}~${endOfWeek}`)
|
||||
params.append('day', date.format('YYYY-MM-DD'))
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
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 (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),
|
||||
category: parseCategory($item),
|
||||
rating: parseRating($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('span:nth-child(1)').text().trim()
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Asia/Seoul')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('span.sdfsdf').clone().children().remove().end().text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('span:nth-child(2) > p').text().trim()
|
||||
}
|
||||
|
||||
function parseRating($item) {
|
||||
const rating = $item('span:nth-child(5) > p:nth-child(1)').text().trim()
|
||||
|
||||
return rating
|
||||
? {
|
||||
system: 'KMRB',
|
||||
value: rating
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.sc_time dd').toArray()
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
const { parser, url, request } = require('./berrymedia.co.kr.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '',
|
||||
xmltv_id: 'GTV.kr'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('http://www.berrymedia.co.kr/schedule_proc.php')
|
||||
})
|
||||
|
||||
it('can generate request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
let params = request.data({ date })
|
||||
|
||||
expect(params.get('week')).toBe('2023-01-23~2023-01-29')
|
||||
expect(params.get('day')).toBe('2023-01-26')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
||||
let results = parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-25T15:00:00.000Z',
|
||||
stop: '2023-01-25T16:00:00.000Z',
|
||||
title: '더트롯쇼',
|
||||
category: '연예/오락',
|
||||
rating: {
|
||||
system: 'KMRB',
|
||||
value: '15'
|
||||
}
|
||||
})
|
||||
|
||||
expect(results[17]).toMatchObject({
|
||||
start: '2023-01-26T13:50:00.000Z',
|
||||
stop: '2023-01-26T14:20:00.000Z',
|
||||
title: '나는 자연인이다',
|
||||
category: '교양',
|
||||
rating: {
|
||||
system: 'KMRB',
|
||||
value: 'ALL'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url, request } = require('./berrymedia.co.kr.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '',
|
||||
xmltv_id: 'GTV.kr'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('http://www.berrymedia.co.kr/schedule_proc.php')
|
||||
})
|
||||
|
||||
it('can generate request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
let params = request.data({ date })
|
||||
|
||||
expect(params.get('week')).toBe('2023-01-23~2023-01-29')
|
||||
expect(params.get('day')).toBe('2023-01-26')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
||||
let results = parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-25T15:00:00.000Z',
|
||||
stop: '2023-01-25T16:00:00.000Z',
|
||||
title: '더트롯쇼',
|
||||
category: '연예/오락',
|
||||
rating: {
|
||||
system: 'KMRB',
|
||||
value: '15'
|
||||
}
|
||||
})
|
||||
|
||||
expect(results[17]).toMatchObject({
|
||||
start: '2023-01-26T13:50:00.000Z',
|
||||
stop: '2023-01-26T14:20:00.000Z',
|
||||
title: '나는 자연인이다',
|
||||
category: '교양',
|
||||
rating: {
|
||||
system: 'KMRB',
|
||||
value: 'ALL'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user