Merge branch 'main' of github.com:noisy5ilence/movie-advisor into main

This commit is contained in:
ner committed 2024-10-15 20:06:16 +03:00
commit 20d00ab61a
12 files changed
+175 -128

No files matched your search

@@ -2,7 +2,7 @@
import { FC, useRef, useState } from 'react';
import { MediaPlayer, MediaPlayerInstance, MediaProvider, Track, VideoSrc } from '@vidstack/react';
import { defaultLayoutIcons, DefaultVideoLayout } from '@vidstack/react/player/layouts/default';
import { PlyrLayout, plyrLayoutIcons } from '@vidstack/react/player/layouts/plyr';
import CaptionsMenu from './components/CaptionsMenu';
import VideosMenu from './components/VideosMenu';
@@ -10,10 +10,10 @@ import VideosMenu from './components/VideosMenu';
interface Props {
subtitles: Source[];
videos: Source[];
onClose: () => void;
onReady: () => void;
}
const Player: FC<Props> = ({ videos, subtitles }) => {
const Player: FC<Props> = ({ videos, subtitles, onReady }) => {
const [index, setIndex] = useState(0);
const player = useRef<MediaPlayerInstance>(null);
@@ -23,6 +23,7 @@ const Player: FC<Props> = ({ videos, subtitles }) => {
return (
<MediaPlayer
autoPlay
onCanPlay={onReady}
load='eager'
storage='movie-advisor'
ref={player}
@@ -34,17 +35,15 @@ const Player: FC<Props> = ({ videos, subtitles }) => {
<Track key={track.name} src={track.src} kind='subtitles' label={track.name} type='srt' default />
))}
</MediaProvider>
<DefaultVideoLayout
colorScheme='dark'
icons={defaultLayoutIcons}
<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,
captionButton: null,
googleCastButton: null,
beforeSettingsMenu: Boolean(videos.length > 1) && (
<VideosMenu source={source} sources={videos} onChange={setIndex} />
),
afterSettingsMenu: Boolean(subtitles.length) && <CaptionsMenu />
captionsButton: null
}}
/>
</MediaPlayer>
@@ -14,7 +14,12 @@ const CaptionsMenu = () => {
options={tracks.map((track) => ({ label: track.label, onClick: () => track.select() }))}
isChecked={({ label }) => (label === 'Off' ? !track : label === track?.label)}
>
{track ? <ClosedCaptionsOnIcon className={cn('vds-icon')} /> : <ClosedCaptionsIcon className={cn('vds-icon')} />}
{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>
);
};
@@ -13,17 +13,17 @@ interface Props {
}
const PlayerMenu: FC<Props> = ({ children, options, isChecked }) => (
<Menu.Root className={cn('vds-menu')}>
<Menu.Button className={cn('vds-menu-button vds-button')} aria-label='Settings'>
<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('vds-menu-items !p-2')} placement='top end' offset={0}>
<Menu.Items className={cn('plyr__menu__container !p-0')} placement='top end' offset={0}>
<Menu.RadioGroup>
{options.map((option) => (
<Menu.Radio
key={option.label}
title={option.label}
className='flex w-64 cursor-pointer items-center gap-2 truncate p-2'
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} />
@@ -16,7 +16,8 @@ const VideosMenu: FC<Props> = ({ sources, source, onChange }) => (
options={sources.map(({ name }, index) => ({ label: name, onClick: () => onChange(index) }))}
isChecked={({ label }) => source.name === label}
>
<PlaylistIcon className={cn('vds-icon')} />
<PlaylistIcon className={cn('vds-icon !transform-none')} />
<span className={cn('plyr__tooltip')}>Playlist</span>
</PlayerMenu>
);
@@ -1,4 +1,6 @@
import { useState } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import { Loader } from 'lucide-react';
import dynamic from 'next/dynamic';
import { Modal } from '@/components/ui/dialog';
@@ -15,14 +17,22 @@ interface Props extends InstanceProps<void> {
}
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();
@@ -32,9 +42,18 @@ const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => {
<Modal className='overflow-hidden rounded-lg 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} onClose={onResolve} />
<Player subtitles={subtitles} videos={videos} onReady={() => setIsReady(true)} />
</div>
{isLoading && <img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />}
{(!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>
);
@@ -12,13 +12,14 @@ interface Props {
value: Sort;
sortable: boolean;
onChange: (sort: Sort) => void;
className?: string;
}
const TableHeadSortable: FC<Props> = ({ title, sort, value, sortable, onChange }) => {
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')}>
<TableHead onClick={handleSort} className={cn('select-none px-2', sortable && 'cursor-pointer', className)}>
<div className='flex items-center gap-1'>
<span>{title}</span>
{sortable &&
+11 -4
View File
@@ -83,7 +83,14 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
<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={setSort} />
<TableHeadSortable sortable={sortable} title='Seeders' sort={Sort.seeds} value={sort} onChange={setSort} />
<TableHeadSortable
sortable={sortable}
title='Seeders'
className='max-w-10'
sort={Sort.seeds}
value={sort}
onChange={setSort}
/>
<TableHead className='cursor-pointer select-none px-2' onClick={() => showHostManagerModal()} />
</TableRow>
</TableHeader>
@@ -116,12 +123,12 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
<TableCell className='hidden p-2 md:table-cell'>
<div className='flex shrink-0 items-center gap-1'>{torrent.quality}</div>
</TableCell>
<TableCell className='p-2'>
<TableCell className='truncate p-2'>
<div className='flex shrink-0 items-center gap-1'>{torrent.size}</div>
</TableCell>
<TableCell className='p-2'>{torrent.seeders}</TableCell>
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
<TableCell className='p-1 pr-2 text-center'>
<div className='flex justify-end gap-2'>
<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'