torrent-agent 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
package/dist/query.js
CHANGED
|
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { EventEmitter } from "events";
|
|
11
11
|
import PQueue from "p-queue";
|
|
12
|
-
import {
|
|
12
|
+
import { TorrentGalaxy } from "./scrapers/torrentGalaxy.js";
|
|
13
13
|
export class QueryError extends Error {
|
|
14
14
|
constructor(msg) {
|
|
15
15
|
super();
|
|
16
16
|
this.message = msg;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export const DefaultScrapers = [new
|
|
19
|
+
export const DefaultScrapers = [new TorrentGalaxy()];
|
|
20
20
|
export const QueueDestroyedErr = new QueryError("The queue is destroyed cannot run the query.\nThis error may be caused because the query is already destroyed.");
|
|
21
21
|
export const QueryDestroyed = new QueryError("The query is destroyed cannot run the query.");
|
|
22
22
|
export default class Query extends EventEmitter {
|
|
@@ -10,7 +10,7 @@ export interface Torrent {
|
|
|
10
10
|
magnetURI?: string;
|
|
11
11
|
torrentDownload?: string;
|
|
12
12
|
size: string;
|
|
13
|
-
uploader
|
|
13
|
+
uploader?: string;
|
|
14
14
|
}
|
|
15
15
|
export interface TorrentLink {
|
|
16
16
|
name: string;
|
|
@@ -19,7 +19,7 @@ export interface TorrentLink {
|
|
|
19
19
|
provider: string;
|
|
20
20
|
url: string;
|
|
21
21
|
size: string;
|
|
22
|
-
uploader
|
|
22
|
+
uploader?: string;
|
|
23
23
|
}
|
|
24
24
|
export declare abstract class Scraper {
|
|
25
25
|
protected opts: ScraperOpts;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Scraper, ScraperOpts, Torrent, TorrentLink } from "./scraper.js";
|
|
2
|
+
export declare class TorrentGalaxy extends Scraper {
|
|
3
|
+
static firstTouchUrl: string;
|
|
4
|
+
constructor(opts?: ScraperOpts);
|
|
5
|
+
firstTouch(query: string, limit?: number): Promise<TorrentLink[]>;
|
|
6
|
+
scrapeTorrent(link: TorrentLink): Promise<Torrent>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { Scraper } from "./scraper.js";
|
|
12
|
+
import { load } from "cheerio";
|
|
13
|
+
export class TorrentGalaxy extends Scraper {
|
|
14
|
+
constructor(opts = {}) {
|
|
15
|
+
super(opts);
|
|
16
|
+
}
|
|
17
|
+
firstTouch(query, limit) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (!query) {
|
|
20
|
+
throw new Error("search query is required to scrape");
|
|
21
|
+
}
|
|
22
|
+
let results = [];
|
|
23
|
+
let page = 1;
|
|
24
|
+
while (results.length != (limit || 20)) {
|
|
25
|
+
const { data } = yield axios.get(TorrentGalaxy.firstTouchUrl
|
|
26
|
+
.replace(":query", query || "")
|
|
27
|
+
.replace(":page", page.toString()));
|
|
28
|
+
const $ = load(data);
|
|
29
|
+
let torrentCount = $(".table-list-wrap tbody tr").length;
|
|
30
|
+
if (torrentCount === 0) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
$(".table-list-wrap tbody tr").each((i, el) => {
|
|
34
|
+
if (results.length >= (limit || 20))
|
|
35
|
+
return;
|
|
36
|
+
const name = $(el).find("td .tt-name a").eq(0).text().trim();
|
|
37
|
+
const url = "https://torrentgalaxy.hair" +
|
|
38
|
+
$(el).find("td .tt-name a").eq(0).attr("href");
|
|
39
|
+
const tds = $(el).find("td");
|
|
40
|
+
const size = $(tds[2]).text().trim();
|
|
41
|
+
const seeders = $(tds[3]).text().trim();
|
|
42
|
+
const leechers = $(tds[4]).text().trim();
|
|
43
|
+
results.push({
|
|
44
|
+
name,
|
|
45
|
+
url,
|
|
46
|
+
seeders: +seeders,
|
|
47
|
+
leechers: +leechers,
|
|
48
|
+
provider: "TGx",
|
|
49
|
+
size,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
page++;
|
|
53
|
+
}
|
|
54
|
+
return results;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
scrapeTorrent(link) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (!link.url) {
|
|
60
|
+
throw new Error("url is required in the torrent link");
|
|
61
|
+
}
|
|
62
|
+
const { data } = yield axios.get(link.url);
|
|
63
|
+
const $ = load(data);
|
|
64
|
+
const magnetURI = $("a[href^='magnet:?']").attr("href");
|
|
65
|
+
const infoHash = $(".infohash-box span").text().trim();
|
|
66
|
+
const torrentDownload = $("a[href$='.torrent']").attr("href");
|
|
67
|
+
return Object.assign({ magnetURI, infoHash, torrentDownload }, link);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
TorrentGalaxy.firstTouchUrl = "https://torrentgalaxy.hair/lmsearch?q=:query&category=lmsearch&page=:page";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "torrent-agent",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "NPM library for searching torrents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
"test:watch": "jest --watch",
|
|
14
14
|
"build": "tsc"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"torrent",
|
|
18
|
+
"torrent search"
|
|
19
|
+
],
|
|
17
20
|
"author": "khlala",
|
|
18
21
|
"license": "Apache-2.0",
|
|
19
22
|
"devDependencies": {
|