liyugang
3 天以前 8c24730e9a52dc2c8933e8d41d2f9651de48a231
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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'));