epg-grabber 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +11 -2
- package/src/index.js +22 -0
- package/tests/__data__/output/guide.xml +1 -1
- package/tests/index.test.js +56 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -101,10 +101,19 @@ export type GrabCallbackData = {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export declare class EPGGrabber {
|
|
104
|
-
constructor(config:
|
|
104
|
+
constructor(config: SiteConfig)
|
|
105
105
|
grab(
|
|
106
106
|
channel: Channel,
|
|
107
107
|
date: string | dayjs.Dayjs,
|
|
108
|
-
cb: (data: GrabCallbackData, err: Error) => void
|
|
108
|
+
cb: (data: GrabCallbackData, err: Error | null) => void
|
|
109
|
+
): Promise<Program[]>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare class EPGGrabberMock {
|
|
113
|
+
constructor(config: SiteConfig)
|
|
114
|
+
grab(
|
|
115
|
+
channel: Channel,
|
|
116
|
+
date: string | dayjs.Dayjs,
|
|
117
|
+
cb: (data: GrabCallbackData, err: Error | null) => void
|
|
109
118
|
): Promise<Program[]>
|
|
110
119
|
}
|
package/src/index.js
CHANGED
|
@@ -53,4 +53,26 @@ class EPGGrabber {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
class EPGGrabberMock {
|
|
57
|
+
constructor(config) {
|
|
58
|
+
this.config = config
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async grab(channel, date, cb) {
|
|
62
|
+
let _date = getUTCDate(date)
|
|
63
|
+
let _programs = await this.config.parser({ channel, date: _date })
|
|
64
|
+
let programs = _programs.map(data => new Program(data, channel))
|
|
65
|
+
|
|
66
|
+
if (this.config.request?.timeout !== undefined && this.config.request.timeout < 1) {
|
|
67
|
+
cb({ programs: [], date: _date, channel }, new Error('Connection timeout'))
|
|
68
|
+
return []
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
cb({ programs, date: _date, channel }, null)
|
|
72
|
+
|
|
73
|
+
return programs
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
56
77
|
module.exports.EPGGrabber = EPGGrabber
|
|
78
|
+
module.exports.EPGGrabberMock = EPGGrabberMock
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8" ?><tv date="
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?><tv date="20230930">
|
|
2
2
|
<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>
|
|
3
3
|
<channel id="2TV.com"><display-name>2 TV</display-name><icon src="http://example.com/logos/1TV.png?x=шеллы&sid=777"/><url>https://example.com</url></channel>
|
|
4
4
|
<channel id="3TV.com"><display-name>3 TV</display-name><icon src="http://example.com/logos/1TV.png?x=шеллы&sid=777"/><url>https://example2.com</url></channel>
|
package/tests/index.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jest-environment node
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { EPGGrabber, Channel } from '../src/index'
|
|
5
|
+
import { EPGGrabber, EPGGrabberMock, Channel } from '../src/index'
|
|
6
6
|
import axios from 'axios'
|
|
7
7
|
|
|
8
8
|
jest.mock('axios')
|
|
@@ -66,3 +66,58 @@ it('can grab single channel programs', done => {
|
|
|
66
66
|
done()
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
|
+
|
|
70
|
+
it('can mock epg grabber', done => {
|
|
71
|
+
const config = {
|
|
72
|
+
site: 'example.com',
|
|
73
|
+
url: 'http://example.com/20210319/1tv.json',
|
|
74
|
+
parser: ({ channel, date }) => [
|
|
75
|
+
{ title: `Test (${channel.name})`, start: '2021-03-19T04:30:00.000Z' }
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
const channel = new Channel({
|
|
79
|
+
site: 'example.com',
|
|
80
|
+
site_id: '1',
|
|
81
|
+
xmltv_id: '1TV.fr',
|
|
82
|
+
lang: 'fr',
|
|
83
|
+
name: '1TV'
|
|
84
|
+
})
|
|
85
|
+
const grabber = new EPGGrabberMock(config)
|
|
86
|
+
grabber
|
|
87
|
+
.grab(channel, '2022-01-01', (data, err) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
done()
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.then(programs => {
|
|
93
|
+
expect(programs.length).toBe(1)
|
|
94
|
+
expect(programs).toEqual([
|
|
95
|
+
{
|
|
96
|
+
site: 'example.com',
|
|
97
|
+
channel: '1TV.fr',
|
|
98
|
+
titles: [{ value: 'Test (1TV)', lang: 'fr' }],
|
|
99
|
+
sub_titles: [],
|
|
100
|
+
descriptions: [],
|
|
101
|
+
icon: { src: '' },
|
|
102
|
+
episodeNumbers: [],
|
|
103
|
+
date: null,
|
|
104
|
+
start: 1616128200000,
|
|
105
|
+
stop: null,
|
|
106
|
+
urls: [],
|
|
107
|
+
ratings: [],
|
|
108
|
+
categories: [],
|
|
109
|
+
directors: [],
|
|
110
|
+
actors: [],
|
|
111
|
+
writers: [],
|
|
112
|
+
adapters: [],
|
|
113
|
+
producers: [],
|
|
114
|
+
composers: [],
|
|
115
|
+
editors: [],
|
|
116
|
+
presenters: [],
|
|
117
|
+
commentators: [],
|
|
118
|
+
guests: []
|
|
119
|
+
}
|
|
120
|
+
])
|
|
121
|
+
done()
|
|
122
|
+
})
|
|
123
|
+
})
|