fix: removed torrents
This commit is contained in:
1 parent
ef60471cb4
commit
74e35267f9
6 files changed
+190
-38
No files matched your search
@@ -0,0 +1,99 @@
|
|||||||
|
import axios, { Axios, AxiosError, AxiosInstance } from 'axios';
|
||||||
|
import iconv from 'iconv-lite';
|
||||||
|
import { parse } from 'node-html-parser';
|
||||||
|
|
||||||
|
export class Tracker {
|
||||||
|
private client: AxiosInstance;
|
||||||
|
// private authorized: Promise<boolean>;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private credentials: { login: string; password: string },
|
||||||
|
private host: string = process.env.TRACKER_HOST || 'https://rutracker.org/forum'
|
||||||
|
) {
|
||||||
|
this.host = host;
|
||||||
|
this.credentials = credentials;
|
||||||
|
this.client = axios.create({
|
||||||
|
baseURL: this.host,
|
||||||
|
responseType: 'arraybuffer',
|
||||||
|
headers: {
|
||||||
|
Cookie:
|
||||||
|
'bb_guid=VRSW4TnBYXKS;bb_ssl=1;opt_js={%22only_new%22:0%2C%22h_flag%22:0%2C%22h_av%22:0%2C%22h_rnk_i%22:0%2C%22h_post_i%22:0%2C%22h_smile%22:0%2C%22h_sig%22:0%2C%22sp_op%22:0%2C%22tr_tm%22:0%2C%22h_cat%22:%22%22%2C%22h_tsp%22:0%2C%22h_ta%22:76};bb_t=a%3A5%3A%7Bi%3A6370796%3Bi%3A1685706087%3Bi%3A6358638%3Bi%3A1683106302%3Bi%3A6123599%3Bi%3A1664644059%3Bi%3A6169892%3Bi%3A1643607794%3Bi%3A6169913%3Bi%3A1643503061%3B%7D;bb_session=0-17771272-7EtecN88pRZEt82Uf9z7;cf_clearance=sR1CBz2JU3HK8IH8USbPQg681FvxoKMEDFcp.bOCiMw-1691858160-0-1-9ac26b22.c8ca8b5e.cdc334c2-0.2.1691858160'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.client.interceptors.response.use((response) => ({
|
||||||
|
...response,
|
||||||
|
data: iconv.decode(response.data, 'win1251')
|
||||||
|
}));
|
||||||
|
// this.authorized = this.login();
|
||||||
|
}
|
||||||
|
|
||||||
|
async login() {
|
||||||
|
const body = new URLSearchParams();
|
||||||
|
|
||||||
|
body.append('redirect', 'index.php');
|
||||||
|
body.append('login_username', this.credentials.login);
|
||||||
|
body.append('login_password', this.credentials.password);
|
||||||
|
body.append('login', 'Вход');
|
||||||
|
|
||||||
|
return this.client
|
||||||
|
.post('/login.php', body.toString(), {
|
||||||
|
maxRedirects: 0,
|
||||||
|
validateStatus(status) {
|
||||||
|
return status === 302;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(({ headers }) => {
|
||||||
|
const [_, session] = headers['set-cookie'] || [];
|
||||||
|
const [Cookie] = (session || '').split(';');
|
||||||
|
|
||||||
|
this.client.defaults.headers.common = {
|
||||||
|
Cookie: `bb_ssl=1; ${Cookie}`
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async search({ query, page = 0, searchId }: { query: string; page?: number; searchId?: string }) {
|
||||||
|
// try {
|
||||||
|
// await this.authorized.catch((error) => {
|
||||||
|
// return Promise.reject(iconv.decode(error.response?.data, 'win1251'));
|
||||||
|
// });
|
||||||
|
// } catch (error) {
|
||||||
|
// return Promise.resolve(error);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return this.client
|
||||||
|
.post('/tracker.php', null, {
|
||||||
|
params: {
|
||||||
|
nm: query,
|
||||||
|
search_id: searchId,
|
||||||
|
start: page * 50
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
|
const html = parse(data);
|
||||||
|
|
||||||
|
const topics = html.querySelectorAll('tr[data-topic_id]').map((row) => {
|
||||||
|
return {
|
||||||
|
id: row.getAttribute('data-topic_id'),
|
||||||
|
category: row.querySelector('.f-name .ts-text')?.text,
|
||||||
|
size: row.querySelector('.tor-size .tr-dl')?.text?.replace(' ↓', ''),
|
||||||
|
title: row.querySelector('.t-title .ts-text')?.text,
|
||||||
|
seeders: parseInt(row.querySelector('.seedmed')?.text || '0'),
|
||||||
|
searchId: new URLSearchParams(html.querySelector('.pg')?.getAttribute('href')?.split('?')?.[1]).get(
|
||||||
|
'search_id'
|
||||||
|
)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return topics;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchMagnet(torrentId: string) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tracker = new Tracker({ login: process.env.TRACKER_LOGIN!, password: process.env.TRACKER_PASSWORD! });
|
||||||
|
|
||||||
|
export default tracker;
|
||||||
@@ -1,37 +1,39 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import Tracker from 'rutracker-api-with-proxy';
|
|
||||||
|
// import Tracker from 'rutracker-api-with-proxy';
|
||||||
|
import tracker from '../parsers/tracker';
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const tracker = new Tracker();
|
// const tracker = new Tracker();
|
||||||
await tracker.login({ username: process.env.TRACKER_LOGIN, password: process.env.TRACKER_PASSWORD });
|
// await tracker.login({ username: process.env.TRACKER_LOGIN, password: process.env.TRACKER_PASSWORD });
|
||||||
|
|
||||||
const results: TrackerTorrent[] = await tracker.search({ query: params.query });
|
// const results: TrackerTorrent[] = await tracker.search({ query: params.query });
|
||||||
|
|
||||||
const movies = results.filter((torrent) => torrent.category.includes('кино'));
|
// const movies = results.filter((torrent) => torrent.category.includes('кино'));
|
||||||
|
|
||||||
const links = ((await Promise.all(movies?.map(({ id }) => tracker.getMagnetLink(id)))) || []) as string[];
|
// const links = ((await Promise.all(movies?.map(({ id }) => tracker.getMagnetLink(id)))) || []) as string[];
|
||||||
|
|
||||||
const torrents =
|
// const torrents =
|
||||||
movies?.map(
|
// movies?.map(
|
||||||
({ seeds, title, id, size }, index) =>
|
// ({ seeds, title, id, size }, index) =>
|
||||||
({
|
// ({
|
||||||
seeders: seeds,
|
// seeders: seeds,
|
||||||
title,
|
// title,
|
||||||
id,
|
// id,
|
||||||
magnetLink: links[index],
|
// magnetLink: links[index],
|
||||||
size: `${(size / (1024 * 1024 * 1024)).toFixed(2)} GiB`
|
// size: `${(size / (1024 * 1024 * 1024)).toFixed(2)} GiB`
|
||||||
}) as Torrent
|
// }) as Torrent
|
||||||
) || [];
|
// ) || [];
|
||||||
|
|
||||||
|
// return NextResponse.json(torrents);
|
||||||
|
// } catch (error) {
|
||||||
|
// return NextResponse.json([{ title: JSON.stringify(error) }]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
const torrents = await tracker.search({ query: params.query, page: parseInt(params.page || '0') });
|
||||||
|
|
||||||
return NextResponse.json(torrents);
|
return NextResponse.json(torrents);
|
||||||
} catch (error) {
|
|
||||||
return NextResponse.json([
|
|
||||||
{ title: `${JSON.stringify(error)}, ${process.env.TRACKER_LOGIN}, ${process.env.TRACKER_PASSWORD}` }
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const revalidate = 0;
|
|
||||||
@@ -6,9 +6,7 @@ import Credits from '@/components/Movie/components/Credits';
|
|||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
import Rating from '@/components/Movie/components/Rating';
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
import Title from '@/components/Movie/components/Title';
|
import Title from '@/components/Movie/components/Title';
|
||||||
import Torrents from '@/components/Movie/components/Torrents';
|
|
||||||
import Trailer from '@/components/Movie/components/Trailer';
|
import Trailer from '@/components/Movie/components/Trailer';
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -20,7 +18,6 @@ interface Props {
|
|||||||
const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
||||||
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
||||||
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||||
const [isShowTorrents, setIsShowTorrents] = useState(false);
|
|
||||||
|
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
@@ -62,15 +59,11 @@ const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
|||||||
<div className='flex flex-col items-start grow justify-between'>
|
<div className='flex flex-col items-start grow justify-between'>
|
||||||
<p className='leading-7'>{movie.overview}</p>
|
<p className='leading-7'>{movie.overview}</p>
|
||||||
</div>
|
</div>
|
||||||
<Button size='sm' className='h-8 mt-2' onClick={() => setIsShowTorrents(true)}>
|
|
||||||
Torrents
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Credits movieId={movie.id} onPersonClick={onPersonClick} />
|
<Credits movieId={movie.id} onPersonClick={onPersonClick} />
|
||||||
</div>
|
</div>
|
||||||
{isShowTrailer && <Trailer trailerKey={trailer?.key} onClose={() => setIsShowTrailer(false)} />}
|
{isShowTrailer && <Trailer trailerKey={trailer?.key} onClose={() => setIsShowTrailer(false)} />}
|
||||||
{isShowTorrents && <Torrents title={movie.title} onClose={() => setIsShowTorrents(false)} />}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import { clsx } from 'clsx'
|
|
||||||
import { twMerge } from 'tailwind-merge'
|
|
||||||
|
|
||||||
export function cn(...inputs) {
|
|
||||||
return twMerge(clsx(inputs))
|
|
||||||
}
|
|
||||||
Generated
+62
@@ -31,11 +31,13 @@
|
|||||||
"cmdk": "^0.2.0",
|
"cmdk": "^0.2.0",
|
||||||
"eslint": "8.45.0",
|
"eslint": "8.45.0",
|
||||||
"eslint-config-next": "13.4.12",
|
"eslint-config-next": "13.4.12",
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
"jotai": "^2.2.2",
|
"jotai": "^2.2.2",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"lucide-react": "^0.263.0",
|
"lucide-react": "^0.263.0",
|
||||||
"next": "13.4.9",
|
"next": "13.4.9",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
|
"node-html-parser": "^6.1.5",
|
||||||
"openai": "^3.3.0",
|
"openai": "^3.3.0",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
@@ -4977,6 +4979,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/he": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
|
||||||
|
"bin": {
|
||||||
|
"he": "bin/he"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/htmlparser2": {
|
"node_modules/htmlparser2": {
|
||||||
"version": "8.0.2",
|
"version": "8.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",
|
||||||
@@ -5043,6 +5053,17 @@
|
|||||||
"memory-chunk-store": "^1.3.5"
|
"memory-chunk-store": "^1.3.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/iconv-lite": {
|
||||||
|
"version": "0.6.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||||
|
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/idb": {
|
"node_modules/idb": {
|
||||||
"version": "6.1.5",
|
"version": "6.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/idb/-/idb-6.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/idb/-/idb-6.1.5.tgz",
|
||||||
@@ -6127,6 +6148,15 @@
|
|||||||
"node-gyp-build-test": "build-test.js"
|
"node-gyp-build-test": "build-test.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/node-html-parser": {
|
||||||
|
"version": "6.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-6.1.5.tgz",
|
||||||
|
"integrity": "sha512-fAaM511feX++/Chnhe475a0NHD8M7AxDInsqQpz6x63GRF7xYNdS8Vo5dKsIVPgsOvG7eioRRTZQnWBrhDHBSg==",
|
||||||
|
"dependencies": {
|
||||||
|
"css-select": "^5.1.0",
|
||||||
|
"he": "1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-releases": {
|
"node_modules/node-releases": {
|
||||||
"version": "2.0.13",
|
"version": "2.0.13",
|
||||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
|
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
|
||||||
@@ -7363,6 +7393,11 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/safer-buffer": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
|
},
|
||||||
"node_modules/sax": {
|
"node_modules/sax": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||||
@@ -11932,6 +11967,11 @@
|
|||||||
"has-symbols": "^1.0.2"
|
"has-symbols": "^1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"he": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
|
||||||
|
},
|
||||||
"htmlparser2": {
|
"htmlparser2": {
|
||||||
"version": "8.0.2",
|
"version": "8.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",
|
||||||
@@ -11982,6 +12022,14 @@
|
|||||||
"memory-chunk-store": "^1.3.5"
|
"memory-chunk-store": "^1.3.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"iconv-lite": {
|
||||||
|
"version": "0.6.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||||
|
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
||||||
|
"requires": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"idb": {
|
"idb": {
|
||||||
"version": "6.1.5",
|
"version": "6.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/idb/-/idb-6.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/idb/-/idb-6.1.5.tgz",
|
||||||
@@ -12679,6 +12727,15 @@
|
|||||||
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==",
|
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"node-html-parser": {
|
||||||
|
"version": "6.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-6.1.5.tgz",
|
||||||
|
"integrity": "sha512-fAaM511feX++/Chnhe475a0NHD8M7AxDInsqQpz6x63GRF7xYNdS8Vo5dKsIVPgsOvG7eioRRTZQnWBrhDHBSg==",
|
||||||
|
"requires": {
|
||||||
|
"css-select": "^5.1.0",
|
||||||
|
"he": "1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node-releases": {
|
"node-releases": {
|
||||||
"version": "2.0.13",
|
"version": "2.0.13",
|
||||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
|
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
|
||||||
@@ -13471,6 +13528,11 @@
|
|||||||
"is-regex": "^1.1.4"
|
"is-regex": "^1.1.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"safer-buffer": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
|
},
|
||||||
"sax": {
|
"sax": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||||
|
|||||||
@@ -32,11 +32,13 @@
|
|||||||
"cmdk": "^0.2.0",
|
"cmdk": "^0.2.0",
|
||||||
"eslint": "8.45.0",
|
"eslint": "8.45.0",
|
||||||
"eslint-config-next": "13.4.12",
|
"eslint-config-next": "13.4.12",
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
"jotai": "^2.2.2",
|
"jotai": "^2.2.2",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"lucide-react": "^0.263.0",
|
"lucide-react": "^0.263.0",
|
||||||
"next": "13.4.9",
|
"next": "13.4.9",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
|
"node-html-parser": "^6.1.5",
|
||||||
"openai": "^3.3.0",
|
"openai": "^3.3.0",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
|
|||||||
Reference in new issue
Block a user