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
+60
-45
No files matched your search
@@ -92,12 +92,7 @@ const Actions = ({ show, className, externalLink }: Props) => {
|
||||
onClick={async () => {
|
||||
const showTorrentsModal = (await import('../Torrents')).default;
|
||||
|
||||
showTorrentsModal({
|
||||
imdbID: show.imdb_id!,
|
||||
title: show.title,
|
||||
backdrop: show.backdrop,
|
||||
year: new Date(show.release).getFullYear()
|
||||
});
|
||||
showTorrentsModal(show);
|
||||
}}
|
||||
>
|
||||
<Play size={15} />
|
||||
|
||||
+37
-11
@@ -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 { providers } from '@/components/Preview/components/Torrents/constants';
|
||||
@@ -14,17 +14,18 @@ import showPlayerModal from './components/Player';
|
||||
import useMagnet from './useMagnet';
|
||||
|
||||
interface Props {
|
||||
show: Show & Partial<Details>;
|
||||
torrent: Torrent;
|
||||
backdrop: string;
|
||||
title: string;
|
||||
provider: string;
|
||||
}
|
||||
|
||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
const Actions: FC<Props> = ({ torrent, title, provider, show }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
const streamUrl = useStreamUrl();
|
||||
const M3UUrl = useM3UUrl();
|
||||
const [isStreamPending, setIsStreamPending] = useState(false);
|
||||
|
||||
const isStandalone = isStandaloneApp();
|
||||
|
||||
@@ -53,11 +54,24 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
||||
|
||||
const handleM3ULink = () => {
|
||||
const link = window.open(
|
||||
`${M3UUrl}${encodeURIComponent(`${streamUrl}/stream?m3u&link=${encodeURIComponent(magnet)}`)}`,
|
||||
'_blank'
|
||||
);
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
setIsStreamPending(true);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
m3u: `${streamUrl}/stream?m3u&link=${magnet}`,
|
||||
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 (
|
||||
@@ -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'
|
||||
)}
|
||||
onClick={() => {
|
||||
showPlayerModal({ backdrop, title, hash, magnet });
|
||||
showPlayerModal({ backdrop: show.backdrop, title, hash, magnet });
|
||||
}}
|
||||
title='Play'
|
||||
>
|
||||
@@ -92,8 +106,20 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
<Magnet size={20} />
|
||||
</Button>
|
||||
{M3UUrl ? (
|
||||
<Button className='relative grow-0 px-3' variant='outline' title='Play m3u playlist' onClick={handleM3ULink}>
|
||||
<Cast size={20} />
|
||||
<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} />
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
supportedForCast && (
|
||||
|
||||
@@ -8,19 +8,19 @@ import TableHeadSortable from '../TableHeadSortable';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
|
||||
interface Props {
|
||||
type Props = {
|
||||
show: Show & Partial<Details>;
|
||||
title: string;
|
||||
backdrop: string;
|
||||
torrents: Torrent[];
|
||||
sort: Sort;
|
||||
sortable: boolean;
|
||||
provider: string;
|
||||
year: number;
|
||||
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 year = new Date(show.release).getFullYear();
|
||||
|
||||
return (
|
||||
<Table className='overflow-hidden rounded-xl'>
|
||||
@@ -68,7 +68,7 @@ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, p
|
||||
</TableCell>
|
||||
<TableCell className='truncate p-2'>{torrent.seeders}</TableCell>
|
||||
<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>
|
||||
</TableRow>
|
||||
</Fragment>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { TabsContent } from '@radix-ui/react-tabs';
|
||||
import { Loader } from 'lucide-react';
|
||||
import { Search } from 'lucide-react';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
@@ -15,42 +16,36 @@ 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;
|
||||
}
|
||||
type Props = InstanceProps<void> & Show & Partial<Details>;
|
||||
|
||||
const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop, onResolve }: Props) => {
|
||||
const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
|
||||
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 [query, setQuery] = useState(title);
|
||||
const year = new Date(show.release).getFullYear();
|
||||
|
||||
const yts = useTorrents({
|
||||
query: initialTitle,
|
||||
query: show.title,
|
||||
queryFn: providers.yts.queryFn,
|
||||
sort,
|
||||
key: providers.yts.key,
|
||||
imdbID
|
||||
imdbID: show.imdb_id!
|
||||
});
|
||||
const tpb = useTorrents({
|
||||
query,
|
||||
queryFn: providers.tpb.queryFn,
|
||||
sort,
|
||||
key: providers.tpb.key,
|
||||
imdbID
|
||||
imdbID: show.imdb_id!
|
||||
});
|
||||
const tlk = useTorrents({
|
||||
query,
|
||||
queryFn: providers.tlk.queryFn,
|
||||
sort,
|
||||
key: providers.tlk.key,
|
||||
imdbID
|
||||
imdbID: show.imdb_id!
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
@@ -71,7 +66,7 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
||||
const handleSearch = (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
setQuery(title || initialQuery);
|
||||
setQuery(manualQuery);
|
||||
};
|
||||
|
||||
const checkIsEmpty = (query: (typeof tabs)[number]['query']) =>
|
||||
@@ -83,14 +78,14 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
||||
<ButtonsGroup className='h-10'>
|
||||
<Input
|
||||
className='h-full'
|
||||
value={title}
|
||||
onChange={({ target }) => setTitle(target.value)}
|
||||
value={manualQuery}
|
||||
onChange={({ target: { value } }) => setManualQuery(value)}
|
||||
placeholder='Start typing title...'
|
||||
/>
|
||||
<Button
|
||||
type='submit'
|
||||
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} />
|
||||
</Button>
|
||||
@@ -110,9 +105,8 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
|
||||
return (
|
||||
<TabsContent className='pb-1' key={provider.key} value={provider.key}>
|
||||
<TorrentsTable
|
||||
year={year}
|
||||
title={title}
|
||||
backdrop={backdrop}
|
||||
show={show}
|
||||
title={show.title}
|
||||
sort={sort}
|
||||
sortable={provider.sortable}
|
||||
onChangeSort={setSort}
|
||||
|
||||
Reference in new issue
Block a user