Initial Commit
This commit is contained in:
1
sites/toonamiaftermath.com/__data__/content.json
Normal file
1
sites/toonamiaftermath.com/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
1
sites/toonamiaftermath.com/__data__/playlists.json
Normal file
1
sites/toonamiaftermath.com/__data__/playlists.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"_id":"635e6c0917f6824d95312bf7","scheduleName":"Toonami Aftermath EST","startDate":"2022-11-28T17:00:00.000Z","endDate":"2022-11-29T17:00:00.000Z"},{"_id":"635fbd8117f6824d953a216e","scheduleName":"Toonami Aftermath EST","startDate":"2022-11-29T17:00:00.000Z","endDate":"2022-11-30T17:00:00.000Z"},{"_id":"63610efab2ea42e7a913c18a","scheduleName":"Toonami Aftermath EST","startDate":"2022-11-30T17:00:00.000Z","endDate":"2022-12-01T17:00:00.000Z"},{"_id":"6362607ab2ea42e7a91ba353","scheduleName":"Toonami Aftermath EST","startDate":"2022-12-01T17:00:00.000Z","endDate":"2022-12-02T17:00:00.000Z"},{"_id":"6363b1f9b2ea42e7a9231e25","scheduleName":"Toonami Aftermath EST","startDate":"2022-12-02T17:00:00.000Z","endDate":"2022-12-03T11:00:00.000Z"},{"_id":"6365037ab2ea42e7a92b3415","scheduleName":"Toonami Aftermath EST","startDate":"2022-12-03T11:00:00.000Z","endDate":"2022-12-04T12:48:20.000Z"},{"_id":"636654fab2ea42e7a9339918","scheduleName":"Toonami Aftermath EST","startDate":"2022-12-04T11:00:00.000Z","endDate":"2022-12-05T16:27:37.000Z"}]
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="toonamiaftermath.com">
|
||||
<channels>
|
||||
<channel lang="en" xmltv_id="ToonamiAftermathEast.us" site_id="Toonami Aftermath EST">Toonami Aftermath East</channel>
|
||||
</channels>
|
||||
</site>
|
||||
61
sites/toonamiaftermath.com/toonamiaftermath.com.config.js
Normal file
61
sites/toonamiaftermath.com/toonamiaftermath.com.config.js
Normal file
@@ -0,0 +1,61 @@
|
||||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
|
||||
|
||||
const dayjs = require('dayjs')
|
||||
const axios = require('axios')
|
||||
|
||||
const API_ENDPOINT = `https://api.toonamiaftermath.com`
|
||||
|
||||
module.exports = {
|
||||
site: 'toonamiaftermath.com',
|
||||
days: 3,
|
||||
async url({ channel, date }) {
|
||||
const playlists = await axios
|
||||
.get(
|
||||
`${API_ENDPOINT}/playlists?scheduleName=${channel.site_id}&startDate=${date
|
||||
.add(1, 'd')
|
||||
.toJSON()}&thisWeek=true&weekStartDay=monday`
|
||||
)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
const playlist = playlists.find(p => date.isSame(p.startDate, 'day'))
|
||||
|
||||
return `${API_ENDPOINT}/playlist?id=${playlist._id}&addInfo=true`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
sub_title: parseEpisode(item),
|
||||
icon: parseIcon(item),
|
||||
start: dayjs(item.startDate),
|
||||
stop: dayjs(item.endDate)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
if (!content) return []
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !data.playlist) return []
|
||||
|
||||
return data.playlist.blocks
|
||||
.reduce((acc, curr) => {
|
||||
acc = acc.concat(curr.mediaList)
|
||||
|
||||
return acc
|
||||
}, [])
|
||||
}
|
||||
|
||||
function parseEpisode(item) {
|
||||
return (item && item.info && item.info.episode) ? item.info.episode : null
|
||||
}
|
||||
|
||||
function parseIcon(item) {
|
||||
return (item && item.info && item.info.image) ? item.info.image : null
|
||||
}
|
||||
63
sites/toonamiaftermath.com/toonamiaftermath.com.test.js
Normal file
63
sites/toonamiaftermath.com/toonamiaftermath.com.test.js
Normal file
@@ -0,0 +1,63 @@
|
||||
// npx epg-grabber --config=sites/toonamiaftermath.com/toonamiaftermath.com.config.js --channels=sites/toonamiaftermath.com/toonamiaftermath.com.channels.xml --output=guide.xml --days=2
|
||||
|
||||
const { parser, url, request } = require('./toonamiaftermath.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const API_ENDPOINT = `https://api.toonamiaftermath.com`
|
||||
|
||||
const date = dayjs.utc('2022-11-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'Toonami Aftermath EST',
|
||||
xmltv_id: 'ToonamiAftermathEast.us'
|
||||
}
|
||||
|
||||
it('can generate valid url', async () => {
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
`${API_ENDPOINT}/playlists?scheduleName=Toonami Aftermath EST&startDate=2022-11-30T00:00:00.000Z&thisWeek=true&weekStartDay=monday`
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/playlists.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
const result = await url({ channel, date })
|
||||
|
||||
expect(result).toBe(`${API_ENDPOINT}/playlist?id=635fbd8117f6824d953a216e&addInfo=true`)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(62)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-29T17:00:30.231Z',
|
||||
stop: '2022-11-29T17:20:54.031Z',
|
||||
title: 'X-Men',
|
||||
sub_title: 'Reunion (Part 1)',
|
||||
icon: 'https://i.imgur.com/ZSZ0x1m.gif'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({ content: '', date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
Reference in New Issue
Block a user