hytranslator / dist /torrent /itorrent.js
no1b4me's picture
Upload 61 files
762fa11 verified
import axios from "axios";
import * as cheerio from "cheerio";
export var ItorrentCategory;
(function (ItorrentCategory) {
ItorrentCategory[ItorrentCategory["Film"] = 3] = "Film";
ItorrentCategory[ItorrentCategory["Sorozat"] = 4] = "Sorozat";
})(ItorrentCategory || (ItorrentCategory = {}));
export var ItorrentQuality;
(function (ItorrentQuality) {
ItorrentQuality["SD"] = "sd";
ItorrentQuality["HD"] = "hd";
ItorrentQuality["CAM"] = "cam";
})(ItorrentQuality || (ItorrentQuality = {}));
export const searchItorrent = async (searchQuery, categories, qualities) => {
const torrents = [];
const quality = qualities.join(",");
await Promise.all(categories.map(async (category) => {
let page = 0;
while (page <= 5) {
try {
page++;
let torrentsOnPage = 0;
const link = `https://itorrent.ws/torrentek/category/${category}/title/${searchQuery}/qualities[]/${quality}/page/${page}/`;
const torrentsPage = await axios.get(link);
const $ = cheerio.load(torrentsPage.data);
await Promise.all([...$("tr.gradeX")].map(async (el) => {
torrentsOnPage++;
const tracker = "iTorrent";
const torrentAnchor = $(el).find("td.ellipse > a");
const torrentHref = torrentAnchor.attr("href");
const name = torrentAnchor.text().trim();
if (!torrentHref || !name)
return;
const category = parseCategory($(el).find("i.zqf").attr("title"));
const size = parseSize($(el).find("td:nth-child(5)").text().trim());
const seeds = Number($(el).find("td:nth-child(7)").text());
const peers = Number($(el).find("td:nth-child(8)").text());
const torrentPageLink = `https://itorrent.ws${torrentHref}`;
let torrent;
let magnet;
try {
const torrentPage = await axios.get(torrentPageLink);
const $ = cheerio.load(torrentPage.data);
const torrentFileHref = $("a.btn-primary.seed-warning").attr("href");
if (torrentFileHref)
torrent = `https://itorrent.ws${torrentFileHref}`;
magnet = $("a.btn-success.seed-warning").attr("href");
if (!torrent && !magnet)
return;
}
catch {
return;
}
torrents.push({
name,
tracker,
category,
size,
seeds,
peers,
torrent,
magnet,
});
}));
if (torrentsOnPage < 48)
break;
}
catch {
continue;
}
}
}));
return torrents;
};
const parseCategory = (category) => {
const categories = {
"Film/HU/CAM": "Movies/CAM/HU",
"Film/HU/SD": "Movies/SD/HU",
"Film/HU/HD": "Movies/HD/HU",
"Sorozat/HU/SD": "TV/SD/HU",
"Sorozat/HU/HD": "TV/HD/HU",
};
return categories[category];
};
const parseSize = (size) => {
const units = {
TB: 1024 ** 4,
GB: 1024 ** 3,
MB: 1024 ** 2,
KB: 1024,
B: 1,
};
const [sizeStr, unit] = size.split(" ");
const sizeNum = Number(sizeStr);
if (!sizeNum || !units[unit])
return 0;
return Math.ceil(sizeNum * units[unit]);
};
//# sourceMappingURL=itorrent.js.map