Replace LF endings with CRLF

This commit is contained in:
freearhey
2025-07-31 22:29:01 +03:00
parent 17e3b4ddda
commit 29aa427923
379 changed files with 29332 additions and 29332 deletions

View File

@@ -1,92 +1,92 @@
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 = 'Asia/Hong_Kong'
module.exports = {
site: 'programme.tvb.com',
days: 2,
url({ channel, date, time = null }) {
return `https://programme.tvb.com/api/schedule?input_date=${date.format(
'YYYYMMDD'
)}&network_code=${channel.site_id}&_t=${time ? time : parseInt(Date.now() / 1000)}`
},
parser({ content, channel, date }) {
const programs = []
const data = content ? JSON.parse(content) : {}
if (Array.isArray(data.data?.list)) {
for (const d of data.data.list) {
if (Array.isArray(d.schedules)) {
const schedules = d.schedules.filter(s => s.network_code === channel.site_id)
schedules.forEach((s, i) => {
const start = dayjs.tz(s.event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
let stop
if (i < schedules.length - 1) {
stop = dayjs.tz(schedules[i + 1].event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
} else {
stop = date.add(1, 'd')
}
programs.push({
title: channel.lang === 'en' ? s.en_programme_title : s.programme_title,
description: channel.lang === 'en' ? s.en_synopsis : s.synopsis,
start,
stop
})
})
}
}
}
return programs
},
async channels({ lang = 'en' }) {
const channels = []
const axios = require('axios')
const base = 'https://programme.tvb.com'
const queues = [base]
while (true) {
if (queues.length) {
const url = queues.shift()
const content = await axios
.get(url)
.then(response => response.data)
.catch(console.error)
if (content) {
const assets = content.match(/assets\/index\.([a-z0-9]+)\.js/g)
if (assets) {
queues.push(...assets.map(a => base + '/' + a))
} else {
const metadata = content.match(/e=(\[(.*?)\])/)
if (metadata) {
const infos = eval(metadata[1])
if (Array.isArray(infos)) {
infos
.filter(a => a.code.length)
.map(a => {
channels.push({
lang,
site_id: a.code,
name: lang === 'en' ? a.nameEn : a.name
})
})
break
}
}
}
if (queues.length) {
continue
}
}
}
break
}
return channels
}
}
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 = 'Asia/Hong_Kong'
module.exports = {
site: 'programme.tvb.com',
days: 2,
url({ channel, date, time = null }) {
return `https://programme.tvb.com/api/schedule?input_date=${date.format(
'YYYYMMDD'
)}&network_code=${channel.site_id}&_t=${time ? time : parseInt(Date.now() / 1000)}`
},
parser({ content, channel, date }) {
const programs = []
const data = content ? JSON.parse(content) : {}
if (Array.isArray(data.data?.list)) {
for (const d of data.data.list) {
if (Array.isArray(d.schedules)) {
const schedules = d.schedules.filter(s => s.network_code === channel.site_id)
schedules.forEach((s, i) => {
const start = dayjs.tz(s.event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
let stop
if (i < schedules.length - 1) {
stop = dayjs.tz(schedules[i + 1].event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
} else {
stop = date.add(1, 'd')
}
programs.push({
title: channel.lang === 'en' ? s.en_programme_title : s.programme_title,
description: channel.lang === 'en' ? s.en_synopsis : s.synopsis,
start,
stop
})
})
}
}
}
return programs
},
async channels({ lang = 'en' }) {
const channels = []
const axios = require('axios')
const base = 'https://programme.tvb.com'
const queues = [base]
while (true) {
if (queues.length) {
const url = queues.shift()
const content = await axios
.get(url)
.then(response => response.data)
.catch(console.error)
if (content) {
const assets = content.match(/assets\/index\.([a-z0-9]+)\.js/g)
if (assets) {
queues.push(...assets.map(a => base + '/' + a))
} else {
const metadata = content.match(/e=(\[(.*?)\])/)
if (metadata) {
const infos = eval(metadata[1])
if (Array.isArray(infos)) {
infos
.filter(a => a.code.length)
.map(a => {
channels.push({
lang,
site_id: a.code,
name: lang === 'en' ? a.nameEn : a.name
})
})
break
}
}
}
if (queues.length) {
continue
}
}
}
break
}
return channels
}
}

View File

@@ -1,64 +1,64 @@
const { parser, url } = require('./programme.tvb.com.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 content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'J',
xmltv_id: 'Jade.hk',
lang: 'en'
}
it('can generate valid url', () => {
const time = 1733491000
expect(url({ channel, date, time })).toBe(
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
)
})
it('can parse response (en)', () => {
const results = parser({ content, channel, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(3)
expect(results[1]).toMatchObject({
start: '2024-12-06T15:55:00.000Z',
stop: '2024-12-06T16:55:00.000Z',
title: 'Line Walker: Bull Fight#16[Can][PG]'
})
})
it('can parse response (zh)', () => {
const results = parser({ content, channel: { ...channel, lang: 'zh' }, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(3)
expect(results[1]).toMatchObject({
start: '2024-12-06T15:55:00.000Z',
stop: '2024-12-06T16:55:00.000Z',
title: '使徒行者3#16[粵][PG]',
description:
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。'
})
})
it('can handle empty guide', () => {
const result = parser({
content: '',
date
})
expect(result).toMatchObject([])
})
const { parser, url } = require('./programme.tvb.com.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 content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'J',
xmltv_id: 'Jade.hk',
lang: 'en'
}
it('can generate valid url', () => {
const time = 1733491000
expect(url({ channel, date, time })).toBe(
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
)
})
it('can parse response (en)', () => {
const results = parser({ content, channel, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(3)
expect(results[1]).toMatchObject({
start: '2024-12-06T15:55:00.000Z',
stop: '2024-12-06T16:55:00.000Z',
title: 'Line Walker: Bull Fight#16[Can][PG]'
})
})
it('can parse response (zh)', () => {
const results = parser({ content, channel: { ...channel, lang: 'zh' }, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(3)
expect(results[1]).toMatchObject({
start: '2024-12-06T15:55:00.000Z',
stop: '2024-12-06T16:55:00.000Z',
title: '使徒行者3#16[粵][PG]',
description:
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。'
})
})
it('can handle empty guide', () => {
const result = parser({
content: '',
date
})
expect(result).toMatchObject([])
})