Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ file [tools/analyzer-config.json](./tools/analyzer-config.json).
| `cache` | Whether or not to test again a provider if it is already listed either in `succeeded.json` or `failed.json` upon subsequent relaunching of the script. | ✓ | `false` |
| `groupsToTest` | Number of IPTV groups to fetch channels from.<br/>The group(s) are selected randomly among all IPTV genres of the provider. | &#x2713; | `1` |
| `channelsToTest` | Number of IPTV channels to check the liveness.<br/>The channel(s) are selected randomly among all channels from the result of selected genres (see `groupsToTest`). | &#x2713; | `1` |
| `retestSuccess` | Whether to test again the `success.json` content (if file exists). Only applicable if `cache` is `true`. | &#x2713; | `false` |
| `retestFailed` | Whether to test again the `failed.json` content (if file exists). Only applicable if `cache` is `true`. | &#x2713; | `false` |
| `threadsCount` | Number of providers to analyze in parallel. | &#x2713; | `10` |
| `streamTester` | Stream tester mode. One of value `http` or `ffmpeg`. | &#x2713; | `ffmpeg` |

Expand Down Expand Up @@ -253,7 +255,6 @@ The criteria can be configured through config file [m3u-tester-config.json](tool
| `minSuccess` | Minimal number of failures before marking a M3U file as succeeded. Deactivate testing upon success with value -1. | &#x2713; | `1` |
| `renameOnFailure` | Whether to rename a failed M3U by prefixing with 'renamePrefix'. | &#x2713; | `false` |
| `renamePrefix` | Prefix to rename a failed M3U (only if 'renameOnFailure' is set to true). | &#x2713; | `UNHEALTHY_` |
| `retestSuccess` | Whether to test again the success.json content (if file exists). | &#x2713; | `false` |
| `threadsCount` | Number of M3U to process in parallel. | &#x2713; | `1` |
| `streamTester` | Stream tester mode. One of value `http` or `ffmpeg`. | &#x2713; | `ffmpeg` |

Expand Down
39 changes: 33 additions & 6 deletions tools/iptv-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface AnalyzerConfig extends BaseConfig {
groupsToTest?: number;
channelsToTest?: number;
retestSuccess?: boolean;
retestFailed?: boolean;
threadsCount?: number;
}

Expand Down Expand Up @@ -111,8 +112,10 @@ async function initFiles(): Promise<void> {
if (!config.retestSuccess && fs.existsSync(SUCCEEDED_FILE)) {
succeeded.push(...JSON.parse(fs.readFileSync(SUCCEEDED_FILE, READ_OPTIONS)) as UrlConfig[]);
}
if (fs.existsSync(FAILED_FILE)) {
if (!config.retestFailed && fs.existsSync(FAILED_FILE)) {
readFileAsync(failed, FAILED_FILE, res, rej);
} else {
res();
}
} else {
// Clear files
Expand Down Expand Up @@ -159,6 +162,9 @@ function getConfig(): Readonly<AnalyzerConfig> {
if (config.retestSuccess === undefined) {
config.retestSuccess = false;
}
if (config.retestFailed === undefined) {
config.retestFailed = false;
}
if (config.threadsCount === undefined) {
// Number of threads for analyze process
config.threadsCount = 10;
Expand All @@ -176,6 +182,9 @@ function getConfig(): Readonly<AnalyzerConfig> {
if (typeof config.retestSuccess !== "boolean") {
config.retestSuccess = config.retestSuccess as any === "true";
}
if (typeof config.retestFailed !== "boolean") {
config.retestFailed = config.retestFailed as any === "true";
}

return config;
}
Expand Down Expand Up @@ -209,10 +218,6 @@ function fetchUrl(url: string): Observable<FetchContent> {
/** Load sources urls */
function fetchAllUrls(urls: string[]): void {

if (config.retestSuccess) {
urls.push(`file:///${SUCCEEDED_FILE}`);
}

const requests = urls
.filter(url => url.trim().length > 0)
.filter(url => !url.startsWith('#') && !url.startsWith(';'))
Expand Down Expand Up @@ -240,6 +245,29 @@ function fetchAllUrls(urls: string[]): void {

return urls;
}),
concatMap(urls => {
const failedToReplay: UrlAndMac[] = [];
return new Promise<void>((res, rej) => {
if (config.retestFailed) {
readFileAsync(failedToReplay, FAILED_FILE, res, rej);
} else {
res();
}
}).then(x => {
if (config.retestFailed) {
// Clear failed file
fs.writeFileSync(FAILED_FILE, JSON.stringify([], null, 2));
}
failedToReplay.forEach((value) => {
if (!urls.has(value.url)) {
urls.set(value.url, new Set());
}
urls.set(value.url, new Set([...urls.get(value.url)!, value.mac]));
});

return Promise.resolve(urls);
});
}),
concatMap(urls => {
const items: UrlAndMac[] = [];

Expand All @@ -256,7 +284,6 @@ function fetchAllUrls(urls: string[]): void {
// Clear success file
fs.writeFileSync(SUCCEEDED_FILE, JSON.stringify([], null, 2));
}

urls.forEach((macs, url) => {
macs.forEach(mac => {
const urlAndMac: UrlAndMac = {url, mac};
Expand Down
5 changes: 5 additions & 0 deletions tools/schemas/analyzer-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"description": "Whether to test again the success.json content (if file exists)",
"default": false
},
"retestFailed": {
"type": "boolean",
"description": "Whether to test again the failed.json content (if file exists)",
"default": false
},
"streamTester": {
"type": "string",
"description": "Stream tester mode",
Expand Down