improve firstmedia

This commit is contained in:
ta 2023-06-15 17:05:09 +07:00
parent 66360221ff
commit 751fb1e7a5
2 changed files with 8 additions and 6 deletions

View file

@ -1,14 +1,16 @@
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const timezone = require("dayjs/plugin/timezone"); const timezone = require("dayjs/plugin/timezone");
const utc = require('dayjs/plugin/utc');
dayjs.extend(timezone); dayjs.extend(timezone);
dayjs.extend(utc);
module.exports = { module.exports = {
site: "firstmedia.com", site: "firstmedia.com",
days: 2, days: 1,
url: function ({ channel, date }) { url: function ({ channel, date }) {
return `https://www.firstmedia.com/ajax/schedule?date=${ return `https://www.firstmedia.com/ajax/schedule?date=${date.format("DD/MM/YYYY")
date.format("DD/MM/YYYY") }&channel=${channel.site_id}&start_time=1&end_time=24&need_channels=0`;
}&channel=${channel.site_id}&start_time=1&end_time=24&need_channels=0`;
}, },
parser: function ({ content, channel }) { parser: function ({ content, channel }) {
if (!content || !channel) return []; if (!content || !channel) return [];
@ -29,7 +31,7 @@ module.exports = {
}; };
function parseItems(content, channel) { function parseItems(content, channel) {
return JSON.parse(content).entries[channel]; return JSON.parse(content.trim()).entries[channel];
} }
function parseTitle(item) { function parseTitle(item) {

View file

@ -19,7 +19,7 @@ it('can parse response', () => {
start: '2023-06-13T03:55:00.000Z', start: '2023-06-13T03:55:00.000Z',
stop: '2023-06-13T04:30:00.000Z', stop: '2023-06-13T04:30:00.000Z',
title: 'China Tonight', title: 'China Tonight',
description: 'China is a superpower that dominates global news but it\'s also home to 1.4 billion stories. Sam Yang is back for a new season, hearing from the people who make this extraordinary nation what it is today.' description: 'China is a superpower that dominates global news but it\'s also home to 1.4 billion stories. Sam Yang is back for a new season, hearing from the people who make this extraordinary nation what it is today.'
} }
]) ])
}) })