fix: if download failed, continue with error log
This commit is contained in:
parent
c41be73e3a
commit
56ee05c297
17
index.js
Normal file → Executable file
17
index.js
Normal file → Executable file
|
@ -10,6 +10,7 @@ const leven = require('leven');
|
|||
const { URL, URLSearchParams } = require('url');
|
||||
const fetch = require('node-fetch');
|
||||
const m3u = require('m3u');
|
||||
const promisepipe = require('promisepipe');
|
||||
require('dotenv').config();
|
||||
|
||||
|
||||
|
@ -103,12 +104,18 @@ async function main(playlistUrl){
|
|||
}
|
||||
bestMatch.path = `${bestMatch.artist} - ${bestMatch.title}.mp3`;
|
||||
debug('bestMatch=%O', bestMatch);
|
||||
await fs.access(bestMatch.path).catch(async () => { // TODO find a proper way to not re-download, lower/uppercase problems
|
||||
await fetch(bestMatch.url).then(res => {
|
||||
res.body.pipe(createWriteStream(bestMatch.path));
|
||||
try {
|
||||
await fs.access(bestMatch.path).catch(async () => { // TODO find a proper way to not re-download, lower/uppercase problems
|
||||
await fetch(bestMatch.url).then(async res => {
|
||||
await promisepipe(res.body, createWriteStream(bestMatch.path));
|
||||
});
|
||||
debug('Done downloading');
|
||||
});
|
||||
debug('Done downloading');
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Download failed for ', bestMatch);
|
||||
console.error(err);
|
||||
return null;
|
||||
}
|
||||
return bestMatch;
|
||||
}, {concurrency: 1});
|
||||
|
||||
|
|
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -164,6 +164,11 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"promisepipe": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/promisepipe/-/promisepipe-3.0.0.tgz",
|
||||
"integrity": "sha512-V6TbZDJ/ZswevgkDNpGt/YqNCiZP9ASfgU+p83uJE6NrGtvSGoOcHLiDCqkMs2+yg7F5qHdLV8d0aS8O26G/KA=="
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
"leven": "^3.1.0",
|
||||
"lodash": "^4.17.15",
|
||||
"m3u": "0.0.2",
|
||||
"node-fetch": "^2.6.0"
|
||||
"node-fetch": "^2.6.0",
|
||||
"promisepipe": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user