import { HttpsProxyAgent } from "https-proxy-agent";
|
import axios from "axios";
|
/* ----------axios代理------------ */
|
const httpsAgent = new HttpsProxyAgent(`http://127.0.0.1:10809`);
|
const myAxios = axios.create({
|
proxy: false,
|
httpsAgent,
|
});
|
// fs.mkdirSync('nofiction-torrents');
|
const urls = [];
|
for (let i = 1373; i < 4265; i++) {
|
const url = `https://libgen.rs/repository_torrent/r_${i ? i : ''}000.torrent`;
|
urls.push(url);
|
let retry = true;
|
let retryCnt = 0;
|
while (retry) {
|
await myAxios.get(url, { responseType: 'arraybuffer' }).then((resp) => {
|
const buffer = Buffer.from(resp.data, 'binary');
|
const filename = `nofiction-torrents/r_${i ? i : ''}000.torrent`;
|
fs.writeFileSync(filename, buffer);
|
retry = false;
|
}).catch((err) => {
|
retryCnt++;
|
if (retryCnt > 3) retry = false;
|
});
|
}
|
}
|
fs.writeFileSync('libgen-nofiction-urls.txt', urls.join('\n'));
|