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 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, E as EPGGrabber, g as getUTCDate, a as generateXMLTV } from './index-Bcnk0U8G.js';
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 'xml-js';
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
- class ProxyParser {
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 Storage.loadJs(options.config);
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 = ProxyParser.parse(options.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 channel list...");
106
- const channelList = await grabber.loadChannels();
81
+ logger.info("Loading channels...");
82
+ const channels = await grabber.loadChannels();
107
83
  const template = new Template(configObject.output);
108
- const groups = channelList.getGroups({ template });
109
- if (channelList.getChannels().isEmpty()) {
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 channels = new Collection(group);
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 = channels.count() * days;
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
- channels.forEach((channel) => {
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({ channel, date });
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(channels.all(), programs.all(), utcDate);
152
- const channelSample = channels.sample();
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 });