epg-grabber 0.42.0 → 0.43.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/dist/cli.js +27 -41
- package/dist/{index-Bcnk0U8G.js → index-_okTrZbD.js} +266 -269
- package/dist/index.d.ts +376 -238
- package/dist/index.js +6 -5
- package/package.json +1 -1
- package/src/cli.ts +27 -16
- package/src/core/client.ts +3 -4
- package/src/core/siteConfig.ts +67 -39
- package/src/{utils.ts → core/utils.ts} +45 -17
- package/src/index.ts +141 -34
- package/src/models/channel.ts +2 -2
- package/src/models/program.ts +65 -65
- package/src/types/channel.d.ts +1 -1
- package/src/types/client.d.ts +2 -2
- package/src/types/grab.d.ts +10 -0
- package/src/types/index.d.ts +5 -10
- package/src/types/program.d.ts +58 -58
- package/src/types/siteConfig.d.ts +137 -121
- package/src/types/utils.d.ts +14 -0
- package/tests/{models → core}/siteConfig.test.ts +4 -6
- package/tests/core/utils.test.ts +34 -0
- package/tests/index.test.ts +512 -103
- package/tests/models/program.test.ts +4 -4
- package/tsconfig.json +1 -1
- package/src/core/channelList.ts +0 -60
- package/src/core/channelsParser.ts +0 -30
- package/src/core/programsParser.ts +0 -27
- package/src/core/proxyParser.ts +0 -31
- package/src/core/storage.ts +0 -9
- package/src/core/xmltvGenerator.ts +0 -29
- package/src/types/channelList.d.ts +0 -11
- package/tests/core/channelsParser.test.ts +0 -102
- package/tests/core/programsParser.test.ts +0 -48
- package/tests/core/proxyParser.test.ts +0 -12
- package/tests/core/xmltvGenerator.test.ts +0 -194
- package/tests/utils.test.ts +0 -14
package/dist/cli.js
CHANGED
|
@@ -1,48 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as name, v as version, d as description, p as parseNumber, L as Logger,
|
|
2
|
+
import { n as name, v as version, d as description, p as parseNumber, L as Logger, l as loadJs, a as parseProxy, E as EPGGrabber, g as getUTCDate } from './index-_okTrZbD.js';
|
|
3
3
|
import { Template, Collection } from '@freearhey/core';
|
|
4
4
|
import { Command, Option } from 'commander';
|
|
5
5
|
import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
6
|
-
import { URL } from 'node:url';
|
|
7
|
-
import path from 'node:path';
|
|
8
6
|
import { TaskQueue } from 'cwait';
|
|
9
7
|
import Promise$1 from 'bluebird';
|
|
8
|
+
import path from 'node:path';
|
|
10
9
|
import fs from 'fs-extra';
|
|
11
10
|
import pako from 'pako';
|
|
12
11
|
import _ from 'lodash';
|
|
13
12
|
import 'dayjs';
|
|
14
13
|
import 'dayjs/plugin/utc.js';
|
|
15
|
-
import '
|
|
14
|
+
import 'node:url';
|
|
16
15
|
import 'glob';
|
|
17
16
|
import 'axios';
|
|
18
17
|
import 'curl-generator';
|
|
19
|
-
import 'axios-cache-interceptor';
|
|
20
18
|
import 'winston';
|
|
21
19
|
import 'path';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
static parse(proxy) {
|
|
25
|
-
const parsed = new URL(proxy);
|
|
26
|
-
const result = {
|
|
27
|
-
protocol: parsed.protocol.replace(":", "") || null,
|
|
28
|
-
host: parsed.hostname,
|
|
29
|
-
port: parsed.port ? parseInt(parsed.port) : null
|
|
30
|
-
};
|
|
31
|
-
if (parsed.username || parsed.password) {
|
|
32
|
-
result.auth = {};
|
|
33
|
-
if (parsed.username) result.auth.username = parsed.username;
|
|
34
|
-
if (parsed.password) result.auth.password = parsed.password;
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class Storage {
|
|
41
|
-
static async loadJs(filepath) {
|
|
42
|
-
const absPath = path.resolve(filepath);
|
|
43
|
-
return (await import(absPath)).default;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
20
|
+
import 'axios-cache-interceptor';
|
|
21
|
+
import 'xml-js';
|
|
46
22
|
|
|
47
23
|
const program = new Command();
|
|
48
24
|
program.name(name).version(version, "-v, --version").description(description).addOption(
|
|
@@ -73,7 +49,7 @@ async function main() {
|
|
|
73
49
|
logger.info("Starting...");
|
|
74
50
|
logger.debug(`Options: ${JSON.stringify(options, null, 2)}`);
|
|
75
51
|
logger.info(`Loading '${options.config}'...`);
|
|
76
|
-
let configObject = await
|
|
52
|
+
let configObject = await loadJs(options.config);
|
|
77
53
|
configObject = _.merge(configObject, {
|
|
78
54
|
filepath: path.resolve(options.config),
|
|
79
55
|
channels: typeof options.channels === "string" ? path.resolve(options.channels) : void 0,
|
|
@@ -90,7 +66,7 @@ async function main() {
|
|
|
90
66
|
if (configObject.request.timeout === void 0) configObject.request.timeout = options.timeout;
|
|
91
67
|
if (options.cacheTtl !== void 0) configObject.request.cache = { ttl: options.cacheTtl };
|
|
92
68
|
if (options.proxy !== void 0) {
|
|
93
|
-
const proxy =
|
|
69
|
+
const proxy = parseProxy(options.proxy);
|
|
94
70
|
if (proxy.protocol && ["socks", "socks5", "socks5h", "socks4", "socks4a"].includes(String(proxy.protocol))) {
|
|
95
71
|
const socksProxyAgent = new SocksProxyAgent(options.proxy);
|
|
96
72
|
configObject.request = {
|
|
@@ -102,28 +78,38 @@ async function main() {
|
|
|
102
78
|
}
|
|
103
79
|
}
|
|
104
80
|
const grabber = new EPGGrabber(configObject, { logger });
|
|
105
|
-
logger.info("Loading
|
|
106
|
-
const
|
|
81
|
+
logger.info("Loading channels...");
|
|
82
|
+
const channels = await grabber.loadChannels();
|
|
107
83
|
const template = new Template(configObject.output);
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
84
|
+
const variables = template.variables();
|
|
85
|
+
if (!channels.length) {
|
|
110
86
|
logger.info("No channels found");
|
|
111
87
|
logger.info("Exit");
|
|
112
88
|
return;
|
|
113
89
|
}
|
|
90
|
+
const groups = new Collection(channels).groupBy((channel) => {
|
|
91
|
+
let groupId = "";
|
|
92
|
+
for (const key in channel) {
|
|
93
|
+
if (variables.includes(key)) {
|
|
94
|
+
const obj = channel.toObject();
|
|
95
|
+
groupId += obj[key];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return groupId;
|
|
99
|
+
});
|
|
114
100
|
logger.info("Processing...");
|
|
115
101
|
for (let groupId of groups.keys()) {
|
|
116
102
|
const group = groups.get(groupId);
|
|
117
|
-
const
|
|
103
|
+
const groupChannels = new Collection(group);
|
|
118
104
|
let programs = new Collection();
|
|
119
105
|
let index = 1;
|
|
120
106
|
let days = configObject.days;
|
|
121
107
|
const maxConnections = configObject.maxConnections;
|
|
122
|
-
const total =
|
|
108
|
+
const total = groupChannels.count() * days;
|
|
123
109
|
const utcDate = getUTCDate(process.env.CURR_DATE);
|
|
124
110
|
const dates = Array.from({ length: days }, (_2, i) => utcDate.add(i, "d"));
|
|
125
111
|
let queue = new Collection();
|
|
126
|
-
|
|
112
|
+
groupChannels.forEach((channel) => {
|
|
127
113
|
for (let date of dates) {
|
|
128
114
|
queue.add({ channel, date });
|
|
129
115
|
}
|
|
@@ -133,7 +119,7 @@ async function main() {
|
|
|
133
119
|
taskQueue.wrap(async (queueItem) => {
|
|
134
120
|
const { channel, date } = queueItem;
|
|
135
121
|
if (!channel.logo && configObject.logo) {
|
|
136
|
-
channel.logo = await grabber.loadLogo(
|
|
122
|
+
channel.logo = await grabber.loadLogo(channel, date);
|
|
137
123
|
}
|
|
138
124
|
const _programs = await grabber.grab(channel, date, (context, error) => {
|
|
139
125
|
const { channel: channel2, date: date2, programs: programs2 } = context;
|
|
@@ -148,8 +134,8 @@ async function main() {
|
|
|
148
134
|
);
|
|
149
135
|
await Promise$1.all(requests.all());
|
|
150
136
|
programs = programs.uniqBy((program2) => program2.start + program2.channel);
|
|
151
|
-
const xml = generateXMLTV(
|
|
152
|
-
const channelSample =
|
|
137
|
+
const xml = EPGGrabber.generateXMLTV(groupChannels.all(), programs.all(), utcDate);
|
|
138
|
+
const channelSample = groupChannels.sample();
|
|
153
139
|
let outputPath = template.format(channelSample.toObject());
|
|
154
140
|
const outputDir = path.dirname(outputPath);
|
|
155
141
|
fs.mkdirSync(outputDir, { recursive: true });
|