Skip to content

Commit

Permalink
Merge pull request #21 from Chaphasilor/dev
Browse files Browse the repository at this point in the history
Fix parsing errors and crashes
  • Loading branch information
Chaphasilor authored Oct 17, 2021
2 parents 255fab8 + fa1ca09 commit dc9fa29
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dist
# ignore for now
test.js

# local development folders
# local development folders & files
ODD
Scans/
out.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ indexer.scanUrl(url)
| Wrapper Version | Supported ODD Versions (up to) | Included Version |
| --- | --- | --- |
| **6.0.0** | **2.1.0.0** | **2.1.0.0** |
| **6.1.0** | **2.1.0.0** | **2.1.0.0** |
| 5.1.0 | 2.0.0.6 | 2.0.0.3 |
| 5.0.0 | 2.0.0.2 | 2.0.0.0 |
| 4.0.3 | 1.9.6.1 | 1.9.6.1 |
Expand Down
11 changes: 9 additions & 2 deletions open-directory-downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ module.exports.OpenDirectoryDownloader = class OpenDirectoryDownloader {

// console.log(`finalResults:`, finalResults);

const redditOutputRegExp = /Saved URL list.*\r\nHttp status codes\r\n(?:.|\r\n)*?(^\|\*\*(?:.|\r\n)*?)\r\n\^\(Created by.*?\)\r\n\r\n/m
const redditOutputRegExp = options.performSpeedtest ?
/Finished speedtest.*\r\nHttp status codes\r\n(?:.|\r\n)*?(^\|\*\*(?:.|\r\n)*?)\r\n\^\(Created by.*?\)\r\n\r\n/m :
/Saved URL list.*\r\nHttp status codes\r\n(?:.|\r\n)*?(^\|\*\*(?:.|\r\n)*?)\r\n\^\(Created by.*?\)\r\n\r\n/m
const redditOutputEndRegExp = /\^\(Created by \[KoalaBear84\'s OpenDirectory Indexer v.*?\]\(https:\/\/github\.com\/KoalaBear84\/OpenDirectoryDownloader\/\)\)/;
const credits = transcriber.output.match(redditOutputEndRegExp)[0]

let redditOutput = finalResults.match(redditOutputRegExp)[1]
if (!redditOutputRegExp.test(finalResults)) {
return reject([new ODDWrapperError(`Failed to parse ODD output!`)])
}
let redditOutput = `|**Url` + finalResults.match(redditOutputRegExp)[1]
.split('|**Url').filter(Boolean).slice(-1)[0] // make sure there's only a single table

let missingFileSizes = redditOutput.includes(`**Total:** n/a`)

Expand Down Expand Up @@ -321,6 +327,7 @@ class OutputTranscriber extends EventEmitter {
this.stdinStream = stdin

this.stdinStream.setEncoding(`utf8`)
this.stdinStream.on('error', (err) => {}) // handle errors to prevent crashing
this.stdinStreamIntervalId = setInterval(() => {
this.stdinStream.write(`s`); // input `S` to trigger ODD stats output
}, this.options.statsInterval * 1000);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-directory-downloader",
"version": "6.0.0",
"version": "6.1.0",
"description": "A NodeJS wrapper around KoalaBear84/OpenDirectoryDownloader",
"main": "open-directory-downloader.js",
"scripts": {
Expand Down

0 comments on commit dc9fa29

Please sign in to comment.