fix: toloka magnet links
This commit is contained in:
1 parent
ee782f3845
commit
4f4e6b1307
10 files changed
+35
-734
No files matched your search
@@ -1,10 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { STREAM_URL as BASE_STREAM_URL } from '../../constants';
|
||||
|
||||
export type Source = { name: string; src: string; type: string };
|
||||
type Sources = { subtitles: Source[]; videos: Source[] };
|
||||
|
||||
const useFiles = (magnet: string) => {
|
||||
const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?link=${encodeURIComponent(magnet)}`;
|
||||
const STREAM_URL = `${BASE_STREAM_URL}${encodeURIComponent(magnet)}`;
|
||||
|
||||
const query = useQuery<Stream>({
|
||||
queryKey: ['files', magnet],
|
||||
|
||||
+11
-32
@@ -10,8 +10,6 @@ import { providers } from '../../../../constants';
|
||||
import { useCastMagnet, usePrefix } from '../../../../hooks/useMagnetHosts';
|
||||
import showPlayer from '../../../Player';
|
||||
|
||||
import useMagnet from './useMagnet';
|
||||
|
||||
interface Props {
|
||||
torrent: Torrent;
|
||||
backdrop: string;
|
||||
@@ -22,7 +20,6 @@ interface Props {
|
||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
const { mutateAsync, isPending } = useMagnet();
|
||||
|
||||
const supportedForStream = Boolean(
|
||||
(provider === providers.yts.key &&
|
||||
@@ -33,55 +30,37 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
|
||||
const supportedForCast = prefix && !prefix.includes('{host}');
|
||||
|
||||
const prefetchMagnet = (handler: (magnet: string) => void) => () => {
|
||||
if (!torrent.download) return handler(torrent.magnet);
|
||||
|
||||
return mutateAsync(torrent.download).then((magnet) => {
|
||||
console.log('magnet', magnet);
|
||||
return handler(magnet);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<ButtonsGroup className='ml-auto w-fit grow-0'>
|
||||
{supportedForStream && (
|
||||
<Button
|
||||
disabled={isPending}
|
||||
variant='destructive'
|
||||
className={cn('flex-grow-0 px-3 bg-red-600')}
|
||||
onClick={prefetchMagnet((magnet) => showPlayer({ magnet, backdrop, title }))}
|
||||
onClick={() => showPlayer({ magnet: torrent.download || torrent.magnet, backdrop, title })}
|
||||
title='Play'
|
||||
>
|
||||
<Play size={15} />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
disabled={isPending}
|
||||
variant='outline'
|
||||
className='relative grow-0 px-3'
|
||||
title='Play using your native video player'
|
||||
onClick={prefetchMagnet((magnet) => {
|
||||
window.open(`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(magnet)}`);
|
||||
})}
|
||||
>
|
||||
<Button variant='outline' className='relative grow-0 px-3' title='Play using your native video player'>
|
||||
<a
|
||||
className='absolute left-0 top-0 size-full'
|
||||
href={`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(
|
||||
torrent.download || torrent.magnet
|
||||
)}`}
|
||||
/>
|
||||
<ListVideo size={20} />
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
className='relative grow-0 px-3'
|
||||
variant='outline'
|
||||
onClick={prefetchMagnet((magnet) => window.open(magnet))}
|
||||
title='Download magnet'
|
||||
title={`Download ${torrent.download ? 'torrent' : 'magnet'}`}
|
||||
>
|
||||
<a className='absolute left-0 top-0 size-full' href={torrent.download || torrent.magnet} />
|
||||
<Magnet size={20} />
|
||||
</Button>
|
||||
{supportedForCast && (
|
||||
<Button
|
||||
disabled={isPending}
|
||||
className='grow-0 px-3'
|
||||
variant='outline'
|
||||
onClick={prefetchMagnet((magnet) => cast(magnet))}
|
||||
>
|
||||
<Button className='grow-0 px-3' variant='outline' onClick={() => cast(torrent.download || torrent.magnet)}>
|
||||
<Cast size={20} />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { fetchTLKMagnet } from '@/api';
|
||||
|
||||
const useMagnet = () => {
|
||||
return useMutation({ mutationFn: fetchTLKMagnet });
|
||||
};
|
||||
|
||||
export default useMagnet;
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Sort } from '@/api/parsers';
|
||||
|
||||
export const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?link=`;
|
||||
|
||||
type Options = { query: string; sort: Sort; imdbID: string };
|
||||
|
||||
const queryFn = ({ query, sort, imdbID, key }: Options & { key: keyof typeof providers }) =>
|
||||
|
||||
@@ -4,7 +4,9 @@ import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import showHostManagerModal from '@/components/Preview/components/Torrents/components/HostManager';
|
||||
|
||||
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
|
||||
import { STREAM_URL } from '../constants';
|
||||
|
||||
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:9090/magnet?magnet=', undefined, {
|
||||
unstable_getOnInit: true
|
||||
});
|
||||
|
||||
@@ -16,7 +18,15 @@ export const useCastMagnet = () => {
|
||||
const prefix = usePrefix();
|
||||
|
||||
return useCallback(
|
||||
(magnet: string) => {
|
||||
async (link: string) => {
|
||||
let magnet = link;
|
||||
|
||||
if (link && !link.startsWith('magnet')) {
|
||||
magnet = await fetch(`${STREAM_URL}${encodeURIComponent(link)}&stat=true`)
|
||||
.then((response) => response.json())
|
||||
.then((torrent: Stream) => `magnet:?xt=urn:btih:${torrent.hash}&dn=${encodeURIComponent(torrent.name)}`);
|
||||
}
|
||||
|
||||
const open = (prefix: string) => {
|
||||
const link = window.open(`${prefix}${magnet}`, '_blank');
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
|
||||
Reference in new issue
Block a user