From f447cf3423e9ec95bfe24b96d949d4a1d7af2b87 Mon Sep 17 00:00:00 2001 From: ner Date: Sat, 13 Dec 2025 20:16:46 +0200 Subject: [PATCH] fix: new address for yts provider --- .../Torrents/components/Player/index.tsx | 52 +------ .../Actions/components/Player/index.tsx | 22 ++- .../{ => components/Player}/useFiles.ts | 13 +- .../components/Actions/index.tsx | 15 +- .../components/TorrentsTable/index.tsx | 24 +--- .../Preview/components/Torrents/index.tsx | 134 ++++++++---------- data/parsers/yts/index.ts | 2 +- 7 files changed, 85 insertions(+), 177 deletions(-) rename components/Preview/components/Torrents/components/TorrentsTable/components/Actions/{ => components/Player}/useFiles.ts (84%) diff --git a/components/Preview/components/Torrents/components/Player/index.tsx b/components/Preview/components/Torrents/components/Player/index.tsx index 4cbbcac..739a016 100644 --- a/components/Preview/components/Torrents/components/Player/index.tsx +++ b/components/Preview/components/Torrents/components/Player/index.tsx @@ -1,6 +1,6 @@ 'use client'; -import { FC, MutableRefObject, useEffect, useImperativeHandle, useRef, useState } from 'react'; +import { FC, useEffect, useRef } from 'react'; import { MediaPlayer, MediaPlayerInstance, @@ -13,7 +13,7 @@ import { import { NextIcon } from '@vidstack/react/icons'; 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 Captions from './components/Captions'; @@ -22,31 +22,14 @@ import useSource from './useSource'; import '@vidstack/react/player/styles/plyr/theme.css'; -interface Stream { +interface Props { magnet: string; subtitles: Source[]; playlist: Source[]; } -const sample = { type: 'video/mp4', src: '/sample.mp4', name: 'Sample' }; - -export type PlayerControlRef = MutableRefObject<{ - play: (options: { sources: Sources; magnet: string }) => void; -}>; - -interface Props { - controlRef: PlayerControlRef; -} - -const Player: FC = ({ controlRef }) => { - const [{ magnet, playlist, subtitles }, setStream] = useState({ - magnet: '', - subtitles: [], - playlist: [sample] - }); - const canPlay = useCanPlay(); +const Player: FC = ({ magnet, playlist, subtitles }) => { const setCanPlay = useSetCanPlay(); - const { index, setIndex } = useSource({ magnet }); const player = useRef(null); @@ -63,28 +46,6 @@ const Player: FC = ({ controlRef }) => { 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 ( = ({ controlRef }) => { preload='none' storage='movie-advisor' ref={player} - loop={pending} src={(source as VideoSrc) || []} - onCanPlay={handlePlay} - className={cn('relative size-full select-none', { invisible: pending })} + onCanPlay={() => setCanPlay(true)} + className={cn('relative size-full select-none')} > {subtitles.map((track, index) => ( diff --git a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/index.tsx b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/index.tsx index b3161fa..8a17c06 100644 --- a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/index.tsx +++ b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/index.tsx @@ -1,27 +1,26 @@ import { create, InstanceProps } from 'react-modal-promise'; -import { DialogContentProps } from '@radix-ui/react-dialog'; import { Loader } from 'lucide-react'; +import Player from '@/components/Preview/components/Torrents/components/Player'; import { Modal } from '@/components/ui/dialog'; import { useCanPlay, useSetCanPlay } from '@/hooks/useCanPlay'; +import { useFiles } from './useFiles'; import { useStats } from './useStats'; interface Props extends InstanceProps { hash: string; backdrop: 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 setCanPlay = useSetCanPlay(); const { isReady, preloadingProgress, downloadSpeed } = useStats({ hash, canPlay }); - const handlePlayerInteraction: DialogContentProps['onInteractOutside'] = (event) => { - if (document.getElementById(playerEntryId)?.contains(event.target as Node)) event.preventDefault(); - }; + const sources = useFiles({ magnet }); const handleClose = () => { setCanPlay(false); @@ -29,14 +28,11 @@ const showPlayerModal = create(({ onResolve, hash, backdrop, title, playerEntryI }; return ( - +
-
+
+ {sources && } +
{(!isReady || !canPlay) && (
{title} diff --git a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/useFiles.ts b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/useFiles.ts similarity index 84% rename from components/Preview/components/Torrents/components/TorrentsTable/components/Actions/useFiles.ts rename to components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/useFiles.ts index fda67f6..a886451 100644 --- a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/useFiles.ts +++ b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/components/Player/useFiles.ts @@ -1,4 +1,4 @@ -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQuery } from '@tanstack/react-query'; import { useStreamUrl } from '@/hooks/useStreamUrl'; @@ -6,11 +6,12 @@ interface Props { magnet: string; } -const useFiles = ({ magnet }: Props) => { +export const useFiles = ({ magnet }: Props) => { const streamUrl = `${useStreamUrl()}/stream?link=${encodeURIComponent(magnet)}`; - return useMutation({ - mutationFn: () => + const { data } = useQuery({ + queryKey: ['sources', magnet], + queryFn: () => fetch(`${streamUrl}&stat`) .then((response) => { if (!response.ok) return Promise.reject('Download Failed: unable to retrieve the video'); @@ -42,6 +43,6 @@ const useFiles = ({ magnet }: Props) => { return sources; }) }); -}; -export default useFiles; + return data; +}; diff --git a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx index c0d4dda..193849a 100644 --- a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx +++ b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx @@ -1,6 +1,8 @@ import { FC, useMemo } from '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 ButtonsGroup from '@/components/ui/buttons-group'; import { Quality } from '@/data/parsers/yts/models'; @@ -8,11 +10,7 @@ import { useM3UUrl } from '@/hooks/useM3UStreamUrl'; import { useStreamUrl } from '@/hooks/useStreamUrl'; import { cn, detectSafari, getMagnetHash, isStandaloneApp } from '@/lib/utils'; -import { providers } from '../../../../constants'; -import { useCastMagnet, usePrefix } from '../../../../hooks/useMagnetHosts'; - import showPlayerModal from './components/Player'; -import useFiles from './useFiles'; import useMagnet from './useMagnet'; interface Props { @@ -20,11 +18,9 @@ interface Props { backdrop: string; title: string; provider: string; - onPlay: (options: Promise<{ sources: Sources; magnet: string }>) => void; - playerEntryId: string; } -const Actions: FC = ({ torrent, backdrop, title, provider, playerEntryId, onPlay }) => { +const Actions: FC = ({ torrent, backdrop, title, provider }) => { const prefix = usePrefix(); const cast = useCastMagnet(); const streamUrl = useStreamUrl(); @@ -52,8 +48,6 @@ const Actions: FC = ({ torrent, backdrop, title, provider, playerEntryId, const magnet = fetchMagnet.data || torrent.magnet; - const fetchSources = useFiles({ magnet }); - const hash = getMagnetHash(magnet); const supportedForCast = prefix && !prefix.includes('{host}'); @@ -77,8 +71,7 @@ const Actions: FC = ({ torrent, backdrop, title, provider, playerEntryId, 'hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600' )} onClick={() => { - showPlayerModal({ backdrop, title, hash, playerEntryId }); - onPlay(fetchSources.mutateAsync().then((sources) => ({ sources, magnet }))); + showPlayerModal({ backdrop, title, hash, magnet }); }} title='Play' > diff --git a/components/Preview/components/Torrents/components/TorrentsTable/index.tsx b/components/Preview/components/Torrents/components/TorrentsTable/index.tsx index b540d58..9c89f9c 100644 --- a/components/Preview/components/Torrents/components/TorrentsTable/index.tsx +++ b/components/Preview/components/Torrents/components/TorrentsTable/index.tsx @@ -17,22 +17,9 @@ interface Props { provider: string; year: number; onChangeSort: (sort: Sort) => void; - onPlay: (options: Promise<{ sources: Sources; magnet: string }>) => void; - playerEntryId: string; } -const TorrentsTable: FC = ({ - title, - torrents, - backdrop, - sort, - sortable, - provider, - year, - onChangeSort, - onPlay, - playerEntryId -}) => { +const TorrentsTable: FC = ({ title, torrents, backdrop, sort, sortable, provider, year, onChangeSort }) => { const colSpan = 5; return ( @@ -81,14 +68,7 @@ const TorrentsTable: FC = ({ {torrent.seeders} - + diff --git a/components/Preview/components/Torrents/index.tsx b/components/Preview/components/Torrents/index.tsx index 4b0e752..ad45e27 100644 --- a/components/Preview/components/Torrents/index.tsx +++ b/components/Preview/components/Torrents/index.tsx @@ -1,5 +1,4 @@ -import React, { FormEvent, useId, useRef, useState } from 'react'; -import { createPortal } from 'react-dom'; +import React, { FormEvent, useState } from 'react'; import { create, InstanceProps } from 'react-modal-promise'; import { TabsContent } from '@radix-ui/react-tabs'; import { Loader } from 'lucide-react'; @@ -12,7 +11,6 @@ import { Input } from '@/components/ui/input'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Sort } from '@/data/parsers'; -import Player, { PlayerControlRef } from './components/Player'; import TorrentsTable from './components/TorrentsTable'; import { providers } from './constants'; 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(null); - const handleSearch = (event: FormEvent) => { event.preventDefault(); @@ -86,78 +78,64 @@ const showTorrentsModal = create(({ title: initialTitle, year, imdbID, backdrop, query.isFetched && !query.isLoading && !query.data?.length; return ( - <> -
- {createPortal( - , - document.getElementById(playerEntryId) || playerEntryRef.current || document.body - )} -
- -
- - setTitle(target.value)} - placeholder='Start typing title...' - /> - - -
- - - {tabs.map(({ provider, query }) => ( - - {query.isLoading ? : provider.label} - - ))} - - {tabs.map(({ provider, query }) => { - const isEmpty = checkIsEmpty(query); + +
+ + setTitle(target.value)} + placeholder='Start typing title...' + /> + + +
+ + + {tabs.map(({ provider, query }) => ( + + {query.isLoading ? : provider.label} + + ))} + + {tabs.map(({ provider, query }) => { + const isEmpty = checkIsEmpty(query); - return ( - - { - if (!playerControlRef.current) return; + return ( + + - options.then((options) => playerControlRef.current.play(options)); - }} - /> + {(query.isLoading || query.isFetching) && ( +
+ +
+ )} - {(query.isLoading || query.isFetching) && ( -
- -
- )} - - {isEmpty && ( -
- Nothing was found -
- )} -
- ); - })} -
-
- + {isEmpty && ( +
+ Nothing was found +
+ )} + + ); + })} +
+
); }); diff --git a/data/parsers/yts/index.ts b/data/parsers/yts/index.ts index 1fc72f7..08dd060 100644 --- a/data/parsers/yts/index.ts +++ b/data/parsers/yts/index.ts @@ -11,7 +11,7 @@ export class YTS { private host: string; 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({ baseURL: this.host