feat: toloka
This commit is contained in:
1 parent
f3b90f30c3
commit
be9a128793
11 files changed
+644
-58
No files matched your search
+89
@@ -0,0 +1,89 @@
|
||||
import { FC } from 'react';
|
||||
import { Cast, ListVideo, Magnet, Play } from 'lucide-react';
|
||||
|
||||
import { Quality } from '@/api/parsers/yts/models';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import { providers } from '../../../../constants';
|
||||
import { useCastMagnet, usePrefix } from '../../../../hooks/useMagnetHosts';
|
||||
import showPlayer from '../../../Player';
|
||||
|
||||
import useMagnet from './useMagnet';
|
||||
|
||||
interface Props {
|
||||
torrent: Torrent;
|
||||
backdrop: string;
|
||||
title: string;
|
||||
provider: string;
|
||||
}
|
||||
|
||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
const { mutateAsync, isPending } = useMagnet();
|
||||
|
||||
const supportedForStream = Boolean(
|
||||
(provider === providers.yts.key &&
|
||||
torrent.seeders &&
|
||||
[Quality.The1080P, Quality.The720P].includes(torrent.quality as Quality)) ||
|
||||
torrent.container?.includes('mp4')
|
||||
);
|
||||
|
||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
||||
|
||||
const prefetchMagnet = (handler: (magnet: string) => void) => () => {
|
||||
if (!torrent.download) return handler(torrent.magnet);
|
||||
|
||||
return mutateAsync(torrent.download).then((magnet) => handler(magnet));
|
||||
};
|
||||
|
||||
return (
|
||||
<ButtonsGroup className='ml-auto w-fit grow-0'>
|
||||
{supportedForStream && (
|
||||
<Button
|
||||
disabled={isPending}
|
||||
variant='destructive'
|
||||
className={cn('flex-grow-0 px-3 bg-red-600')}
|
||||
onClick={prefetchMagnet((magnet) => showPlayer({ magnet, backdrop, title }))}
|
||||
title='Play'
|
||||
>
|
||||
<Play size={15} />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
disabled={isPending}
|
||||
variant='outline'
|
||||
className='relative grow-0 px-3'
|
||||
title='Play using your native video player'
|
||||
onClick={prefetchMagnet((magnet) => {
|
||||
window.open(`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(magnet)}`);
|
||||
})}
|
||||
>
|
||||
<ListVideo size={20} />
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
className='relative grow-0 px-3'
|
||||
variant='outline'
|
||||
onClick={prefetchMagnet((magnet) => window.open(magnet))}
|
||||
title='Download magnet'
|
||||
>
|
||||
<Magnet size={20} />
|
||||
</Button>
|
||||
{supportedForCast && (
|
||||
<Button
|
||||
disabled={isPending}
|
||||
className='grow-0 px-3'
|
||||
variant='outline'
|
||||
onClick={prefetchMagnet((magnet) => cast(magnet))}
|
||||
>
|
||||
<Cast size={20} />
|
||||
</Button>
|
||||
)}
|
||||
</ButtonsGroup>
|
||||
);
|
||||
};
|
||||
|
||||
export default Actions;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { fetchTLKMagnet } from '@/api';
|
||||
|
||||
const useMagnet = () => {
|
||||
return useMutation({ mutationFn: fetchTLKMagnet });
|
||||
};
|
||||
|
||||
export default useMagnet;
|
||||
@@ -1,19 +1,13 @@
|
||||
import { FC, Fragment } from 'react';
|
||||
import { Cast, ListVideo, Magnet, Play } from 'lucide-react';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { Quality } from '@/api/parsers/yts/models';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import { providers } from '../../constants';
|
||||
import { useCastMagnet, usePrefix } from '../../hooks/useMagnetHosts';
|
||||
import showHostManagerModal from '../HostManager';
|
||||
import showPlayer from '../Player';
|
||||
import TableHeadSortable from '../TableHeadSortable';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
backdrop: string;
|
||||
@@ -26,9 +20,6 @@ interface Props {
|
||||
}
|
||||
|
||||
const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, provider, year, onChangeSort }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
|
||||
const colSpan = 5;
|
||||
|
||||
return (
|
||||
@@ -54,15 +45,6 @@ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, p
|
||||
|
||||
<TableBody>
|
||||
{torrents?.map((torrent) => {
|
||||
const supportedForStream = Boolean(
|
||||
(provider === providers.yts.key &&
|
||||
torrent.seeders &&
|
||||
[Quality.The1080P, Quality.The720P].includes(torrent.quality as Quality)) ||
|
||||
torrent.container?.includes('mp4')
|
||||
);
|
||||
|
||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
||||
|
||||
const yearView = torrent.year && year.toString() != torrent.year && `[${torrent.year}]`;
|
||||
|
||||
return (
|
||||
@@ -87,40 +69,7 @@ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, p
|
||||
</TableCell>
|
||||
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
|
||||
<TableCell className='p-1 pr-2 text-center'>
|
||||
<ButtonsGroup className='ml-auto w-fit grow-0'>
|
||||
{supportedForStream && (
|
||||
<Button
|
||||
variant='destructive'
|
||||
className={cn('flex-grow-0 px-3 bg-red-600')}
|
||||
onClick={() => showPlayer({ magnet: torrent.magnet, backdrop, title })}
|
||||
title='Play'
|
||||
>
|
||||
<Play size={15} />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant='outline'
|
||||
className='relative grow-0 px-3'
|
||||
title='Play using your native video player'
|
||||
>
|
||||
<a
|
||||
className='absolute left-0 top-0 size-full'
|
||||
href={`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(
|
||||
torrent.magnet
|
||||
)}`}
|
||||
/>
|
||||
<ListVideo size={20} />
|
||||
</Button>
|
||||
<Button className='relative grow-0 px-3' variant='outline' title='Download magnet'>
|
||||
<a className='absolute left-0 top-0 size-full' href={torrent.magnet} />
|
||||
<Magnet size={20} />
|
||||
</Button>
|
||||
{supportedForCast && (
|
||||
<Button className='grow-0 px-3' variant='outline' onClick={() => cast(torrent.magnet!)}>
|
||||
<Cast size={20} />
|
||||
</Button>
|
||||
)}
|
||||
</ButtonsGroup>
|
||||
<Actions title={title} backdrop={backdrop} torrent={torrent} provider={provider} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</Fragment>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { TPBTorrents, YTSTorrents } from '@/api';
|
||||
import { TLKTorrents, TPBTorrents, YTSTorrents } from '@/api';
|
||||
|
||||
export const providers = {
|
||||
yts: { label: 'YTS', key: 'yts', queryFn: YTSTorrents, sortable: false },
|
||||
tpb: { label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true }
|
||||
tpb: { label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true },
|
||||
tlk: { label: 'Toloka', key: 'tlk', queryFn: TLKTorrents, sortable: true }
|
||||
};
|
||||
@@ -34,6 +34,13 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
|
||||
key: providers.tpb.key,
|
||||
imdbID
|
||||
});
|
||||
const tlk = useTorrents({
|
||||
query: withYear ? `${title} ${year}` : title,
|
||||
queryFn: providers.tlk.queryFn,
|
||||
sort,
|
||||
key: providers.tlk.key,
|
||||
imdbID
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
@@ -43,6 +50,10 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
|
||||
{
|
||||
query: tpb,
|
||||
provider: providers.tpb
|
||||
},
|
||||
{
|
||||
query: tlk,
|
||||
provider: providers.tlk
|
||||
}
|
||||
];
|
||||
|
||||
@@ -65,7 +76,7 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
|
||||
</Button>
|
||||
</div>
|
||||
<Tabs value={providerKey} className='w-full rounded-none'>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{tabs.map(({ provider, query }) => (
|
||||
<TabsTrigger
|
||||
disabled={checkIsEmpty(query)}
|
||||
|
||||
Reference in new issue
Block a user