feat(torrents): pass show metadata to m3u stream request
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f447cf3423
commit
c77dcf913d
4 files changed
+59
-44
No files matched your search
@@ -92,12 +92,7 @@ const Actions = ({ show, className, externalLink }: Props) => {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const showTorrentsModal = (await import('../Torrents')).default;
|
const showTorrentsModal = (await import('../Torrents')).default;
|
||||||
|
|
||||||
showTorrentsModal({
|
showTorrentsModal(show);
|
||||||
imdbID: show.imdb_id!,
|
|
||||||
title: show.title,
|
|
||||||
backdrop: show.backdrop,
|
|
||||||
year: new Date(show.release).getFullYear()
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Play size={15} />
|
<Play size={15} />
|
||||||
|
|||||||
+36
-10
@@ -1,4 +1,4 @@
|
|||||||
import { FC, useMemo } from 'react';
|
import { FC, useMemo, useState } from 'react';
|
||||||
import { Cast, Download, ListVideo, Loader, Magnet, Play, TrafficCone } from 'lucide-react';
|
import { Cast, Download, ListVideo, Loader, Magnet, Play, TrafficCone } from 'lucide-react';
|
||||||
|
|
||||||
import { providers } from '@/components/Preview/components/Torrents/constants';
|
import { providers } from '@/components/Preview/components/Torrents/constants';
|
||||||
@@ -14,17 +14,18 @@ import showPlayerModal from './components/Player';
|
|||||||
import useMagnet from './useMagnet';
|
import useMagnet from './useMagnet';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
show: Show & Partial<Details>;
|
||||||
torrent: Torrent;
|
torrent: Torrent;
|
||||||
backdrop: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
provider: string;
|
provider: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
const Actions: FC<Props> = ({ torrent, title, provider, show }) => {
|
||||||
const prefix = usePrefix();
|
const prefix = usePrefix();
|
||||||
const cast = useCastMagnet();
|
const cast = useCastMagnet();
|
||||||
const streamUrl = useStreamUrl();
|
const streamUrl = useStreamUrl();
|
||||||
const M3UUrl = useM3UUrl();
|
const M3UUrl = useM3UUrl();
|
||||||
|
const [isStreamPending, setIsStreamPending] = useState(false);
|
||||||
|
|
||||||
const isStandalone = isStandaloneApp();
|
const isStandalone = isStandaloneApp();
|
||||||
|
|
||||||
@@ -53,11 +54,24 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
|||||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
const supportedForCast = prefix && !prefix.includes('{host}');
|
||||||
|
|
||||||
const handleM3ULink = () => {
|
const handleM3ULink = () => {
|
||||||
const link = window.open(
|
setIsStreamPending(true);
|
||||||
`${M3UUrl}${encodeURIComponent(`${streamUrl}/stream?m3u&link=${encodeURIComponent(magnet)}`)}`,
|
|
||||||
'_blank'
|
const params = new URLSearchParams({
|
||||||
);
|
m3u: `${streamUrl}/stream?m3u&link=${magnet}`,
|
||||||
setTimeout(() => link?.close(), 1000);
|
poster: show.poster['2x'],
|
||||||
|
backdrop: show.backdrop,
|
||||||
|
type: show.type,
|
||||||
|
name: show.title,
|
||||||
|
imdb_id: show.imdb_id ?? '',
|
||||||
|
year: new Date(show.release).getFullYear().toString(),
|
||||||
|
runtime: show.runtime?.toString() ?? ''
|
||||||
|
});
|
||||||
|
|
||||||
|
fetch(`${M3UUrl}?${params}`, {
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => setIsStreamPending(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -71,7 +85,7 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
|||||||
'hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600'
|
'hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600'
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
showPlayerModal({ backdrop, title, hash, magnet });
|
showPlayerModal({ backdrop: show.backdrop, title, hash, magnet });
|
||||||
}}
|
}}
|
||||||
title='Play'
|
title='Play'
|
||||||
>
|
>
|
||||||
@@ -92,8 +106,20 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
|||||||
<Magnet size={20} />
|
<Magnet size={20} />
|
||||||
</Button>
|
</Button>
|
||||||
{M3UUrl ? (
|
{M3UUrl ? (
|
||||||
<Button className='relative grow-0 px-3' variant='outline' title='Play m3u playlist' onClick={handleM3ULink}>
|
<Button
|
||||||
|
className='relative h-[32px] w-[45px] grow-0 px-3'
|
||||||
|
variant='outline'
|
||||||
|
title='Play m3u playlist'
|
||||||
|
onClick={handleM3ULink}
|
||||||
|
disabled={isStreamPending}
|
||||||
|
>
|
||||||
|
{isStreamPending ? (
|
||||||
|
<div className='animate-spin'>
|
||||||
|
<Loader size={18} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<Cast size={20} />
|
<Cast size={20} />
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
supportedForCast && (
|
supportedForCast && (
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ import TableHeadSortable from '../TableHeadSortable';
|
|||||||
|
|
||||||
import Actions from './components/Actions';
|
import Actions from './components/Actions';
|
||||||
|
|
||||||
interface Props {
|
type Props = {
|
||||||
|
show: Show & Partial<Details>;
|
||||||
title: string;
|
title: string;
|
||||||
backdrop: string;
|
|
||||||
torrents: Torrent[];
|
torrents: Torrent[];
|
||||||
sort: Sort;
|
sort: Sort;
|
||||||
sortable: boolean;
|
sortable: boolean;
|
||||||
provider: string;
|
provider: string;
|
||||||
year: number;
|
|
||||||
onChangeSort: (sort: Sort) => void;
|
onChangeSort: (sort: Sort) => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, provider, year, onChangeSort }) => {
|
const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provider, onChangeSort }) => {
|
||||||
const colSpan = 5;
|
const colSpan = 5;
|
||||||
|
const year = new Date(show.release).getFullYear();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table className='overflow-hidden rounded-xl'>
|
<Table className='overflow-hidden rounded-xl'>
|
||||||
@@ -68,7 +68,7 @@ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, p
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
|
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
|
||||||
<TableCell className='p-1 pr-2 text-center'>
|
<TableCell className='p-1 pr-2 text-center'>
|
||||||
<Actions title={title} backdrop={backdrop} torrent={torrent} provider={provider} />
|
<Actions show={show} title={title} torrent={torrent} provider={provider} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { TabsContent } from '@radix-ui/react-tabs';
|
|||||||
import { Loader } from 'lucide-react';
|
import { Loader } from 'lucide-react';
|
||||||
import { Search } from 'lucide-react';
|
import { Search } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
@@ -15,42 +16,36 @@ import TorrentsTable from './components/TorrentsTable';
|
|||||||
import { providers } from './constants';
|
import { providers } from './constants';
|
||||||
import useTorrents from './useTorrents';
|
import useTorrents from './useTorrents';
|
||||||
|
|
||||||
interface Props extends InstanceProps<void> {
|
type Props = InstanceProps<void> & Show & Partial<Details>;
|
||||||
imdbID: string;
|
|
||||||
title: string;
|
|
||||||
year: number;
|
|
||||||
backdrop: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop, onResolve }: Props) => {
|
const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
|
||||||
const [sort, setSort] = useState<Sort>(Sort.seeds);
|
const [sort, setSort] = useState<Sort>(Sort.seeds);
|
||||||
|
|
||||||
const initialQuery = `${initialTitle} ${year}`;
|
const [manualQuery, setManualQuery] = useState(show.title);
|
||||||
|
const [query, setQuery] = useState(manualQuery);
|
||||||
|
|
||||||
const [title, setTitle] = useState(initialQuery);
|
const year = new Date(show.release).getFullYear();
|
||||||
|
|
||||||
const [query, setQuery] = useState(title);
|
|
||||||
|
|
||||||
const yts = useTorrents({
|
const yts = useTorrents({
|
||||||
query: initialTitle,
|
query: show.title,
|
||||||
queryFn: providers.yts.queryFn,
|
queryFn: providers.yts.queryFn,
|
||||||
sort,
|
sort,
|
||||||
key: providers.yts.key,
|
key: providers.yts.key,
|
||||||
imdbID
|
imdbID: show.imdb_id!
|
||||||
});
|
});
|
||||||
const tpb = useTorrents({
|
const tpb = useTorrents({
|
||||||
query,
|
query,
|
||||||
queryFn: providers.tpb.queryFn,
|
queryFn: providers.tpb.queryFn,
|
||||||
sort,
|
sort,
|
||||||
key: providers.tpb.key,
|
key: providers.tpb.key,
|
||||||
imdbID
|
imdbID: show.imdb_id!
|
||||||
});
|
});
|
||||||
const tlk = useTorrents({
|
const tlk = useTorrents({
|
||||||
query,
|
query,
|
||||||
queryFn: providers.tlk.queryFn,
|
queryFn: providers.tlk.queryFn,
|
||||||
sort,
|
sort,
|
||||||
key: providers.tlk.key,
|
key: providers.tlk.key,
|
||||||
imdbID
|
imdbID: show.imdb_id!
|
||||||
});
|
});
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
@@ -71,7 +66,7 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
|||||||
const handleSearch = (event: FormEvent) => {
|
const handleSearch = (event: FormEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
setQuery(title || initialQuery);
|
setQuery(manualQuery);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkIsEmpty = (query: (typeof tabs)[number]['query']) =>
|
const checkIsEmpty = (query: (typeof tabs)[number]['query']) =>
|
||||||
@@ -83,14 +78,14 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
|||||||
<ButtonsGroup className='h-10'>
|
<ButtonsGroup className='h-10'>
|
||||||
<Input
|
<Input
|
||||||
className='h-full'
|
className='h-full'
|
||||||
value={title}
|
value={manualQuery}
|
||||||
onChange={({ target }) => setTitle(target.value)}
|
onChange={({ target: { value } }) => setManualQuery(value)}
|
||||||
placeholder='Start typing title...'
|
placeholder='Start typing title...'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
type='submit'
|
type='submit'
|
||||||
className='h-full !px-3 transition-all duration-200 hover:bg-secondary-foreground hover:shadow-lg hover:shadow-secondary-foreground/60'
|
className='h-full !px-3 transition-all duration-200 hover:bg-secondary-foreground hover:shadow-lg hover:shadow-secondary-foreground/60'
|
||||||
disabled={initialQuery === title || tpb.isPending || tlk.isPending}
|
disabled={tpb.isPending || tlk.isPending}
|
||||||
>
|
>
|
||||||
<Search size={16} />
|
<Search size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -110,9 +105,8 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
|||||||
return (
|
return (
|
||||||
<TabsContent className='pb-1' key={provider.key} value={provider.key}>
|
<TabsContent className='pb-1' key={provider.key} value={provider.key}>
|
||||||
<TorrentsTable
|
<TorrentsTable
|
||||||
year={year}
|
show={show}
|
||||||
title={title}
|
title={show.title}
|
||||||
backdrop={backdrop}
|
|
||||||
sort={sort}
|
sort={sort}
|
||||||
sortable={provider.sortable}
|
sortable={provider.sortable}
|
||||||
onChangeSort={setSort}
|
onChangeSort={setSort}
|
||||||
|
|||||||
Reference in new issue
Block a user