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();
|