fix: new address for yts provider

This commit is contained in:
ner committed 2025-12-13 20:16:46 +02:00
1 parent f790cfef2a
commit f447cf3423
7 files changed
+30 -122

No files matched your search

@@ -1,6 +1,6 @@
'use client'; 'use client';
import { FC, MutableRefObject, useEffect, useImperativeHandle, useRef, useState } from 'react'; import { FC, useEffect, useRef } from 'react';
import { import {
MediaPlayer, MediaPlayer,
MediaPlayerInstance, MediaPlayerInstance,
@@ -13,7 +13,7 @@ import {
import { NextIcon } from '@vidstack/react/icons'; import { NextIcon } from '@vidstack/react/icons';
import { PlyrLayout, plyrLayoutIcons } from '@vidstack/react/player/layouts/plyr'; import { PlyrLayout, plyrLayoutIcons } from '@vidstack/react/player/layouts/plyr';
import { useCanPlay, useSetCanPlay } from '@/hooks/useCanPlay'; import { useSetCanPlay } from '@/hooks/useCanPlay';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import Captions from './components/Captions'; import Captions from './components/Captions';
@@ -22,31 +22,14 @@ import useSource from './useSource';
import '@vidstack/react/player/styles/plyr/theme.css'; import '@vidstack/react/player/styles/plyr/theme.css';
interface Stream { interface Props {
magnet: string; magnet: string;
subtitles: Source[]; subtitles: Source[];
playlist: Source[]; playlist: Source[];
} }
const sample = { type: 'video/mp4', src: '/sample.mp4', name: 'Sample' }; const Player: FC<Props> = ({ magnet, playlist, subtitles }) => {
export type PlayerControlRef = MutableRefObject<{
play: (options: { sources: Sources; magnet: string }) => void;
}>;
interface Props {
controlRef: PlayerControlRef;
}
const Player: FC<Props> = ({ controlRef }) => {
const [{ magnet, playlist, subtitles }, setStream] = useState<Stream>({
magnet: '',
subtitles: [],
playlist: [sample]
});
const canPlay = useCanPlay();
const setCanPlay = useSetCanPlay(); const setCanPlay = useSetCanPlay();
const { index, setIndex } = useSource({ magnet }); const { index, setIndex } = useSource({ magnet });
const player = useRef<MediaPlayerInstance>(null); const player = useRef<MediaPlayerInstance>(null);
@@ -63,28 +46,6 @@ const Player: FC<Props> = ({ controlRef }) => {
const source = playlist[index]; const source = playlist[index];
const handlePlay = () => {
if (!player.current) return;
player.current
.play()
.catch(() => {})
.finally(() => {
if (source === sample) return;
setCanPlay(true);
});
};
useImperativeHandle(controlRef, () => ({
play({ magnet, sources }) {
setStream({ magnet, ...sources });
setCanPlay(false);
}
}));
const pending = !canPlay;
return ( return (
<MediaPlayer <MediaPlayer
playsInline playsInline
@@ -93,10 +54,9 @@ const Player: FC<Props> = ({ controlRef }) => {
preload='none' preload='none'
storage='movie-advisor' storage='movie-advisor'
ref={player} ref={player}
loop={pending}
src={(source as VideoSrc) || []} src={(source as VideoSrc) || []}
onCanPlay={handlePlay} onCanPlay={() => setCanPlay(true)}
className={cn('relative size-full select-none', { invisible: pending })} className={cn('relative size-full select-none')}
> >
<MediaProvider className='relative flex size-full justify-center [&>video]:!h-full'> <MediaProvider className='relative flex size-full justify-center [&>video]:!h-full'>
{subtitles.map((track, index) => ( {subtitles.map((track, index) => (
@@ -1,27 +1,26 @@
import { create, InstanceProps } from 'react-modal-promise'; import { create, InstanceProps } from 'react-modal-promise';
import { DialogContentProps } from '@radix-ui/react-dialog';
import { Loader } from 'lucide-react'; import { Loader } from 'lucide-react';
import Player from '@/components/Preview/components/Torrents/components/Player';
import { Modal } from '@/components/ui/dialog'; import { Modal } from '@/components/ui/dialog';
import { useCanPlay, useSetCanPlay } from '@/hooks/useCanPlay'; import { useCanPlay, useSetCanPlay } from '@/hooks/useCanPlay';
import { useFiles } from './useFiles';
import { useStats } from './useStats'; import { useStats } from './useStats';
interface Props extends InstanceProps<void> { interface Props extends InstanceProps<void> {
hash: string; hash: string;
backdrop: string; backdrop: string;
title: string; title: string;
playerEntryId: string; magnet: string;
} }
const showPlayerModal = create(({ onResolve, hash, backdrop, title, playerEntryId }: Props) => { const showPlayerModal = create(({ onResolve, hash, backdrop, title, magnet }: Props) => {
const canPlay = useCanPlay(); const canPlay = useCanPlay();
const setCanPlay = useSetCanPlay(); const setCanPlay = useSetCanPlay();
const { isReady, preloadingProgress, downloadSpeed } = useStats({ hash, canPlay }); const { isReady, preloadingProgress, downloadSpeed } = useStats({ hash, canPlay });
const handlePlayerInteraction: DialogContentProps['onInteractOutside'] = (event) => { const sources = useFiles({ magnet });
if (document.getElementById(playerEntryId)?.contains(event.target as Node)) event.preventDefault();
};
const handleClose = () => { const handleClose = () => {
setCanPlay(false); setCanPlay(false);
@@ -29,14 +28,11 @@ const showPlayerModal = create(({ onResolve, hash, backdrop, title, playerEntryI
}; };
return ( return (
<Modal <Modal className='overflow-hidden border-none bg-black p-0' onClose={handleClose}>
className='overflow-hidden border-none bg-black p-0'
onClose={handleClose}
onInteractOutside={handlePlayerInteraction}
onPointerDownOutside={handlePlayerInteraction}
>
<div className='relative w-full overflow-hidden pt-[56.25%]'> <div className='relative w-full overflow-hidden pt-[56.25%]'>
<div className='absolute left-0 top-0 size-full' id={playerEntryId} /> <div className='absolute left-0 top-0 size-full'>
{sources && <Player magnet={magnet} playlist={sources.playlist} subtitles={sources.subtitles} />}
</div>
{(!isReady || !canPlay) && ( {(!isReady || !canPlay) && (
<div className='absolute left-0 top-0 size-full'> <div className='absolute left-0 top-0 size-full'>
<img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} /> <img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query'; import { useMutation, useQuery } from '@tanstack/react-query';
import { useStreamUrl } from '@/hooks/useStreamUrl'; import { useStreamUrl } from '@/hooks/useStreamUrl';
@@ -6,11 +6,12 @@ interface Props {
magnet: string; magnet: string;
} }
const useFiles = ({ magnet }: Props) => { export const useFiles = ({ magnet }: Props) => {
const streamUrl = `${useStreamUrl()}/stream?link=${encodeURIComponent(magnet)}`; const streamUrl = `${useStreamUrl()}/stream?link=${encodeURIComponent(magnet)}`;
return useMutation<Sources>({ const { data } = useQuery<Sources>({
mutationFn: () => queryKey: ['sources', magnet],
queryFn: () =>
fetch(`${streamUrl}&stat`) fetch(`${streamUrl}&stat`)
.then((response) => { .then((response) => {
if (!response.ok) return Promise.reject('Download Failed: unable to retrieve the video'); if (!response.ok) return Promise.reject('Download Failed: unable to retrieve the video');
@@ -42,6 +43,6 @@ const useFiles = ({ magnet }: Props) => {
return sources; return sources;
}) })
}); });
};
export default useFiles; return data;
};
@@ -1,6 +1,8 @@
import { FC, useMemo } from 'react'; import { FC, useMemo } 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 { useCastMagnet, usePrefix } from '@/components/Preview/components/Torrents/hooks/useMagnetHosts';
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';
@@ -8,11 +10,7 @@ import { useM3UUrl } from '@/hooks/useM3UStreamUrl';
import { useStreamUrl } from '@/hooks/useStreamUrl'; import { useStreamUrl } from '@/hooks/useStreamUrl';
import { cn, detectSafari, getMagnetHash, isStandaloneApp } from '@/lib/utils'; import { cn, detectSafari, getMagnetHash, isStandaloneApp } from '@/lib/utils';
import { providers } from '../../../../constants';
import { useCastMagnet, usePrefix } from '../../../../hooks/useMagnetHosts';
import showPlayerModal from './components/Player'; import showPlayerModal from './components/Player';
import useFiles from './useFiles';
import useMagnet from './useMagnet'; import useMagnet from './useMagnet';
interface Props { interface Props {
@@ -20,11 +18,9 @@ interface Props {
backdrop: string; backdrop: string;
title: string; title: string;
provider: string; provider: string;
onPlay: (options: Promise<{ sources: Sources; magnet: string }>) => void;
playerEntryId: string;
} }
const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId, onPlay }) => { const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
const prefix = usePrefix(); const prefix = usePrefix();
const cast = useCastMagnet(); const cast = useCastMagnet();
const streamUrl = useStreamUrl(); const streamUrl = useStreamUrl();
@@ -52,8 +48,6 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId,
const magnet = fetchMagnet.data || torrent.magnet; const magnet = fetchMagnet.data || torrent.magnet;
const fetchSources = useFiles({ magnet });
const hash = getMagnetHash(magnet); const hash = getMagnetHash(magnet);
const supportedForCast = prefix && !prefix.includes('{host}'); const supportedForCast = prefix && !prefix.includes('{host}');
@@ -77,8 +71,7 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider, playerEntryId,
'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, playerEntryId }); showPlayerModal({ backdrop, title, hash, magnet });
onPlay(fetchSources.mutateAsync().then((sources) => ({ sources, magnet })));
}} }}
title='Play' title='Play'
> >
@@ -17,22 +17,9 @@ interface Props {
provider: string; provider: string;
year: number; year: number;
onChangeSort: (sort: Sort) => void; onChangeSort: (sort: Sort) => void;
onPlay: (options: Promise<{ sources: Sources; magnet: string }>) => void;
playerEntryId: string;
} }
const TorrentsTable: FC<Props> = ({ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, provider, year, onChangeSort }) => {
title,
torrents,
backdrop,
sort,
sortable,
provider,
year,
onChangeSort,
onPlay,
playerEntryId
}) => {
const colSpan = 5; const colSpan = 5;
return ( return (
@@ -81,14 +68,7 @@ const TorrentsTable: FC<Props> = ({
</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 <Actions title={title} backdrop={backdrop} torrent={torrent} provider={provider} />
title={title}
backdrop={backdrop}
torrent={torrent}
provider={provider}
onPlay={onPlay}
playerEntryId={playerEntryId}
/>
</TableCell> </TableCell>
</TableRow> </TableRow>
</Fragment> </Fragment>
@@ -1,5 +1,4 @@
import React, { FormEvent, useId, useRef, useState } from 'react'; import React, { FormEvent, useState } from 'react';
import { createPortal } from 'react-dom';
import { create, InstanceProps } from 'react-modal-promise'; import { create, InstanceProps } from 'react-modal-promise';
import { TabsContent } from '@radix-ui/react-tabs'; import { TabsContent } from '@radix-ui/react-tabs';
import { Loader } from 'lucide-react'; import { Loader } from 'lucide-react';
@@ -12,7 +11,6 @@ import { Input } from '@/components/ui/input';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Sort } from '@/data/parsers'; import { Sort } from '@/data/parsers';
import Player, { PlayerControlRef } from './components/Player';
import TorrentsTable from './components/TorrentsTable'; import TorrentsTable from './components/TorrentsTable';
import { providers } from './constants'; import { providers } from './constants';
import useTorrents from './useTorrents'; import useTorrents from './useTorrents';
@@ -70,12 +68,6 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
} }
]; ];
const playerControlRef = useRef() as PlayerControlRef;
const playerEntryId = useId();
const playerEntryRef = useRef<HTMLDivElement>(null);
const handleSearch = (event: FormEvent) => { const handleSearch = (event: FormEvent) => {
event.preventDefault(); event.preventDefault();
@@ -86,13 +78,6 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
query.isFetched && !query.isLoading && !query.data?.length; query.isFetched && !query.isLoading && !query.data?.length;
return ( return (
<>
<div className='hidden' ref={playerEntryRef}>
{createPortal(
<Player controlRef={playerControlRef} />,
document.getElementById(playerEntryId) || playerEntryRef.current || document.body
)}
</div>
<Modal className='rounded-xl p-0' onClose={onResolve}> <Modal className='rounded-xl p-0' onClose={onResolve}>
<form className='p-2' tabIndex={1} onSubmit={handleSearch}> <form className='p-2' tabIndex={1} onSubmit={handleSearch}>
<ButtonsGroup className='h-10'> <ButtonsGroup className='h-10'>
@@ -133,12 +118,6 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
onChangeSort={setSort} onChangeSort={setSort}
provider={provider.key} provider={provider.key}
torrents={query.data || []} torrents={query.data || []}
playerEntryId={playerEntryId}
onPlay={(options) => {
if (!playerControlRef.current) return;
options.then((options) => playerControlRef.current.play(options));
}}
/> />
{(query.isLoading || query.isFetching) && ( {(query.isLoading || query.isFetching) && (
@@ -157,7 +136,6 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop,
})} })}
</Tabs> </Tabs>
</Modal> </Modal>
</>
); );
}); });
+1 -1
View File
@@ -11,7 +11,7 @@ export class YTS {
private host: string; private host: string;
constructor() { constructor() {
this.host = YTS_HOST || 'https://yts.mx/api/v2/list_movies.json'; this.host = YTS_HOST || 'https://yts.lt/api/v2/list_movies.json';
this.client = axios.create({ this.client = axios.create({
baseURL: this.host baseURL: this.host