feat: favorite & watch lists
This commit is contained in:
1 parent
960a7a6242
commit
8858e47d38
51 files changed
+561
-290
No files matched your search
@@ -1,46 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import showTorrentsModal from '@/components/Show/components/Torrents';
|
||||
import ToggleTrailer from '@/components/Show/components/Trailer';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface Props {
|
||||
show: Show & Partial<Details>;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Actions = ({ onClose, show }: Props) => (
|
||||
<>
|
||||
<ToggleTrailer showType={show.type} showId={show.id}>
|
||||
{({ onPlay, disabled }) => (
|
||||
<Button className='h-8 w-1/2 grow' onClick={onPlay} disabled={disabled}>
|
||||
Trailer
|
||||
</Button>
|
||||
)}
|
||||
</ToggleTrailer>
|
||||
<Button
|
||||
className='h-8 w-1/2 grow'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
imdbID: show.imdb_id!,
|
||||
title: show.title,
|
||||
backdrop: show.backdrop,
|
||||
year: new Date(show.release).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Link
|
||||
className='flex w-1/2'
|
||||
href={`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className='h-8 grow'>Similar</Button>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
|
||||
export default Actions;
|
||||
@@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
import { Bookmark, Copy, Heart, Play, Star } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
|
||||
import showTorrentsModal from '@/components/Preview/components/Torrents';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import useShowState, { useMutateShowState } from '@/hooks/useShowState';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
show: Show & Partial<Details>;
|
||||
className: string;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Actions = ({ onClose, show, className }: Props) => {
|
||||
const state = useShowState({ showId: show.id, showType: show.type });
|
||||
const toggle = useMutateShowState(show);
|
||||
|
||||
const groupClassName = 'flex bg-input gap-[1px] rounded-md md:flex-grow-0 flex-grow';
|
||||
const leftClassName = 'h-8 gap-1 flex-grow border-r-0 rounded-none rounded-l-md md:px-3 px-2';
|
||||
const rightClassName = 'h-8 gap-1 flex-grow border-l-0 rounded-none rounded-r-md md:px-3 px-2';
|
||||
|
||||
return (
|
||||
<div className={cn('flex gap-2 flex-wrap md:flex-grow-0 flex-grow', className)}>
|
||||
<div className={cn(groupClassName, 'pointer-events-none')}>
|
||||
<Button className={leftClassName} variant='outline'>
|
||||
<Star size={14} />
|
||||
</Button>
|
||||
<Button className={rightClassName} variant='outline'>
|
||||
{show.rating.toFixed(1)}
|
||||
</Button>
|
||||
</div>
|
||||
<div className={groupClassName}>
|
||||
<Button
|
||||
className={leftClassName}
|
||||
variant='outline'
|
||||
disabled={toggle.list === 'favorite' && toggle.isPending}
|
||||
onClick={() => toggle.mutate({ list: 'favorite', value: !state?.favorite })}
|
||||
>
|
||||
<Heart size={14} className={cn({ 'fill-secondary-foreground': state?.favorite })} />
|
||||
</Button>
|
||||
<Button
|
||||
className={rightClassName}
|
||||
variant='outline'
|
||||
disabled={toggle.list === 'watchlist' && toggle.isPending}
|
||||
onClick={() => toggle.mutate({ list: 'watchlist', value: !state?.watchlist })}
|
||||
>
|
||||
<Bookmark size={14} className={cn({ 'fill-secondary-foreground': state?.watchlist })} />
|
||||
</Button>
|
||||
</div>
|
||||
<div className={cn(groupClassName, 'gap-0')}>
|
||||
<Link
|
||||
className='flex grow'
|
||||
href={`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className={leftClassName} variant='outline'>
|
||||
<Copy size={14} />
|
||||
Similar
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
className={cn(rightClassName, 'bg-red-600')}
|
||||
variant='destructive'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
imdbID: show.imdb_id!,
|
||||
title: show.title,
|
||||
backdrop: show.backdrop,
|
||||
year: new Date(show.release).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
<Play size={15} />
|
||||
Watch
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Actions;
|
||||
@@ -0,0 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
|
||||
import ScrollNavigation from '@/components/ScrollNavigation';
|
||||
|
||||
import useCredits from './useCredits';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
onPersonClick?: (id: string) => void;
|
||||
}
|
||||
|
||||
const Credits: FC<Props> = ({ showId, showType = 'movie', onPersonClick }) => {
|
||||
const { data: credits } = useCredits({ showId, showType });
|
||||
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
<ScrollNavigation<HTMLUListElement>>
|
||||
{(setRef) => (
|
||||
<ul
|
||||
ref={setRef}
|
||||
className='no-scrollbar flex animate-fade-aside-slide-in snap-x snap-mandatory gap-2 overflow-auto rounded-lg opacity-0'
|
||||
>
|
||||
{credits?.map((actor) => (
|
||||
<li
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
className='relative w-full max-w-[120px] shrink-0 cursor-pointer snap-start self-end bg-card text-card-foreground transition-shadow hover:shadow-lg'
|
||||
>
|
||||
<Link
|
||||
href={`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`}
|
||||
onClick={() => onPersonClick?.(actor.id.toString())}
|
||||
>
|
||||
<div className='overflow-hidden rounded-lg'>
|
||||
{actor.profile_path ? (
|
||||
<img height={180} width={120} src={actor.photoUrl} alt={actor.name} />
|
||||
) : (
|
||||
<div className='flex h-[180px] w-[120px] items-center justify-center rounded-lg'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className='absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 py-1 text-sm text-white'>
|
||||
<p className=' truncate'>{actor.name}</p>
|
||||
{Boolean(actor.character) && <p className='truncate'>{actor.character}</p>}
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</ScrollNavigation>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default Credits;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { credits } from '@/api';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
}
|
||||
|
||||
const useCredits = ({ showId, showType }: Props) => {
|
||||
return useQuery({
|
||||
queryKey: ['credits', showId, showType],
|
||||
queryFn: () => credits({ showId, showType }),
|
||||
enabled: Boolean(showId)
|
||||
});
|
||||
};
|
||||
|
||||
export default useCredits;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
||||
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
||||
|
||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||
const prefix = usePrefix();
|
||||
const setPrefix = useSetPrefix();
|
||||
|
||||
return (
|
||||
<Modal className='m-auto max-w-[200px] p-2' onClose={onReject}>
|
||||
<Input
|
||||
autoFocus
|
||||
placeholder='Enter address of your torrents streamer'
|
||||
value={prefix}
|
||||
className='focus-visible:ring-0'
|
||||
onChange={({ target: { value } }) => setPrefix(value)}
|
||||
onKeyDown={({ key }) => key === 'Enter' && onResolve(prefix)}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default showHostManagerModal;
|
||||
@@ -0,0 +1,53 @@
|
||||
'use client';
|
||||
|
||||
import { FC, useRef, useState } from 'react';
|
||||
import { MediaPlayer, MediaPlayerInstance, MediaProvider, Track, VideoSrc } from '@vidstack/react';
|
||||
import { PlyrLayout, plyrLayoutIcons } from '@vidstack/react/player/layouts/plyr';
|
||||
|
||||
import CaptionsMenu from './components/CaptionsMenu';
|
||||
import VideosMenu from './components/VideosMenu';
|
||||
|
||||
interface Props {
|
||||
subtitles: Source[];
|
||||
videos: Source[];
|
||||
onReady: () => void;
|
||||
}
|
||||
|
||||
const Player: FC<Props> = ({ videos, subtitles, onReady }) => {
|
||||
const [index, setIndex] = useState(0);
|
||||
|
||||
const player = useRef<MediaPlayerInstance>(null);
|
||||
|
||||
const source = videos[index];
|
||||
|
||||
return (
|
||||
<MediaPlayer
|
||||
autoPlay
|
||||
onCanPlay={onReady}
|
||||
load='eager'
|
||||
storage='movie-advisor'
|
||||
ref={player}
|
||||
src={(source as VideoSrc) || []}
|
||||
className='size-full'
|
||||
>
|
||||
<MediaProvider>
|
||||
{subtitles.map((track) => (
|
||||
<Track key={track.name} src={track.src} kind='subtitles' label={track.name} type='srt' default />
|
||||
))}
|
||||
</MediaProvider>
|
||||
<PlyrLayout
|
||||
icons={plyrLayoutIcons}
|
||||
slots={{
|
||||
playLargeButton: null,
|
||||
afterVolumeSlider: <ul className='w-2' />,
|
||||
beforeSettings: Boolean(subtitles.length) && <CaptionsMenu />,
|
||||
settings: videos.length > 1 && <VideosMenu source={source} sources={videos} onChange={setIndex} />,
|
||||
settingsMenu: null,
|
||||
captionsButton: null
|
||||
}}
|
||||
/>
|
||||
</MediaPlayer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Player;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { useActiveTextTrack, useCaptionOptions } from '@vidstack/react';
|
||||
import { ClosedCaptionsIcon, ClosedCaptionsOnIcon } from '@vidstack/react/icons';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import PlayerMenu from '../PlayerMenu';
|
||||
|
||||
const CaptionsMenu = () => {
|
||||
const track = useActiveTextTrack(['subtitles']);
|
||||
const tracks = useCaptionOptions();
|
||||
|
||||
return (
|
||||
<PlayerMenu
|
||||
options={tracks.map((track) => ({ label: track.label, onClick: () => track.select() }))}
|
||||
isChecked={({ label }) => (label === 'Off' ? !track : label === track?.label)}
|
||||
>
|
||||
{track ? (
|
||||
<ClosedCaptionsOnIcon className={cn('vds-icon !transform-none !size-5')} />
|
||||
) : (
|
||||
<ClosedCaptionsIcon className={cn('vds-icon !transform-none !size-5')} />
|
||||
)}
|
||||
<span className={cn('plyr__tooltip')}>Subtitles</span>
|
||||
</PlayerMenu>
|
||||
);
|
||||
};
|
||||
|
||||
export default CaptionsMenu;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { Menu } from '@vidstack/react';
|
||||
import { CheckIcon } from '@vidstack/react/icons';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
type Option = { onClick: () => void; label: string };
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
options: Option[];
|
||||
isChecked: (option: Option) => boolean;
|
||||
}
|
||||
|
||||
const PlayerMenu: FC<Props> = ({ children, options, isChecked }) => (
|
||||
<Menu.Root className={cn('plyr__menu')}>
|
||||
<Menu.Button className={cn('plyr__controls__item plyr__control')} aria-expanded={false}>
|
||||
{children}
|
||||
</Menu.Button>
|
||||
<Menu.Items
|
||||
className={cn('plyr__menu__container !p-0 max-h-52 overflow-auto no-scrollbar')}
|
||||
placement='top end'
|
||||
offset={0}
|
||||
>
|
||||
<Menu.RadioGroup>
|
||||
{options.map((option) => (
|
||||
<Menu.Radio
|
||||
key={option.label}
|
||||
title={option.label}
|
||||
className='!m-0 flex w-64 cursor-pointer items-center gap-2 truncate p-2'
|
||||
onClick={option.onClick}
|
||||
>
|
||||
<CheckIcon className={cn('vds-icon shrink-0', { invisible: !isChecked(option) })} size={16} />
|
||||
<span className='truncate'>{option.label}</span>
|
||||
</Menu.Radio>
|
||||
))}
|
||||
</Menu.RadioGroup>
|
||||
</Menu.Items>
|
||||
</Menu.Root>
|
||||
);
|
||||
|
||||
export default PlayerMenu;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { FC } from 'react';
|
||||
import { PlaylistIcon } from '@vidstack/react/icons';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import PlayerMenu from '../PlayerMenu';
|
||||
|
||||
interface Props {
|
||||
source: Source;
|
||||
sources: Source[];
|
||||
onChange: (index: number) => void;
|
||||
}
|
||||
|
||||
const VideosMenu: FC<Props> = ({ sources, source, onChange }) => (
|
||||
<PlayerMenu
|
||||
options={sources.map(({ name }, index) => ({ label: name, onClick: () => onChange(index) }))}
|
||||
isChecked={({ label }) => source.name === label}
|
||||
>
|
||||
<PlaylistIcon className={cn('vds-icon !transform-none')} />
|
||||
<span className={cn('plyr__tooltip')}>Playlist</span>
|
||||
</PlayerMenu>
|
||||
);
|
||||
|
||||
export default VideosMenu;
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { Loader } from 'lucide-react';
|
||||
import dynamic from 'next/dynamic';
|
||||
import Image from 'next/image';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
|
||||
import useFiles from './useFiles';
|
||||
|
||||
const Player = dynamic(() => import('./Player'));
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
magnet: string;
|
||||
backdrop: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => {
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
|
||||
const {
|
||||
data: { subtitles, videos },
|
||||
error,
|
||||
isFetched,
|
||||
isLoading
|
||||
} = useFiles(magnet);
|
||||
|
||||
const { toast } = useToast();
|
||||
|
||||
if (error) {
|
||||
toast({ description: 'Download Failed: unable to retrieve the video' });
|
||||
onResolve();
|
||||
}
|
||||
|
||||
if (isFetched && !videos.length) {
|
||||
toast({ description: 'This torrent doesn’t contain any compatible video files' });
|
||||
onResolve();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal className='overflow-hidden border-none bg-black p-0' onClose={onResolve}>
|
||||
<div className='relative w-full overflow-hidden pt-[56.25%]'>
|
||||
<div className='absolute left-0 top-0 size-full'>
|
||||
<Player subtitles={subtitles} videos={videos} onReady={() => setIsReady(true)} />
|
||||
</div>
|
||||
{(!isReady || isLoading) && (
|
||||
<div className='absolute left-0 top-0 size-full'>
|
||||
<img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />
|
||||
<div className='absolute left-0 top-0 flex size-full items-center justify-center bg-black/80'>
|
||||
<div className='animate-spin'>
|
||||
<Loader color='white' />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default showPlayer;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
export type Source = { name: string; src: string; type: string };
|
||||
type Sources = { subtitles: Source[]; videos: Source[] };
|
||||
|
||||
const useFiles = (magnet: string) => {
|
||||
const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?link=${encodeURIComponent(magnet)}`;
|
||||
|
||||
const query = useQuery<Stream>({
|
||||
queryKey: ['files', magnet],
|
||||
queryFn: () => fetch(`${STREAM_URL}&stat`).then((response) => response.json())
|
||||
});
|
||||
|
||||
return {
|
||||
...query,
|
||||
data: (query.data?.file_stats || []).reduce<Sources>(
|
||||
(sources, file) => {
|
||||
if (file.path.endsWith('.mp4')) {
|
||||
sources.videos.push({ src: `${STREAM_URL}&index=${file.id}&play`, name: file.path, type: 'video/mp4' });
|
||||
}
|
||||
|
||||
if (file.path.endsWith('.srt')) {
|
||||
sources.subtitles.push({ src: `${STREAM_URL}&index=${file.id}&play`, name: file.path, type: 'srt' });
|
||||
}
|
||||
|
||||
return sources;
|
||||
},
|
||||
{ subtitles: [], videos: [] }
|
||||
)
|
||||
};
|
||||
};
|
||||
|
||||
export default useFiles;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { FC } from 'react';
|
||||
import { CaretSortIcon } from '@radix-ui/react-icons';
|
||||
import { ArrowDownIcon } from 'lucide-react';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { TableHead } from '@/components/ui/table';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
sort: Sort;
|
||||
value: Sort;
|
||||
sortable: boolean;
|
||||
onChange: (sort: Sort) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const TableHeadSortable: FC<Props> = ({ title, sort, value, sortable, className, onChange }) => {
|
||||
const handleSort = !sortable ? undefined : () => onChange(value === Sort.seeds ? Sort.size : Sort.seeds);
|
||||
|
||||
return (
|
||||
<TableHead onClick={handleSort} className={cn('select-none px-2', sortable && 'cursor-pointer', className)}>
|
||||
<div className='flex items-center gap-1'>
|
||||
<span>{title}</span>
|
||||
{sortable &&
|
||||
(sort === value ? <ArrowDownIcon className='ml-2 size-4' /> : <CaretSortIcon className='ml-2 size-4' />)}
|
||||
</div>
|
||||
</TableHead>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableHeadSortable;
|
||||
@@ -0,0 +1,136 @@
|
||||
import { FC, Fragment } from 'react';
|
||||
import { Cast, Copy, ListVideo, Magnet, Play } from 'lucide-react';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { Quality } from '@/api/parsers/yts/models';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
|
||||
import { providers } from '../../constants';
|
||||
import { useCastMagnet, usePrefix } from '../../hooks/useMagnetHosts';
|
||||
import showHostManagerModal from '../HostManager';
|
||||
import showPlayer from '../Player';
|
||||
import TableHeadSortable from '../TableHeadSortable';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
backdrop: string;
|
||||
torrents: Torrent[];
|
||||
sort: Sort;
|
||||
sortable: boolean;
|
||||
provider: string;
|
||||
onChangeSort: (sort: Sort) => void;
|
||||
}
|
||||
|
||||
const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, provider, onChangeSort }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
|
||||
const colSpan = 5;
|
||||
|
||||
return (
|
||||
<Table className='overflow-hidden rounded-xl'>
|
||||
{Boolean(torrents?.length) && (
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className='hidden px-2 md:table-cell'>Title</TableHead>
|
||||
<TableHead className='hidden px-2 md:table-cell'>Resolution</TableHead>
|
||||
<TableHeadSortable sortable={sortable} title='Size' sort={Sort.size} value={sort} onChange={onChangeSort} />
|
||||
<TableHeadSortable
|
||||
sortable={sortable}
|
||||
title='Seeders'
|
||||
className='max-w-10'
|
||||
sort={Sort.seeds}
|
||||
value={sort}
|
||||
onChange={onChangeSort}
|
||||
/>
|
||||
<TableHead className='cursor-pointer select-none px-2' onClick={() => showHostManagerModal()} />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
)}
|
||||
|
||||
<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}');
|
||||
|
||||
return (
|
||||
<Fragment key={torrent.magnet + torrent.id}>
|
||||
<TableRow className='table-row border-b-0 md:hidden'>
|
||||
<TableCell className='break-all p-2' colSpan={colSpan}>
|
||||
<span className='flex w-full flex-wrap items-center gap-3'>
|
||||
{torrent.title} {torrent.year && `[${torrent.year}]`} {torrent.quality && `[${torrent.quality}]`}
|
||||
</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableCell className='hidden break-all p-2 md:table-cell' title={torrent.originalTitle}>
|
||||
{torrent.title} {torrent.year && `[${torrent.year}]`}{' '}
|
||||
<span className='uppercase'>{torrent.source && `[${torrent.source}]`}</span>
|
||||
</TableCell>
|
||||
<TableCell className='hidden p-2 md:table-cell'>
|
||||
<div className='flex shrink-0 items-center gap-1'>{torrent.quality}</div>
|
||||
</TableCell>
|
||||
<TableCell className='truncate p-2'>
|
||||
<div className='flex shrink-0 items-center gap-1'>{torrent.size}</div>
|
||||
</TableCell>
|
||||
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
|
||||
<TableCell className='p-1 pr-2 text-center'>
|
||||
<div className='no-scrollbar flex max-w-full justify-end gap-2 overflow-auto'>
|
||||
{supportedForStream && (
|
||||
<div
|
||||
className='flex size-8 cursor-pointer items-center justify-center rounded-lg border'
|
||||
onClick={() => showPlayer({ magnet: torrent.magnet, backdrop, title })}
|
||||
title='Play show'
|
||||
>
|
||||
<Play size={20} />
|
||||
</div>
|
||||
)}
|
||||
<a
|
||||
href={`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(
|
||||
torrent.magnet
|
||||
)}`}
|
||||
className='flex size-8 items-center justify-center rounded-lg border'
|
||||
title='Open using you native video player'
|
||||
>
|
||||
<ListVideo size={20} />
|
||||
</a>
|
||||
<a
|
||||
href={torrent.magnet}
|
||||
className='flex size-8 items-center justify-center rounded-lg border'
|
||||
title='Download magnet'
|
||||
>
|
||||
<Magnet size={20} />
|
||||
</a>
|
||||
<div
|
||||
className='flex size-8 cursor-pointer items-center justify-center rounded-lg border'
|
||||
onClick={() => navigator.clipboard.writeText(torrent.magnet)}
|
||||
title='Copy magnet into clipboard'
|
||||
>
|
||||
<Copy size={20} />
|
||||
</div>
|
||||
{supportedForCast && (
|
||||
<div
|
||||
onClick={() => cast(torrent.magnet!)}
|
||||
className='flex size-8 cursor-pointer items-center justify-center rounded-lg border'
|
||||
>
|
||||
<Cast size={20} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
|
||||
export default TorrentsTable;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { 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 }
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import showHostManagerModal from '@/components/Preview/components/Torrents/components/HostManager';
|
||||
|
||||
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
|
||||
unstable_getOnInit: true
|
||||
});
|
||||
|
||||
export const usePrefix = () => useAtomValue(magnetPrefixAtom);
|
||||
|
||||
export const useSetPrefix = () => useSetAtom(magnetPrefixAtom);
|
||||
|
||||
export const useCastMagnet = () => {
|
||||
const prefix = usePrefix();
|
||||
|
||||
return useCallback(
|
||||
(magnet: string) => {
|
||||
const open = (prefix: string) => {
|
||||
const link = window.open(`${prefix}${magnet}`, '_blank');
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
};
|
||||
|
||||
if (!prefix || prefix.includes('{host}')) return showHostManagerModal().then(open);
|
||||
|
||||
return Promise.resolve(open(prefix));
|
||||
},
|
||||
[prefix]
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,120 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { TabsContent } from '@radix-ui/react-tabs';
|
||||
import { Loader } from 'lucide-react';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
|
||||
import TorrentsTable from './components/TorrentsTable';
|
||||
import { providers } from './constants';
|
||||
import useTorrents from './useTorrents';
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
imdbID: string;
|
||||
title: string;
|
||||
year: number;
|
||||
backdrop: string;
|
||||
}
|
||||
|
||||
const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: Props) => {
|
||||
const [sort, setSort] = useState<Sort>(Sort.seeds);
|
||||
const [withYear, setWithYear] = useState(true);
|
||||
const [providerKey, setProviderKey] = useState(providers.yts.key);
|
||||
|
||||
const nextProviderKeyRef = useRef<string | null>(null);
|
||||
|
||||
const yts = useTorrents({ query: title, queryFn: providers.yts.queryFn, sort, key: providers.yts.key, imdbID });
|
||||
const tpb = useTorrents({
|
||||
query: withYear ? `${title} ${year}` : title,
|
||||
queryFn: providers.tpb.queryFn,
|
||||
sort,
|
||||
key: providers.tpb.key,
|
||||
imdbID
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
query: yts,
|
||||
provider: providers.yts
|
||||
},
|
||||
{
|
||||
query: tpb,
|
||||
provider: providers.tpb
|
||||
}
|
||||
];
|
||||
|
||||
const checkIsEmpty = (query: (typeof tabs)[number]['query']) =>
|
||||
query.isFetched && !query.isLoading && !query.data?.length;
|
||||
|
||||
useEffect(() => {
|
||||
if (!nextProviderKeyRef.current || providerKey === nextProviderKeyRef.current) return;
|
||||
|
||||
setProviderKey(nextProviderKeyRef.current);
|
||||
nextProviderKeyRef.current = null;
|
||||
}, [providerKey, yts.isFetched, tpb.isFetched]);
|
||||
|
||||
return (
|
||||
<Modal className='rounded-xl p-0 pb-1' onClose={onResolve}>
|
||||
<div className='grid grid-cols-[1fr_auto] items-center gap-3 p-2'>
|
||||
<span className='truncate text-base'>{title}</span>
|
||||
<Button className='h-6 p-2' variant={withYear ? 'default' : 'ghost'} onClick={() => setWithYear((w) => !w)}>
|
||||
{year}
|
||||
</Button>
|
||||
</div>
|
||||
<Tabs value={providerKey} className='w-full rounded-none'>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
{tabs.map(({ provider, query }) => (
|
||||
<TabsTrigger
|
||||
disabled={checkIsEmpty(query)}
|
||||
key={provider.key}
|
||||
value={provider.key}
|
||||
onClick={() => setProviderKey(provider.key)}
|
||||
>
|
||||
{provider.label}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ provider, query }, index) => {
|
||||
const nextIndex = index + 1;
|
||||
|
||||
const isEmpty = checkIsEmpty(query);
|
||||
|
||||
if (isEmpty && tabs[nextIndex]) {
|
||||
nextProviderKeyRef.current = tabs[nextIndex].provider.key;
|
||||
}
|
||||
|
||||
return (
|
||||
<TabsContent key={provider.key} value={provider.key}>
|
||||
<TorrentsTable
|
||||
title={title}
|
||||
backdrop={backdrop}
|
||||
sort={sort}
|
||||
sortable={provider.sortable}
|
||||
onChangeSort={setSort}
|
||||
provider={provider.key}
|
||||
torrents={query.data || []}
|
||||
/>
|
||||
|
||||
{(query.isLoading || query.isFetching) && (
|
||||
<div className='flex h-40 w-full items-center justify-center'>
|
||||
<Loader className='animate-spin' />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isEmpty && (
|
||||
<div className='flex h-40 w-full items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
);
|
||||
})}
|
||||
</Tabs>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default showTorrentsModal;
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
|
||||
const useTorrents = ({
|
||||
query,
|
||||
sort,
|
||||
imdbID,
|
||||
key,
|
||||
queryFn
|
||||
}: {
|
||||
key: string;
|
||||
query: string;
|
||||
sort: Sort;
|
||||
imdbID: string;
|
||||
queryFn: (params: { query: string; sort: Sort; imdbID: string }) => Promise<Torrent[]>;
|
||||
}) => {
|
||||
return useQuery({
|
||||
enabled: Boolean(query),
|
||||
queryKey: [key, query, sort, imdbID],
|
||||
queryFn: () => queryFn({ query, sort, imdbID })
|
||||
});
|
||||
};
|
||||
|
||||
export default useTorrents;
|
||||
@@ -3,11 +3,10 @@
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import Credits from '@/components/Preview/components/Credits';
|
||||
import useDetails from '@/components/Preview/useDetails';
|
||||
import Card from '@/components/Show';
|
||||
import Credits from '@/components/Show/components/Credits';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
@@ -16,30 +15,47 @@ interface Props {
|
||||
show?: Show;
|
||||
className?: string;
|
||||
onClose?: () => void;
|
||||
children?: ReactNode;
|
||||
card?: ReactNode;
|
||||
poster?: ReactNode;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ show: baseShow, className, onClose, children, card }) => {
|
||||
const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
|
||||
const { data: detailedShow } = useDetails({ showId: baseShow?.id, showType: baseShow?.type });
|
||||
|
||||
if (!baseShow) return null;
|
||||
|
||||
const show: (Show & Partial<Details>) | undefined = detailedShow || baseShow;
|
||||
|
||||
const isModal = Boolean(onClose);
|
||||
|
||||
return (
|
||||
<div className={cn('flex flex-col md:flex-row gap-2 rounded-xl', { 'p-2': Boolean(onClose) }, className)}>
|
||||
{card || <Card className='mx-auto' show={show} />}
|
||||
<div className='flex grow flex-col'>
|
||||
{children && <div className='mb-2 flex w-full gap-2 hover-none:hidden max-sm:mb-0'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions show={show} onClose={onClose} />
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col md:flex-row gap-2 rounded-xl',
|
||||
{ 'md:pl-0 md:pt-0 md:pb-0 pl-2 pt-2 pb-2 pr-2 border-none gap-0': isModal },
|
||||
className
|
||||
)}
|
||||
>
|
||||
{poster || <Poster className='mx-auto' rounded='md:rounded-none md:rounded-l-xl' show={show} />}
|
||||
<div className={cn('flex grow flex-col', { 'md:pb-2 md:pl-2 pb-0 pl-0 pt-2': isModal })}>
|
||||
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>
|
||||
|
||||
<div className='order-3 mb-4 flex w-full flex-wrap gap-5 whitespace-nowrap text-sm md:order-2'>
|
||||
<span>{new Date(show.release).getFullYear()}</span>
|
||||
{show.runtime && <span>{show.runtime} minutes</span>}
|
||||
<span>
|
||||
{show.genres
|
||||
?.slice(0, 3)
|
||||
.map(({ name }) => name)
|
||||
.join(' | ')}
|
||||
</span>
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p key={show.id} className='mb-3 leading-7'>
|
||||
|
||||
<Actions className='order-1 mb-4 mt-1 md:order-2 md:mt-0' show={show} onClose={onClose} />
|
||||
|
||||
<p key={show.id} className='order-4 md:order-4 md:line-clamp-3' title={show.overview}>
|
||||
{show.overview}
|
||||
</p>
|
||||
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
||||
<div className='order-5 mt-5 grid grid-cols-1 rounded-lg md:order-5 md:mt-auto'>
|
||||
<Credits showType={show.type} showId={show.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,10 +64,9 @@ const Preview: FC<Props> = ({ show: baseShow, className, onClose, children, card
|
||||
};
|
||||
|
||||
export const showPreviewModal = create(({ onResolve, onClose, show }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block p-0' onClose={onResolve}>
|
||||
<Modal className='block max-w-[932px] p-0' onClose={onResolve}>
|
||||
<Preview
|
||||
show={show}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
onClose?.();
|
||||
|
||||
Reference in new issue
Block a user