feat: added m3u handler support
This commit is contained in:
1 parent
f78af76da5
commit
3460041115
3 files changed
+43
-4
No files matched your search
@@ -5,6 +5,7 @@ import { Check } from 'lucide-react';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { useM3UUrl, useSetM3UUrl } from '@/hooks/useM3UStreamUrl';
|
||||||
import { useSetStreamUrl, useStreamUrl } from '@/hooks/useStreamUrl';
|
import { useSetStreamUrl, useStreamUrl } from '@/hooks/useStreamUrl';
|
||||||
|
|
||||||
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
||||||
@@ -12,8 +13,10 @@ import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
|||||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||||
const [prefix, setPrefix] = useState(usePrefix());
|
const [prefix, setPrefix] = useState(usePrefix());
|
||||||
const submitPrefix = useSetPrefix();
|
const submitPrefix = useSetPrefix();
|
||||||
const [streamUrl, setStreamUrlValue] = useState(useStreamUrl());
|
const [streamUrl, setStreamUrl] = useState(useStreamUrl());
|
||||||
const submitStreamUrl = useSetStreamUrl();
|
const submitStreamUrl = useSetStreamUrl();
|
||||||
|
const [M3UUrl, setM3UUrl] = useState(useM3UUrl());
|
||||||
|
const submitM3UUrl = useSetM3UUrl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='m-auto p-2' onClose={onReject}>
|
<Modal className='m-auto p-2' onClose={onReject}>
|
||||||
@@ -23,6 +26,7 @@ const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onRejec
|
|||||||
|
|
||||||
submitStreamUrl(streamUrl);
|
submitStreamUrl(streamUrl);
|
||||||
submitPrefix(prefix);
|
submitPrefix(prefix);
|
||||||
|
submitM3UUrl(M3UUrl);
|
||||||
|
|
||||||
onResolve(prefix);
|
onResolve(prefix);
|
||||||
}}
|
}}
|
||||||
@@ -33,7 +37,7 @@ const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onRejec
|
|||||||
placeholder='Enter address of your torrent streamer'
|
placeholder='Enter address of your torrent streamer'
|
||||||
value={streamUrl}
|
value={streamUrl}
|
||||||
className='h-full'
|
className='h-full'
|
||||||
onChange={({ target: { value } }) => setStreamUrlValue(value)}
|
onChange={({ target: { value } }) => setStreamUrl(value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -42,6 +46,13 @@ const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onRejec
|
|||||||
className='h-full'
|
className='h-full'
|
||||||
onChange={({ target: { value } }) => setPrefix(value)}
|
onChange={({ target: { value } }) => setPrefix(value)}
|
||||||
/>
|
/>
|
||||||
|
<Input
|
||||||
|
autoFocus
|
||||||
|
placeholder='Enter address of your M3U handler'
|
||||||
|
value={M3UUrl}
|
||||||
|
className='h-full'
|
||||||
|
onChange={({ target: { value } }) => setM3UUrl(value)}
|
||||||
|
/>
|
||||||
<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'
|
||||||
|
|||||||
+18
-2
@@ -4,6 +4,7 @@ import { Cast, Download, ListVideo, Loader, Magnet, Play } from 'lucide-react';
|
|||||||
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 { Quality } from '@/data/parsers/yts/models';
|
import { Quality } from '@/data/parsers/yts/models';
|
||||||
|
import { useM3UUrl } from '@/hooks/useM3UStreamUrl';
|
||||||
import { useStreamUrl } from '@/hooks/useStreamUrl';
|
import { useStreamUrl } from '@/hooks/useStreamUrl';
|
||||||
import { cn, detectSafari, getMagnetHash } from '@/lib/utils';
|
import { cn, detectSafari, getMagnetHash } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId,
|
|||||||
const prefix = usePrefix();
|
const prefix = usePrefix();
|
||||||
const cast = useCastMagnet();
|
const cast = useCastMagnet();
|
||||||
const streamUrl = useStreamUrl();
|
const streamUrl = useStreamUrl();
|
||||||
|
const M3UUrl = useM3UUrl();
|
||||||
|
|
||||||
const { isIOS, isSafari } = detectSafari();
|
const { isIOS, isSafari } = detectSafari();
|
||||||
const isHEVC = torrent.codec?.includes('265') || torrent.codec?.toLowerCase().includes('hevc');
|
const isHEVC = torrent.codec?.includes('265') || torrent.codec?.toLowerCase().includes('hevc');
|
||||||
@@ -54,6 +56,14 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId,
|
|||||||
|
|
||||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative ml-auto w-fit grow-0'>
|
<div className='relative ml-auto w-fit grow-0'>
|
||||||
<ButtonsGroup>
|
<ButtonsGroup>
|
||||||
@@ -86,10 +96,16 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId,
|
|||||||
<a className='absolute left-0 top-0 size-full' target='_blank' rel='noopener noreferrer' href={magnet} />
|
<a className='absolute left-0 top-0 size-full' target='_blank' rel='noopener noreferrer' href={magnet} />
|
||||||
<Magnet size={20} />
|
<Magnet size={20} />
|
||||||
</Button>
|
</Button>
|
||||||
{supportedForCast && (
|
{M3UUrl ? (
|
||||||
<Button className='grow-0 px-3' variant='outline' onClick={() => cast(magnet)}>
|
<Button className='relative grow-0 px-3' variant='outline' title='Play m3u playlist' onClick={handleM3ULink}>
|
||||||
<Cast size={20} />
|
<Cast size={20} />
|
||||||
</Button>
|
</Button>
|
||||||
|
) : (
|
||||||
|
supportedForCast && (
|
||||||
|
<Button className='grow-0 px-3' variant='outline' onClick={() => cast(magnet)}>
|
||||||
|
<Cast size={20} />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</ButtonsGroup>
|
</ButtonsGroup>
|
||||||
{!magnet && (
|
{!magnet && (
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
import { STREAM_URL } from '@/env';
|
||||||
|
|
||||||
|
const M3UUrlAtom = atomWithStorage<string>('M3U url', '', undefined, {
|
||||||
|
unstable_getOnInit: true
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useSetM3UUrl = () => useSetAtom(M3UUrlAtom);
|
||||||
|
|
||||||
|
export const useM3UUrl = () => useAtomValue(M3UUrlAtom);
|
||||||
Reference in new issue
Block a user