feat: YTS torrents provider
This commit is contained in:
1 parent
c256b7fb7c
commit
4b262bc1d6
9 files changed
+308
-59
No files matched your search
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
@@ -14,8 +14,6 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function Actions({ onClose, movie, type }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ToggleTrailer type={type} movieId={movie?.id}>
|
||||
@@ -29,6 +27,8 @@ export default function Actions({ onClose, movie, type }: Props) {
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
id: movie.id,
|
||||
type: type as ShowType,
|
||||
title: movie?.name || movie.title,
|
||||
year: new Date(movie.first_air_date || movie.release_date).getFullYear()
|
||||
})
|
||||
@@ -36,17 +36,13 @@ export default function Actions({ onClose, movie, type }: Props) {
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Button
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie?.name || movie.title)}&type=${type}`
|
||||
);
|
||||
onClose?.();
|
||||
}}
|
||||
<Link
|
||||
className='flex w-[50%]'
|
||||
href={`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie?.name || movie.title)}&type=${type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
Similar
|
||||
</Button>
|
||||
<Button className='h-8 flex-grow'>Similar</Button>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,65 +1,72 @@
|
||||
import React, { Dispatch, FC, Fragment, SetStateAction, useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { ArrowDownIcon, CaretSortIcon } from '@radix-ui/react-icons';
|
||||
import { Cast, Copy,Loader, Magnet } from 'lucide-react';
|
||||
import { Cast, Copy, Loader, Magnet } from 'lucide-react';
|
||||
|
||||
import useTorrents from '@/app/(site)/useTorrents';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Toggle } from '@/components/ui/toggle';
|
||||
import { useCastMagnet, usePrefix } from '@/hooks/useMagnetHosts';
|
||||
import { ORDER } from '@/lib/api/parsers/pirate-bay';
|
||||
import { TPBTorrents, YTSTorrents } from '@/lib/api';
|
||||
import { Sort } from '@/lib/api/parsers';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import showHostManagerModal from './HostManager';
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
id: number;
|
||||
type: ShowType;
|
||||
title: string;
|
||||
year: number;
|
||||
}
|
||||
|
||||
type Sorting = {
|
||||
by: ORDER;
|
||||
};
|
||||
|
||||
const TableHeadSortable = ({
|
||||
title,
|
||||
by,
|
||||
value,
|
||||
onChange
|
||||
}: {
|
||||
const TableHeadSortable: FC<{
|
||||
title: string;
|
||||
by: Sorting['by'];
|
||||
value: Sorting;
|
||||
onChange: Dispatch<SetStateAction<Sorting>>;
|
||||
}) => {
|
||||
sort: Sort;
|
||||
value: Sort;
|
||||
sortable: boolean;
|
||||
onChange: Dispatch<SetStateAction<Sort>>;
|
||||
}> = ({ title, sort, value, onChange, sortable }) => {
|
||||
return (
|
||||
<TableHead
|
||||
onClick={() =>
|
||||
onChange((sorting) => ({
|
||||
by: sorting.by === ORDER.seeders ? ORDER.size : ORDER.seeders
|
||||
}))
|
||||
}
|
||||
className='cursor-pointer select-none px-2'
|
||||
onClick={!sortable ? undefined : () => onChange((sort) => (sort === Sort.seeds ? Sort.size : Sort.seeds))}
|
||||
className={cn('select-none px-2', sortable && 'cursor-pointer')}
|
||||
>
|
||||
<div className='flex gap-1 items-center'>
|
||||
<span>{title}</span>
|
||||
{value.by === by ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />}
|
||||
{sortable &&
|
||||
(sort === value ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />)}
|
||||
</div>
|
||||
</TableHead>
|
||||
);
|
||||
};
|
||||
|
||||
const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
const providers = [
|
||||
{ label: 'YTS', key: 'yts', queryFn: YTSTorrents, sortable: false },
|
||||
{ label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true }
|
||||
];
|
||||
|
||||
const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
const isMobile = matchMedia('(max-width: 600px)').matches;
|
||||
const prefix = usePrefix();
|
||||
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
||||
const [sorting, setSorting] = useState<Sort>(Sort.seeds);
|
||||
const [withYear, setWithYear] = useState(true);
|
||||
const [{ key, queryFn, sortable }, setProvider] = useState(providers[0]);
|
||||
|
||||
const {
|
||||
data: torrents,
|
||||
isLoading,
|
||||
isFetched
|
||||
} = useTorrents({ query: withYear ? `${title} ${year || ''}` : title, order: sorting.by });
|
||||
} = useTorrents({
|
||||
query: withYear ? `${title} ${year || ''}` : title,
|
||||
sort: sorting,
|
||||
id,
|
||||
type,
|
||||
key,
|
||||
queryFn
|
||||
});
|
||||
|
||||
const cast = useCastMagnet();
|
||||
|
||||
@@ -67,7 +74,7 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
<Modal className='p-0' onClose={onResolve}>
|
||||
<Table className='rounded-xl overflow-hidden'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableRow className='!border-b-0'>
|
||||
<TableHead className='px-2' colSpan={4}>
|
||||
<div className='grid grid-cols-[1fr_auto] items-center gap-3'>
|
||||
<span className='overflow-ellipsis overflow-hidden text-base whitespace-nowrap'>{title}</span>
|
||||
@@ -82,10 +89,35 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
</div>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
<TableRow className='!border-b-0'>
|
||||
<th colSpan={5}>
|
||||
<Tabs defaultValue={key} value={key} className='w-full rounded-none'>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
{providers.map((provider) => (
|
||||
<TabsTrigger key={provider.key} value={provider.key} onClick={() => setProvider(provider)}>
|
||||
{provider.label}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</th>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
{!isMobile && <TableHead className='px-2'>Title</TableHead>}
|
||||
<TableHeadSortable title='Size' by={ORDER.size} value={sorting} onChange={setSorting} />
|
||||
<TableHeadSortable title='Seeders' by={ORDER.seeders} value={sorting} onChange={setSorting} />
|
||||
<TableHeadSortable
|
||||
sortable={sortable}
|
||||
title='Size'
|
||||
sort={Sort.size}
|
||||
value={sorting}
|
||||
onChange={setSorting}
|
||||
/>
|
||||
<TableHeadSortable
|
||||
sortable={sortable}
|
||||
title='Seeders'
|
||||
sort={Sort.seeds}
|
||||
value={sorting}
|
||||
onChange={setSorting}
|
||||
/>
|
||||
<TableHead className='px-2 cursor-pointer select-none' onClick={() => showHostManagerModal()} />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -138,7 +170,7 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{isFetched && !torrents?.length && (
|
||||
{!isLoading && isFetched && !torrents?.length && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
|
||||
Reference in new issue
Block a user