fix: SITE_URL
This commit is contained in:
1 parent
1fe912f4bd
commit
dfdfb79169
66 files changed
+1352
-240
No files matched your search
@@ -0,0 +1,4 @@
|
||||
export enum Sort {
|
||||
size = 'size',
|
||||
seeds = 'seeds'
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { wrapper } from 'axios-cookiejar-support';
|
||||
import { load } from 'cheerio';
|
||||
import parseTorrent, { Instance } from 'parse-torrent';
|
||||
import torrentTitle from 'parse-torrent-title';
|
||||
import { CookieJar } from 'tough-cookie';
|
||||
|
||||
import { TOLOKA_HOST, TOLOKA_PASSWORD, TOLOKA_USERNAME } from '@/env';
|
||||
|
||||
import { Sort } from '../index';
|
||||
|
||||
export class Toloka {
|
||||
private client: AxiosInstance;
|
||||
private host: string;
|
||||
private sort = {
|
||||
[Sort.size]: 7,
|
||||
[Sort.seeds]: 10
|
||||
};
|
||||
|
||||
private cookieJar = new CookieJar();
|
||||
|
||||
private magnets: Record<string, string> = {};
|
||||
|
||||
constructor() {
|
||||
this.host = TOLOKA_HOST || 'https://toloka.to';
|
||||
|
||||
this.client = wrapper(
|
||||
axios.create({
|
||||
jar: this.cookieJar,
|
||||
baseURL: this.host,
|
||||
withCredentials: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private async isAuthorized(data: string) {
|
||||
return !load(data)('[href="/login.php"]').length;
|
||||
}
|
||||
|
||||
private async auth() {
|
||||
const data = new FormData();
|
||||
|
||||
data.append('username', TOLOKA_USERNAME as string);
|
||||
data.append('password', TOLOKA_PASSWORD as string);
|
||||
data.append('autologin', 'on');
|
||||
data.append('ssl', 'on');
|
||||
data.append('login', 'Вхід');
|
||||
|
||||
await this.client.post('/login.php', data, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
});
|
||||
}
|
||||
|
||||
async search({ query, sort = Sort.size }: { query: string; sort?: Sort }): Promise<Torrent[]> {
|
||||
const fetchPage = () => this.client.get(`/tracker.php?o=${this.sort[sort]}&nm=${query}`);
|
||||
|
||||
const parseTorrents = (data: string) => {
|
||||
const $ = load(data);
|
||||
const rows = $('.prow1, .prow2');
|
||||
|
||||
return rows
|
||||
.map((_, row) => {
|
||||
const originalTitle = $(row).find('td:nth-child(3)').text();
|
||||
const size = $(row).find('td:nth-child(7)').text();
|
||||
const seeders = $(row).find('td:nth-child(10)').text();
|
||||
const download = $(row).find('td:nth-child(6) a').attr('href');
|
||||
|
||||
const { year, source, codec, container, title, season, episode, resolution } = torrentTitle.parse(
|
||||
originalTitle || ''
|
||||
);
|
||||
|
||||
return {
|
||||
year: year?.toString(),
|
||||
source,
|
||||
codec,
|
||||
container,
|
||||
originalTitle,
|
||||
title: `${title}${season && episode ? ` [S${season}:E${episode}]` : ''}`,
|
||||
id: originalTitle || '',
|
||||
size,
|
||||
seeders: parseInt(seeders || '0'),
|
||||
quality: resolution,
|
||||
magnet: '',
|
||||
download
|
||||
};
|
||||
})
|
||||
.get();
|
||||
};
|
||||
|
||||
let page = await fetchPage();
|
||||
|
||||
if (await this.isAuthorized(page.data)) return parseTorrents(page.data);
|
||||
|
||||
await this.auth();
|
||||
|
||||
page = await fetchPage();
|
||||
|
||||
return parseTorrents(page.data);
|
||||
}
|
||||
|
||||
async magnet(url: string) {
|
||||
if (this.magnets[url]) return this.magnets[url];
|
||||
|
||||
const fetchTorrent = async () => {
|
||||
const { data: buffer } = await this.client.get(`/${url}`, {
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
|
||||
return parseTorrent(buffer);
|
||||
};
|
||||
|
||||
let torrent: Instance;
|
||||
|
||||
try {
|
||||
torrent = (await fetchTorrent()) as Instance;
|
||||
} catch (_) {
|
||||
await this.auth();
|
||||
|
||||
torrent = (await fetchTorrent()) as Instance;
|
||||
}
|
||||
|
||||
const magnet = `magnet:?xt=urn:btih:${torrent.infoHash}&dn=${encodeURIComponent(torrent.name?.toString() || '')}`;
|
||||
|
||||
this.magnets[url] = magnet;
|
||||
|
||||
return this.magnets[url];
|
||||
}
|
||||
}
|
||||
|
||||
const parser = new Toloka();
|
||||
|
||||
export default parser;
|
||||
@@ -0,0 +1,85 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { load } from 'cheerio';
|
||||
import torrentTitle from 'parse-torrent-title';
|
||||
|
||||
import { PIRATE_BAY_HOST } from '@/env';
|
||||
|
||||
import { Sort } from '../index';
|
||||
|
||||
export class PirateBay {
|
||||
private client: AxiosInstance;
|
||||
private host: string;
|
||||
private sort = {
|
||||
[Sort.size]: 5,
|
||||
[Sort.seeds]: 7
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.host = PIRATE_BAY_HOST || 'https://thepiratebay10.info';
|
||||
|
||||
this.client = axios.create({
|
||||
baseURL: this.host
|
||||
});
|
||||
}
|
||||
|
||||
async search({
|
||||
query,
|
||||
page = 1,
|
||||
category = 200,
|
||||
sort = Sort.size
|
||||
}: {
|
||||
query: string;
|
||||
page?: number;
|
||||
category?: number;
|
||||
sort?: Sort;
|
||||
}): Promise<Torrent[]> {
|
||||
return this.client.post(`/search/${query}/${page}/${this.sort[sort]}/${category}`, null).then(({ data }) => {
|
||||
const $ = load(data);
|
||||
const table = $('#searchResult');
|
||||
const rows = table.find('tr:not(.header)');
|
||||
|
||||
const titles = rows
|
||||
.map((_, row) => $(row).find('td:nth-child(2) a').text())
|
||||
.get()
|
||||
.filter(Boolean);
|
||||
const seeders = rows.map((_, row) => $(row).find('td:nth-child(6)').text()).get();
|
||||
|
||||
const sizes = rows
|
||||
.map((_, row) => {
|
||||
const size = $(row).find('td:nth-child(5)').text();
|
||||
return size ? size.replace(' ', ' ').replace('Size ', '') : null;
|
||||
})
|
||||
.get()
|
||||
.filter(Boolean);
|
||||
|
||||
const magnets = table
|
||||
.find('a[href^="magnet:"]')
|
||||
.map((_, link) => $(link).attr('href'))
|
||||
.get();
|
||||
|
||||
return titles.map((originalTitle, index) => {
|
||||
const { title, resolution, source, codec, container, season, episode, year } = torrentTitle.parse(
|
||||
originalTitle || ''
|
||||
);
|
||||
|
||||
return {
|
||||
year: year?.toString(),
|
||||
source,
|
||||
codec,
|
||||
container,
|
||||
originalTitle,
|
||||
title: `${title} ${season && episode ? `[S${season}:E${episode}]` : ''}`,
|
||||
id: title,
|
||||
size: sizes[index],
|
||||
seeders: parseInt(seeders[index] || '0', 10),
|
||||
quality: resolution,
|
||||
magnet: magnets[index] || ''
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const parser = new PirateBay();
|
||||
|
||||
export default parser;
|
||||
@@ -0,0 +1,74 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
|
||||
import { YTS_HOST } from '@/env';
|
||||
|
||||
import { Sort } from '../index';
|
||||
|
||||
import { YTSResponse } from './models';
|
||||
|
||||
export class YTS {
|
||||
private client: AxiosInstance;
|
||||
private host: string;
|
||||
|
||||
constructor() {
|
||||
this.host = YTS_HOST || 'https://yts.mx/api/v2/list_movies.json';
|
||||
|
||||
this.client = axios.create({
|
||||
baseURL: this.host
|
||||
});
|
||||
}
|
||||
|
||||
async search({
|
||||
query,
|
||||
page = 1,
|
||||
sort = Sort.size,
|
||||
imdbID
|
||||
}: {
|
||||
query: string;
|
||||
imdbID: string;
|
||||
page?: number;
|
||||
sort?: Sort;
|
||||
}): Promise<Torrent[]> {
|
||||
return this.client
|
||||
.get<YTSResponse>('', {
|
||||
params: {
|
||||
page,
|
||||
query_term: query,
|
||||
sort_by: sort
|
||||
}
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const movie = data?.data?.movies?.find((movie) => movie.imdb_code === imdbID);
|
||||
|
||||
return (
|
||||
movie?.torrents.map((torrent) => {
|
||||
const trackers = [
|
||||
'udp://open.demonii.com:1337/announce',
|
||||
'udp://tracker.openbittorrent.com:80',
|
||||
'udp://tracker.coppersurfer.tk:6969',
|
||||
'udp://glotorrents.pw:6969/announce',
|
||||
'udp://tracker.opentrackr.org:1337/announce',
|
||||
'udp://torrent.gresille.org:80/announce',
|
||||
'udp://p4p.arenabg.com:1337',
|
||||
'udp://tracker.leechers-paradise.org:6969'
|
||||
];
|
||||
|
||||
return {
|
||||
id: movie.id?.toString(),
|
||||
title: movie.title_english,
|
||||
seeders: torrent.seeds,
|
||||
size: torrent.size,
|
||||
quality: torrent.quality,
|
||||
source: torrent.type,
|
||||
year: movie.year?.toString(),
|
||||
magnet: `magnet:?xt=urn:btih:${torrent.hash}&dn=${encodeURIComponent(query)}&tr=${trackers.join('&tr=')}`
|
||||
};
|
||||
}) || []
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const yts = new YTS();
|
||||
|
||||
export default yts;
|
||||
@@ -0,0 +1,98 @@
|
||||
export interface YTSResponse {
|
||||
status: Stat;
|
||||
status_message: string;
|
||||
data: Data;
|
||||
'@meta': Meta;
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
server_time: number;
|
||||
server_timezone: string;
|
||||
api_version: number;
|
||||
execution_time: string;
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
movie_count: number;
|
||||
limit: number;
|
||||
page_number: number;
|
||||
movies: Movie[];
|
||||
}
|
||||
|
||||
export interface Movie {
|
||||
id: number;
|
||||
url: string;
|
||||
imdb_code: string;
|
||||
title: string;
|
||||
title_english: string;
|
||||
title_long: string;
|
||||
slug: string;
|
||||
year: number;
|
||||
rating: number;
|
||||
runtime: number;
|
||||
genres: string[];
|
||||
summary: string;
|
||||
description_full: string;
|
||||
synopsis: string;
|
||||
yt_trailer_code: string;
|
||||
language: Language;
|
||||
mpa_rating: MpaRating;
|
||||
background_image: string;
|
||||
background_image_original: string;
|
||||
small_cover_image: string;
|
||||
medium_cover_image: string;
|
||||
large_cover_image: string;
|
||||
state: Stat;
|
||||
torrents: Torrent[];
|
||||
date_uploaded: Date;
|
||||
date_uploaded_unix: number;
|
||||
}
|
||||
|
||||
export enum Language {
|
||||
En = 'en',
|
||||
Ja = 'ja'
|
||||
}
|
||||
|
||||
export enum MpaRating {
|
||||
Empty = '',
|
||||
PG13 = 'PG-13',
|
||||
R = 'R'
|
||||
}
|
||||
|
||||
export enum Stat {
|
||||
Ok = 'ok'
|
||||
}
|
||||
|
||||
export interface Torrent {
|
||||
url: string;
|
||||
hash: string;
|
||||
quality: Quality;
|
||||
type: Type;
|
||||
is_repack: string;
|
||||
video_codec: VideoCodec;
|
||||
bit_depth: string;
|
||||
audio_channels: string;
|
||||
seeds: number;
|
||||
peers: number;
|
||||
size: string;
|
||||
size_bytes: number;
|
||||
date_uploaded: Date;
|
||||
date_uploaded_unix: number;
|
||||
}
|
||||
|
||||
export enum Quality {
|
||||
The1080P = '1080p',
|
||||
The2160P = '2160p',
|
||||
The3D = '3D',
|
||||
The720P = '720p'
|
||||
}
|
||||
|
||||
export enum Type {
|
||||
Bluray = 'bluray',
|
||||
Web = 'web'
|
||||
}
|
||||
|
||||
export enum VideoCodec {
|
||||
X264 = 'x264',
|
||||
X265 = 'x265'
|
||||
}
|
||||
Reference in new issue
Block a user