diff --git a/.github/workflows/watchyour.tv.yml b/.github/workflows/watchyour.tv.yml new file mode 100644 index 00000000..2b2b5503 --- /dev/null +++ b/.github/workflows/watchyour.tv.yml @@ -0,0 +1,17 @@ +name: watchyour.tv +on: + schedule: + - cron: '0 3 * * *' + workflow_dispatch: + workflow_run: + workflows: [_trigger] + types: + - completed +jobs: + load: + uses: ./.github/workflows/_load.yml + with: + site: ${{github.workflow}} + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} diff --git a/sites/watchyour.tv/watchyour.tv.config.js b/sites/watchyour.tv/watchyour.tv.config.js new file mode 100644 index 00000000..6a0afc29 --- /dev/null +++ b/sites/watchyour.tv/watchyour.tv.config.js @@ -0,0 +1,54 @@ +const dayjs = require('dayjs') +const axios = require('axios') + +module.exports = { + site: 'watchyour.tv', + url: `https://www.watchyour.tv/guide.json`, + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + parser: function ({ content, date, channel }) { + let programs = [] + const items = parseItems(content, date, channel) + items.forEach(item => { + const start = parseStart(item) + const stop = start.add(parseInt(item.duration), 'm') + programs.push({ + title: item.name, + icon: item.icon, + category: item.category, + start, + stop + }) + }) + + return programs + }, + async channels() { + const data = await axios + .get(`https://www.watchyour.tv/guide.json`) + .then(r => r.data) + .catch(console.log) + + return data.map(item => ({ + site_id: item.id, + name: item.name + })) + } +} + +function parseStart(item) { + return dayjs.unix(parseInt(item.tms)) +} + +function parseItems(content, date, channel) { + if (!content) return [] + const data = JSON.parse(content) + if (!Array.isArray(data)) return [] + const channelData = data.find(i => i.id == channel.site_id) + if (!channelData || !Array.isArray(channelData.shows)) return [] + + return channelData.shows.filter(i => i.start_day === date.format('YYYY-MM-DD')) +} diff --git a/sites/watchyour.tv/watchyour.tv.test.js b/sites/watchyour.tv/watchyour.tv.test.js new file mode 100644 index 00000000..c699b0ef --- /dev/null +++ b/sites/watchyour.tv/watchyour.tv.test.js @@ -0,0 +1,47 @@ +// npx epg-grabber --config=sites/watchyour.tv/watchyour.tv.config.js --channels=sites/watchyour.tv/watchyour.tv_us.channels.xml --output=guide.xml --days=2 +// npm run channels:parse -- --config=./sites/watchyour.tv/watchyour.tv.config.js --output=./sites/watchyour.tv/watchyour.tv_us.channels.xml + +const { parser, url } = require('./watchyour.tv.config.js') +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('2022-10-03', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '735', + xmltv_id: 'TVSClassicSports.us' +} + +it('can generate valid url', () => { + expect(url).toBe('https://www.watchyour.tv/guide.json') +}) + +it('can parse response', () => { + const content = `[{"name":"TVS Classic Sports","icon":"https://www.watchyour.tv/epg/channellogos/tvs-classic-sports.png","language":"English","id":"735","shows":[{"name":"1979 WVU vs Penn State","category":"Sports","start_day":"2022-10-03","start":"04:00:00","end_day":"2022-10-03","end":"06:00:45","duration":"121","url":"http://rpn1.bozztv.com/36bay2/gusa-tvs/index-1664769600-7245.m3u8?token=f7410a9414f61579dced17ac1bbdb971","icon":"https://example.com/image.png","timezone":"+0000","tms":"1664769600"},{"name":"1958 NCAA University of Kentucky vs Seattle U","category":"Sports","start_day":"2022-10-04","start":"00:58:50","end_day":"2022-10-04","end":"01:44:11","duration":"46","url":"http://rpn1.bozztv.com/36bay2/gusa-tvs/index.m3u8?token=93e7b201f544c87296076b73f9d880ae","icon":"","timezone":"+0000","tms":"1664845130"}]}]` + const result = parser({ content, date, channel }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-10-03T04:00:00.000Z', + stop: '2022-10-03T06:01:00.000Z', + title: '1979 WVU vs Penn State', + icon: 'https://example.com/image.png', + category: 'Sports' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: ``, + date, + channel + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/watchyour.tv/watchyour.tv_us.channels.xml b/sites/watchyour.tv/watchyour.tv_us.channels.xml new file mode 100644 index 00000000..0f8d3f5c --- /dev/null +++ b/sites/watchyour.tv/watchyour.tv_us.channels.xml @@ -0,0 +1,44 @@ + + + + TVS Boxing Network + TVS Cipher Network + TVS Classic Movies + TVS Classic Sports + TVS Comedy + TVS Drive In Movie + TVS Film Noir Network + TVS Front Page Detective + TVS Hi Tops + TVS Hollywood History + TVS Horror + TVS Main Street + TVS Nostalgia + TVS Nostalgia Movie Network + TVS Pinball Network + TVS Quiz Show Network + TVS Select Network + TVS Silo Discount Network + TVS Tally Ho + TVS Tavern TV + TVS Today Home Entertainment Network + TVS Turbo Network + TVS Western Movie + TVS Women's Sports Network + + + + + + + + + + + + + + + + +