init: toloka

This commit is contained in:
ner committed 2024-10-25 22:00:02 +03:00
1 parent be9a128793
commit 345cf911a4
5 files changed
+48 -60

No files matched your search

+1 -54
View File
@@ -5,11 +5,8 @@ import { cookies } from 'next/headers';
import { createUniqueRandomGenerator } from '@/lib/utils';
import mapMoviesSeriesResponseToShows, { mapMovieSeriesToShow } from './dto/Show';
import pirateBay from './parsers/pirate-bay';
import toloka from './parsers/toloka';
import yts from './parsers/yts';
import http from './Http';
import { Sort } from './parsers';
const session = () => cookies().get('session')?.value;
@@ -238,54 +235,4 @@ export const credits = async ({
});
};
export const trailers = async ({
showId,
showType
}: {
showId: Show['id'];
showType?: Show['type'];
}): Promise<Trailer[]> => {
return http
.get<{ id: number; results: Trailer[] }>(`/${showType}/${showId}/videos`, {
params: {
language: 'en-US'
}
})
.then((data) => data.results);
};
export const YTSTorrents = async ({ query, sort, imdbID }: { imdbID: string; query: string; sort: Sort }) => {
try {
return yts.search({
imdbID,
query,
sort
});
} catch (error) {
return [];
}
};
export const TPBTorrents = async ({ query, sort }: { imdbID: string; query: string; sort: Sort }) => {
try {
return pirateBay.search({
query,
sort
});
} catch (error) {
return [];
}
};
export const TLKTorrents = async ({ query, sort }: { imdbID: string; query: string; sort: Sort }) => {
try {
return toloka.search({
query,
sort
});
} catch (error) {
return [];
}
};
export const fetchTLKMagnet = async (url: string) => toloka.magnet(url);
export const fetchTLKMagnet = async (url: string) => toloka.magnet(url);
+1 -1
View File
@@ -18,7 +18,7 @@ export class Toloka {
this.host = host;
this.client = axios.create({
baseURL: this.host,
headers: { Cookie: 'toloka_sid=0504c23f6b4fc00d39530cfa78f8d767; toloka_ssl=1' }
headers: { Cookie: 'toloka_sid=e9693224d00c5b60af50c2596d1b880d; toloka_ssl=1' }
});
}
+21
View File
@@ -0,0 +1,21 @@
import { NextRequest } from 'next/server';
import { Sort } from '@/api/parsers';
import pirateBay from '@/api/parsers/pirate-bay';
import toloka from '@/api/parsers/toloka';
import yts from '@/api/parsers/yts';
export async function GET({ nextUrl: { searchParams } }: NextRequest) {
const key = searchParams.get('key') as keyof typeof providers;
const imdbID = searchParams.get('imdbID') as string;
const query = searchParams.get('query') as string;
const sort = searchParams.get('sort') as Sort;
const providers = { yts: yts, tpb: pirateBay, tlk: toloka };
try {
return Response.json(await providers[key].search({ imdbID, query, sort }));
} catch (_) {
return Response.json([]);
}
}
@@ -1,7 +1,27 @@
import { TLKTorrents, TPBTorrents, YTSTorrents } from '@/api';
import { Sort } from '@/api/parsers';
type Options = { query: string; sort: Sort; imdbID: string };
const queryFn = ({ query, sort, imdbID, key }: Options & { key: keyof typeof providers }) =>
fetch(`/api/torrents?key=${key}&query=${query}&sort=${sort}&imdbID=${imdbID}`).then((response) => response.json());
export const providers = {
yts: { label: 'YTS', key: 'yts', queryFn: YTSTorrents, sortable: false },
tpb: { label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true },
tlk: { label: 'Toloka', key: 'tlk', queryFn: TLKTorrents, sortable: true }
yts: {
label: 'YTS',
key: 'yts',
queryFn: (options: Options) => queryFn({ ...options, key: 'yts' }),
sortable: false
},
tpb: {
label: 'The Pirate Bay',
key: 'tpb',
queryFn: (options: Options) => queryFn({ ...options, key: 'tpb' }),
sortable: true
},
tlk: {
label: 'Toloka',
key: 'tlk',
queryFn: (options: Options) => queryFn({ ...options, key: 'tlk' }),
sortable: true
}
};
+1 -1
View File
@@ -1 +1 @@
if(!self.define){let e,s={};const a=(a,n)=>(a=new URL(a+".js",n).href,s[a]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=a,e.onload=s,document.head.appendChild(e)}else e=a,importScripts(a),s()})).then((()=>{let e=s[a];if(!e)throw new Error(`Module ${a} didn’t register its module`);return e})));self.define=(n,c)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(s[i])return;let t={};const r=e=>a(e,i),u={module:{uri:i},exports:t,require:r};s[i]=Promise.all(n.map((e=>u[e]||r(e)))).then((e=>(c(...e),t)))}}define(["./workbox-4754cb34"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/app-build-manifest.json",revision:"2f5a1d17c836a7f987c5aad8087f7f69"},{url:"/_next/static/chunks/152.e619d8b05424829e.js",revision:"e619d8b05424829e"},{url:"/_next/static/chunks/23-e95fe3862375276d.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/26.286553a5ff2812fc.js",revision:"286553a5ff2812fc"},{url:"/_next/static/chunks/276.c3c1130f2adade69.js",revision:"c3c1130f2adade69"},{url:"/_next/static/chunks/311-cfac2c6c6bc4f409.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/344.05938a041227e582.js",revision:"05938a041227e582"},{url:"/_next/static/chunks/37-f6e2aef0dac1a9f4.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/383.78d47f7582340f53.js",revision:"78d47f7582340f53"},{url:"/_next/static/chunks/460.ac20021c7496f1d6.js",revision:"ac20021c7496f1d6"},{url:"/_next/static/chunks/497.a16beaad36f500fe.js",revision:"a16beaad36f500fe"},{url:"/_next/static/chunks/61.e269d4a699fba0b6.js",revision:"e269d4a699fba0b6"},{url:"/_next/static/chunks/621-fa4d2ff1cf645813.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/673.362c29137dd3e968.js",revision:"362c29137dd3e968"},{url:"/_next/static/chunks/693-2767062d917b3456.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/695.156d21364de6e419.js",revision:"156d21364de6e419"},{url:"/_next/static/chunks/755.5cd959eac5682527.js",revision:"5cd959eac5682527"},{url:"/_next/static/chunks/792.b51012549074b93f.js",revision:"b51012549074b93f"},{url:"/_next/static/chunks/810.6105e84414768b0d.js",revision:"6105e84414768b0d"},{url:"/_next/static/chunks/922.9ce4bf0553cfb724.js",revision:"9ce4bf0553cfb724"},{url:"/_next/static/chunks/957-9f7dee59febd35c3.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/favorites/page-597921ef02c719df.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/loading-96645736797edde7.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/page-50279285390a6523.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/popular/page-b24c2917fc8bafde.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/similar/page-76c09599bd10ea14.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/starring/page-cddd4e2d83614eda.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/top/page-489f98dd6cd2a463.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/(site)/watch-list/page-e3f529e210a2a8e9.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/_not-found/page-aa0c8e90320336c2.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/app/layout-e78d8a67bc5fd6ae.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/c8bcbd21.63daf74955ffea8b.js",revision:"63daf74955ffea8b"},{url:"/_next/static/chunks/fd9d1056-bdf7d185613ab264.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/framework-f66176bb897dc684.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/main-af50ab4bffe3e017.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/main-app-51cdaff1a81e6b49.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/pages/_app-6a626577ffa902a4.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/pages/_error-1be831200e60c5c0.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-d4343f8c473d689d.js",revision:"mc2DxrE-1g9uq61LbuNSz"},{url:"/_next/static/css/0d5f6452b2682b9b.css",revision:"0d5f6452b2682b9b"},{url:"/_next/static/css/af880b2e4df9cb52.css",revision:"af880b2e4df9cb52"},{url:"/_next/static/mc2DxrE-1g9uq61LbuNSz/_buildManifest.js",revision:"2ec694eb52ae4f523f265a46bae4d768"},{url:"/_next/static/mc2DxrE-1g9uq61LbuNSz/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/_next/static/media/46c21389e888bf13-s.woff2",revision:"272930c09ba14c81bb294be1fe18b049"},{url:"/_next/static/media/8888a3826f4a3af4-s.p.woff2",revision:"792477d09826b11d1e5a611162c9797a"},{url:"/_next/static/media/eafabf029ad39a43-s.p.woff2",revision:"43751174b6b810eb169101a20d8c26f8"},{url:"/_next/static/media/f5767adec246cdc1-s.woLine truncated
if(!self.define){let e,s={};const a=(a,n)=>(a=new URL(a+".js",n).href,s[a]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=a,e.onload=s,document.head.appendChild(e)}else e=a,importScripts(a),s()})).then((()=>{let e=s[a];if(!e)throw new Error(`Module ${a} didn’t register its module`);return e})));self.define=(n,i)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let c={};const r=e=>a(e,t),o={module:{uri:t},exports:c,require:r};s[t]=Promise.all(n.map((e=>o[e]||r(e)))).then((e=>(i(...e),c)))}}define(["./workbox-4754cb34"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/app-build-manifest.json",revision:"1df7667facd62f5f4fa582d1ba88c5cb"},{url:"/_next/static/EWvUMAZar8b7EDkgXgAVh/_buildManifest.js",revision:"2ec694eb52ae4f523f265a46bae4d768"},{url:"/_next/static/EWvUMAZar8b7EDkgXgAVh/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/_next/static/chunks/152.e619d8b05424829e.js",revision:"e619d8b05424829e"},{url:"/_next/static/chunks/23-e95fe3862375276d.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/26.286553a5ff2812fc.js",revision:"286553a5ff2812fc"},{url:"/_next/static/chunks/276.c3c1130f2adade69.js",revision:"c3c1130f2adade69"},{url:"/_next/static/chunks/311-217b9962adac0d58.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/344.05938a041227e582.js",revision:"05938a041227e582"},{url:"/_next/static/chunks/37-f6e2aef0dac1a9f4.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/383.78d47f7582340f53.js",revision:"78d47f7582340f53"},{url:"/_next/static/chunks/460.ac20021c7496f1d6.js",revision:"ac20021c7496f1d6"},{url:"/_next/static/chunks/497.a16beaad36f500fe.js",revision:"a16beaad36f500fe"},{url:"/_next/static/chunks/61.e269d4a699fba0b6.js",revision:"e269d4a699fba0b6"},{url:"/_next/static/chunks/621-fa4d2ff1cf645813.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/673.362c29137dd3e968.js",revision:"362c29137dd3e968"},{url:"/_next/static/chunks/693-2767062d917b3456.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/695.156d21364de6e419.js",revision:"156d21364de6e419"},{url:"/_next/static/chunks/755.5cd959eac5682527.js",revision:"5cd959eac5682527"},{url:"/_next/static/chunks/792.b51012549074b93f.js",revision:"b51012549074b93f"},{url:"/_next/static/chunks/810.6105e84414768b0d.js",revision:"6105e84414768b0d"},{url:"/_next/static/chunks/922.9ce4bf0553cfb724.js",revision:"9ce4bf0553cfb724"},{url:"/_next/static/chunks/957-9f7dee59febd35c3.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/favorites/page-597921ef02c719df.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/loading-96645736797edde7.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/page-50279285390a6523.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/popular/page-b24c2917fc8bafde.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/similar/page-76c09599bd10ea14.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/starring/page-cddd4e2d83614eda.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/top/page-489f98dd6cd2a463.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/(site)/watch-list/page-e3f529e210a2a8e9.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/_not-found/page-aa0c8e90320336c2.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/app/layout-e78d8a67bc5fd6ae.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/c8bcbd21.63daf74955ffea8b.js",revision:"63daf74955ffea8b"},{url:"/_next/static/chunks/fd9d1056-bdf7d185613ab264.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/framework-f66176bb897dc684.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/main-af50ab4bffe3e017.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/main-app-51cdaff1a81e6b49.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/pages/_app-6a626577ffa902a4.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/pages/_error-1be831200e60c5c0.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-d4343f8c473d689d.js",revision:"EWvUMAZar8b7EDkgXgAVh"},{url:"/_next/static/css/0d5f6452b2682b9b.css",revision:"0d5f6452b2682b9b"},{url:"/_next/static/css/af880b2e4df9cb52.css",revision:"af880b2e4df9cb52"},{url:"/_next/static/media/46c21389e888bf13-s.woff2",revision:"272930c09ba14c81bb294be1fe18b049"},{url:"/_next/static/media/8888a3826f4a3af4-s.p.woff2",revision:"792477d09826b11d1e5a611162c9797a"},{url:"/_next/static/media/eafabf029ad39a43-s.p.woff2",revision:"43751174b6b810eb169101a20d8c26f8"},{url:"/_next/static/media/f5767adec246cdc1-s.woLine truncated