feat(torrents): series parsing, S:E/Year columns, magnet cache
- parse Toloka Ukrainian season/episode naming (Сезони 1-10, серій 7 з 8, homoglyphs) into a clean title + episodes field - add series-only sortable S:E column, desktop-only Year column; strip year/source meta from the title cell - filter out torrents with fewer than 5 seeders in the API route - cache Toloka magnets in Redis so each .torrent is downloaded once across serverless instances; append public trackers to magnets (never the passkey-bearing announce URLs from the .torrent) - fix play button hover state while magnet is pending Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
131beeb07f
commit
2e81908b22
9 files changed
+163
-34
No files matched your search
+1
-1
@@ -86,7 +86,7 @@ const Actions: FC<Props> = ({ torrent, title, provider, show }) => {
|
||||
className={cn(
|
||||
'flex-grow-0 px-3 bg-red-600',
|
||||
'hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600',
|
||||
{ 'bg-transparent': !magnet || fetchMagnet.isPending }
|
||||
{ invisible: !magnet || fetchMagnet.isPending }
|
||||
)}
|
||||
onClick={() => {
|
||||
showPlayerModal({ backdrop: show.backdrop, title, hash, magnet });
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import { FC, Fragment } from 'react';
|
||||
import { FC, Fragment, useState } from 'react';
|
||||
import { ArrowDownIcon } from 'lucide-react';
|
||||
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Sort } from '@/data/parsers';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import showHostManagerModal from '../HostManager';
|
||||
import TableHeadSortable from '../TableHeadSortable';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
|
||||
type EpisodesSort = 'asc' | 'desc';
|
||||
|
||||
// "S3:E7/8" -> [3, 7]; "S1-9" -> [1, 0]; missing info sorts last
|
||||
const seasonEpisode = (episodes?: string): [number, number] => [
|
||||
Number(episodes?.match(/S(\d+)/)?.[1] ?? 9999),
|
||||
Number(episodes?.match(/E(\d+)/)?.[1] ?? 0)
|
||||
];
|
||||
|
||||
type Props = {
|
||||
show: Show & Partial<Details>;
|
||||
title: string;
|
||||
@@ -19,8 +29,28 @@ type Props = {
|
||||
};
|
||||
|
||||
const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provider, onChangeSort }) => {
|
||||
const colSpan = 5;
|
||||
const year = new Date(show.release).getFullYear();
|
||||
const isSeries = show.type === 'tv';
|
||||
const colSpan = 7;
|
||||
|
||||
const [episodesSort, setEpisodesSort] = useState<EpisodesSort | null>(null);
|
||||
|
||||
const rows = episodesSort
|
||||
? [...torrents].sort((a, b) => {
|
||||
const [seasonA, episodeA] = seasonEpisode(a.episodes);
|
||||
const [seasonB, episodeB] = seasonEpisode(b.episodes);
|
||||
const diff = seasonA - seasonB || episodeA - episodeB;
|
||||
|
||||
return episodesSort === 'asc' ? diff : -diff;
|
||||
})
|
||||
: torrents;
|
||||
|
||||
// server sort (size/seeds) refetches in a new order, so drop the client-side S:E sort
|
||||
const handleChangeSort = (next: Sort) => {
|
||||
setEpisodesSort(null);
|
||||
onChangeSort(next);
|
||||
};
|
||||
|
||||
const toggleEpisodesSort = () => setEpisodesSort((current) => (current === 'asc' ? 'desc' : 'asc'));
|
||||
|
||||
return (
|
||||
<Table className='overflow-hidden rounded-xl'>
|
||||
@@ -28,15 +58,32 @@ const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provi
|
||||
<TableHeader>
|
||||
<TableRow className='hover:bg-transparent'>
|
||||
<TableHead className='hidden px-2 md:table-cell'>Title</TableHead>
|
||||
{isSeries && (
|
||||
<TableHead className='hidden cursor-pointer select-none px-2 md:table-cell' onClick={toggleEpisodesSort}>
|
||||
<div className='flex items-center gap-1'>
|
||||
<span>S:E</span>
|
||||
{episodesSort && (
|
||||
<ArrowDownIcon className={cn('ml-2 size-4 shrink-0', episodesSort === 'asc' && 'rotate-180')} />
|
||||
)}
|
||||
</div>
|
||||
</TableHead>
|
||||
)}
|
||||
<TableHead className='hidden px-2 lg:table-cell'>Year</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='Size'
|
||||
sort={Sort.size}
|
||||
value={sort}
|
||||
onChange={handleChangeSort}
|
||||
/>
|
||||
<TableHeadSortable
|
||||
sortable={sortable}
|
||||
title='Seeders'
|
||||
className='max-w-10'
|
||||
sort={Sort.seeds}
|
||||
value={sort}
|
||||
onChange={onChangeSort}
|
||||
onChange={handleChangeSort}
|
||||
/>
|
||||
<TableHead className='cursor-pointer select-none px-2' onClick={() => showHostManagerModal()} />
|
||||
</TableRow>
|
||||
@@ -44,21 +91,28 @@ const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provi
|
||||
)}
|
||||
|
||||
<TableBody>
|
||||
{torrents?.map((torrent) => {
|
||||
const yearView = torrent.year && year.toString() != torrent.year && `[${torrent.year}]`;
|
||||
{rows?.map((torrent) => {
|
||||
return (
|
||||
<Fragment key={torrent.magnet + torrent.id + torrent.download}>
|
||||
<TableRow className='table-row border-b-0 hover:bg-transparent md:hidden'>
|
||||
<TableCell className='break-all p-2' colSpan={colSpan}>
|
||||
<span className='flex w-full flex-wrap items-center gap-3'>
|
||||
{torrent.title} {yearView} {torrent.quality && `[${torrent.quality}]`}
|
||||
{torrent.title} {isSeries && torrent.episodes && `[${torrent.episodes}]`}{' '}
|
||||
{torrent.quality && `[${torrent.quality}]`}
|
||||
</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow className='hover:bg-transparent'>
|
||||
<TableCell className='hidden break-all p-2 md:table-cell' title={torrent.originalTitle}>
|
||||
{torrent.title} {yearView}{' '}
|
||||
<span className='uppercase'>{torrent.source && `[${torrent.source}]`}</span>
|
||||
{torrent.title}
|
||||
</TableCell>
|
||||
{isSeries && (
|
||||
<TableCell className='hidden p-2 md:table-cell'>
|
||||
<div className='flex shrink-0 items-center gap-1'>{torrent.episodes}</div>
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell className='hidden p-2 lg:table-cell'>
|
||||
<div className='flex shrink-0 items-center gap-1'>{torrent.year}</div>
|
||||
</TableCell>
|
||||
<TableCell className='hidden p-2 md:table-cell'>
|
||||
<div className='flex shrink-0 items-center gap-1'>{torrent.quality}</div>
|
||||
|
||||
Reference in new issue
Block a user