diff --git a/sites/tv.cctv.com/__data__/content.json b/sites/tv.cctv.com/__data__/content.json new file mode 100644 index 00000000..e1739edb --- /dev/null +++ b/sites/tv.cctv.com/__data__/content.json @@ -0,0 +1 @@ +{"data":{"cctv1":{"channelName":"CCTV-1 综合","lvUrl":"https://tv.cctv.com/live/cctv1","vip_flag":0,"list":[{"title":"今日说法-2023-302","startTime":1701277980,"endTime":1701279675,"showTime":"01:13","eventType":"","eventId":"","length":1695,"column_url":"https://tv.cctv.com/lm/jrsf/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/jrsf/videoset/","top":""},{"title":"人与自然-2023-248","startTime":1701279675,"endTime":1701281415,"showTime":"01:41","eventType":"","eventId":"","length":1740,"column_url":"https://tv.cctv.com/lm/ryzr/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/ryzr/index.shtml","top":""},{"title":"晚间新闻","startTime":1701281415,"endTime":1701283355,"showTime":"02:10","eventType":"","eventId":"","length":1940,"column_url":"https://tv.cctv.com/lm/wjxw/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/wjxw/index.shtml","top":""},{"title":"精彩一刻-2023-12湿地扎陵湖","startTime":1701283355,"endTime":1701283650,"showTime":"02:42","eventType":"","eventId":"","length":295,"column_url":"","columnBackvideourl":"","top":""},{"title":"精彩一刻-2023-13湿地天鹅洲","startTime":1701283650,"endTime":1701284100,"showTime":"02:47","eventType":"","eventId":"","length":450,"column_url":"","columnBackvideourl":"","top":""},{"title":"非遗里的中国-3","startTime":1701284100,"endTime":1701289740,"showTime":"02:55","eventType":"","eventId":"","length":5640,"column_url":"","columnBackvideourl":"","top":""},{"title":"今日说法-2023-302","startTime":1701289740,"endTime":1701291600,"showTime":"04:29","eventType":"","eventId":"","length":1860,"column_url":"https://tv.cctv.com/lm/jrsf/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/jrsf/videoset/","top":""},{"title":"新闻联播","startTime":1701291600,"endTime":1701293400,"showTime":"05:00","eventType":"","eventId":"","length":1800,"column_url":"https://tv.cctv.com/lm/xwlb/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/xwlb/index.shtml","top":""},{"title":"人与自然-2023-249","startTime":1701293400,"endTime":1701295200,"showTime":"05:30","eventType":"","eventId":"","length":1800,"column_url":"https://tv.cctv.com/lm/ryzr/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/ryzr/index.shtml","top":""},{"title":"朝闻天下","startTime":1701295200,"endTime":1701304595,"showTime":"06:00","eventType":"","eventId":"","length":9395,"column_url":"https://tv.cctv.com/lm/zwtx/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/zwtx/index.shtml","top":""},{"title":"生活早参考-特别节目(生活圈)2023-243","startTime":1701304595,"endTime":1701307560,"showTime":"08:36","eventType":"","eventId":"","length":2965,"column_url":"https://tv.cctv.com/lm/shq/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/shq/index.shtml","top":""},{"title":"人世间32/58","startTime":1701307560,"endTime":1701310485,"showTime":"09:26","eventType":"","eventId":"","length":2925,"column_url":"","columnBackvideourl":"","top":""},{"title":"人世间33/58","startTime":1701310485,"endTime":1701313410,"showTime":"10:14","eventType":"","eventId":"","length":2925,"column_url":"","columnBackvideourl":"","top":""},{"title":"人世间34/58","startTime":1701313410,"endTime":1701316260,"showTime":"11:03","eventType":"","eventId":"","length":2850,"column_url":"","columnBackvideourl":"","top":""},{"title":"2023秘境之眼-312","startTime":1701316260,"endTime":1701316500,"showTime":"11:51","eventType":"","eventId":"","length":240,"column_url":"","columnBackvideourl":"","top":""},{"title":"寻宝-文脉春秋宣传片(3分钟)","startTime":1701316500,"endTime":1701316800,"showTime":"11:55","eventType":"","eventId":"","length":300,"column_url":"","columnBackvideourl":"","top":""},{"title":"新闻30分","startTime":1701316800,"endTime":1701318990,"showTime":"12:00","eventType":"","eventId":"","length":2190,"column_url":"https://tv.cctv.com/lm/xw30f/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/xw30f/index.shtml","top":""},{"title":"今日说法-2023-303","startTime":1701318990,"endTime":1701321060,"showTime":"12:36","eventType":"","eventId":"","length":2070,"column_url":"https://tv.cctv.com/lm/jrsf/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/jrsf/videoset/","top":""},{"title":"梦中的那片海27/38","startTime":1701321060,"endTime":1701323940,"showTime":"13:11","eventType":"","eventId":"","length":2880,"column_url":"","columnBackvideourl":"","top":""},{"title":"梦中的那片海28/38","startTime":1701323940,"endTime":1701326920,"showTime":"13:59","eventType":"","eventId":"","length":2980,"column_url":"","columnBackvideourl":"","top":""},{"title":"梦中的那片海29/38","startTime":1701326920,"endTime":1701329775,"showTime":"14:48","eventType":"","eventId":"","length":2855,"column_url":"","columnBackvideourl":"","top":""},{"title":"梦中的那片海30/38","startTime":1701329775,"endTime":1701332755,"showTime":"15:36","eventType":"","eventId":"","length":2980,"column_url":"","columnBackvideourl":"","top":""},{"title":"梦中的那片海31/38","startTime":1701332755,"endTime":1701335805,"showTime":"16:25","eventType":"","eventId":"","length":3050,"column_url":"","columnBackvideourl":"","top":""},{"title":"第一动画乐园-2023-601","startTime":1701335805,"endTime":1701337030,"showTime":"17:16","eventType":"","eventId":"","length":1225,"column_url":"https://tv.cctv.com/lm/dydhly/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/dydhly/index.shtml","top":""},{"title":"第一动画乐园-2023-602","startTime":1701337030,"endTime":1701339535,"showTime":"17:37","eventType":"","eventId":"","length":2505,"column_url":"https://tv.cctv.com/lm/dydhly/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/dydhly/index.shtml","top":""},{"title":"2023秘境之眼-312","startTime":1701339535,"endTime":1701339670,"showTime":"18:18","eventType":"","eventId":"","length":135,"column_url":"","columnBackvideourl":"","top":""},{"title":"寻宝-文脉春秋-6","startTime":1701339670,"endTime":1701342000,"showTime":"18:21","eventType":"","eventId":"","length":2330,"column_url":"","columnBackvideourl":"","top":""},{"title":"新闻联播","startTime":1701342000,"endTime":1701344360,"showTime":"19:00","eventType":"","eventId":"","length":2360,"column_url":"https://tv.cctv.com/lm/xwlb/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/xwlb/index.shtml","top":""},{"title":"焦点访谈","startTime":1701344360,"endTime":1701345660,"showTime":"19:39","eventType":"","eventId":"","length":1300,"column_url":"https://tv.cctv.com/lm/jdft/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/jdft/index.shtml","top":""},{"title":"前情提要-《此心安处是吾乡》23/32","startTime":1701345660,"endTime":1701345960,"showTime":"20:01","eventType":"","eventId":"","length":300,"column_url":"","columnBackvideourl":"","top":""},{"title":"此心安处是吾乡23/32","startTime":1701345960,"endTime":1701349200,"showTime":"20:06","eventType":"","eventId":"","length":3240,"column_url":"","columnBackvideourl":"","top":""},{"title":"专题节目-1","startTime":1701349200,"endTime":1701352500,"showTime":"21:00","eventType":"","eventId":"","length":3300,"column_url":"","columnBackvideourl":"","top":""},{"title":"寻宝-文脉春秋宣传片(3分钟)","startTime":1701352500,"endTime":1701352800,"showTime":"21:55","eventType":"","eventId":"","length":300,"column_url":"","columnBackvideourl":"","top":""},{"title":"晚间新闻","startTime":1701352800,"endTime":1701354915,"showTime":"22:00","eventType":"","eventId":"","length":2115,"column_url":"https://tv.cctv.com/lm/wjxw/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/wjxw/index.shtml","top":""},{"title":"等着我-2023-26","startTime":1701354915,"endTime":1701357975,"showTime":"22:35","eventType":"","eventId":"","length":3060,"column_url":"https://tv.cctv.com/lm/dzw/index.shtml","columnBackvideourl":"https://tv.cctv.com/lm/dzw/videoset/","top":""},{"title":"寻宝-文脉春秋宣传片(3分钟)","startTime":1701357975,"endTime":1701358215,"showTime":"23:26","eventType":"","eventId":"","length":240,"column_url":"","columnBackvideourl":"","top":""},{"title":"非遗里的中国-4","startTime":1701358215,"endTime":1701359940,"showTime":"23:30","eventType":"","eventId":"","length":1725,"column_url":"","columnBackvideourl":"","top":""}]}}} \ No newline at end of file diff --git a/sites/tv.cctv.com/readme.md b/sites/tv.cctv.com/readme.md new file mode 100644 index 00000000..400c3495 --- /dev/null +++ b/sites/tv.cctv.com/readme.md @@ -0,0 +1,15 @@ +# tv.cctv.com + +https://tv.cctv.com/epg/index.shtml + +### Download the guide + +```sh +npm run grab -- --site=tv.cctv.com +``` + +### Test + +```sh +npm test -- tv.cctv.com +``` diff --git a/sites/tv.cctv.com/tv.cctv.com.config.js b/sites/tv.cctv.com/tv.cctv.com.config.js index ad803161..12cf7335 100644 --- a/sites/tv.cctv.com/tv.cctv.com.config.js +++ b/sites/tv.cctv.com/tv.cctv.com.config.js @@ -36,6 +36,7 @@ function parseStart(item) { function parseItems(content, channel) { const data = JSON.parse(content) + if (!data || !data.data) return [] return data.data[channel.site_id].list || [] } diff --git a/sites/tv.cctv.com/tv.cctv.com.test.js b/sites/tv.cctv.com/tv.cctv.com.test.js new file mode 100644 index 00000000..0189f648 --- /dev/null +++ b/sites/tv.cctv.com/tv.cctv.com.test.js @@ -0,0 +1,51 @@ +const { parser, url } = require('./tv.cctv.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 date = dayjs.utc('2023-11-30', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'cctv1', + xmltv_id: 'CCTV1.cn' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://api.cntv.cn/epg/getEpgInfoByChannelNew?serviceId=tvcctv&c=cctv1&d=20231130' + ) +}) + +it('can parse response', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json')) + const results = parser({ channel, content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results.length).toBe(37) + + expect(results[0]).toMatchObject({ + start: '2023-11-29T17:13:00.000Z', + stop: '2023-11-29T17:41:15.000Z', + title: '今日说法-2023-302' + }) + + expect(results[36]).toMatchObject({ + start: '2023-11-30T15:30:15.000Z', + stop: '2023-11-30T15:59:00.000Z', + title: '非遗里的中国-4' + }) +}) + +it('can handle empty guide', () => { + const results = parser({ + channel, + content: '{"errcode":"1001","msg":"params error"}' + }) + expect(results.length).toBe(0) +})