- parse Toloka Ukrainian season/episode naming (Сезони 1-10, серій 7 з 8, homoglyphs) into a clean title + episodes field - add series-only sortable S:E column, desktop-only Year column; strip year/source meta from the title cell - filter out torrents with fewer than 5 seeders in the API route - cache Toloka magnets in Redis so each .torrent is downloaded once across serverless instances; append public trackers to magnets (never the passkey-bearing announce URLs from the .torrent) - fix play button hover state while magnet is pending Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
import axios, { AxiosInstance } from 'axios';
|
|
|
|
import { YTS_HOST } from '@/env';
|
|
|
|
import { Sort, TRACKERS } from '../index';
|
|
|
|
import { YTSResponse } from './models';
|
|
|
|
export class YTS {
|
|
private client: AxiosInstance;
|
|
private host: string;
|
|
|
|
constructor() {
|
|
this.host = YTS_HOST || 'https://yts.lt/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) => {
|
|
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=')}`,
|
|
hash: torrent.hash,
|
|
codec: torrent.video_codec
|
|
};
|
|
}) || []
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
const yts = new YTS();
|
|
|
|
export default yts;
|