lyg
2024-08-01 ce8cb9c851fa66c7c2902ceb57e369d3cecf1a28
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import xlsx from "node-xlsx";
import * as fs from 'fs';
import * as qbtApi from 'qbittorrent-api-v2';
const fileMap = {};
 
function loadFileMap() {
  const workSheets = xlsx.parse("libgen-撞库图书.xlsx");
  const sheet = workSheets[0];
  for (const row of sheet.data) {
    const [id, file] = row;
    const folderName = (Math.floor(parseInt(id) / 1000) * 1000).toFixed(0);
    if (!fileMap[folderName]) {
      fileMap[folderName] = {};
    }
    fileMap[folderName][file] = true;
  }
}
 
async function main() {
  loadFileMap();
  const qbt = await qbtApi.connect('http://localhost:8081', 'admin', 'adminadmin');
 
  const torrents = await qbt.torrents();
  for (const torrent of torrents) {
    if (torrent.state === 'pausedUP') { continue; }
    const contents = await qbt.files(torrent.hash);
    const torName = torrent.name;
    const files = fileMap[torName];
    if (!files) {
      continue;
    }
    const fileIds = [];
    for (const content of contents) {
      const contentName = content.name.split("/")[1];
      if (!files[contentName]) {
        fileIds.push(content.index);
      }
    }
    if (fileIds.length) {
      await qbt.setFilePriority(torrent.hash, fileIds.join('|'), "0");
    }
  }
}
 
main();