From 0e921f0d7ad3a79b22daafcc7ae76c19e9b1b894 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sat, 11 Jan 2025 22:00:31 +0300 Subject: [PATCH] Create gigatv.3bbtv.co.th.config.js --- .../gigatv.3bbtv.co.th.config.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 sites/gigatv.3bbtv.co.th/gigatv.3bbtv.co.th.config.js diff --git a/sites/gigatv.3bbtv.co.th/gigatv.3bbtv.co.th.config.js b/sites/gigatv.3bbtv.co.th/gigatv.3bbtv.co.th.config.js new file mode 100644 index 00000000..61405de0 --- /dev/null +++ b/sites/gigatv.3bbtv.co.th/gigatv.3bbtv.co.th.config.js @@ -0,0 +1,65 @@ +const axios = require('axios') +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: 'gigatv.3bbtv.co.th', + days: 1, + url({ channel }) { + return `https://gigatv.3bbtv.co.th/wp-content/themes/changwattana/epg/${channel.site_id}.json` + }, + parser: function ({ content, date }) { + let programs = [] + const items = parseItems(content, date) + items.forEach(item => { + programs.push({ + title: item.programName, + start: parseTime(item.startTime), + stop: parseTime(item.endTime) + }) + }) + + return programs + }, + async channels() { + const data = await axios + .get('https://gigatv.3bbtv.co.th/wp-content/themes/changwattana/epg/channel.json') + .then(r => r.data) + .catch(console.log) + + const channels = [] + data.forEach(group => { + group.channel_list.forEach(channel => { + channels.push({ + lang: 'th', + site_id: channel.channel_id, + name: channel.channel_name + }) + }) + }) + + return channels + } +} + +function parseTime(string) { + return dayjs.tz(string, 'YYYY-MM-DD HH:mm:ss', 'Asia/Bangkok') +} + +function parseItems(content, date) { + try { + let data = JSON.parse(content) + if (!Array.isArray(data)) return [] + data = data.filter(p => date.isSame(parseTime(p.startTime), 'day')) + + return data + } catch { + return [] + } +}