fix: new address for yts provider
This commit is contained in:
1 parent
f790cfef2a
commit
f447cf3423
7 files changed
+85
-177
No files matched your search
@@ -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<Props> = ({ controlRef }) => {
|
||||
const [{ magnet, playlist, subtitles }, setStream] = useState<Stream>({
|
||||
magnet: '',
|
||||
subtitles: [],
|
||||
playlist: [sample]
|
||||
});
|
||||
const canPlay = useCanPlay();
|
||||
const Player: FC<Props> = ({ magnet, playlist, subtitles }) => {
|
||||
const setCanPlay = useSetCanPlay();
|
||||
|
||||
const { index, setIndex } = useSource({ magnet });
|
||||
|
||||
const player = useRef<MediaPlayerInstance>(null);
|
||||
@@ -63,28 +46,6 @@ const Player: FC<Props> = ({ 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 (
|
||||
<MediaPlayer
|
||||
playsInline
|
||||
@@ -93,10 +54,9 @@ const Player: FC<Props> = ({ 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')}
|
||||
>
|
||||
<MediaProvider className='relative flex size-full justify-center [&>video]:!h-full'>
|
||||
{subtitles.map((track, index) => (
|
||||
|
||||
+9
-13
@@ -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<void> {
|
||||
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 (
|
||||
<Modal
|
||||
className='overflow-hidden border-none bg-black p-0'
|
||||
onClose={handleClose}
|
||||
onInteractOutside={handlePlayerInteraction}
|
||||
onPointerDownOutside={handlePlayerInteraction}
|
||||
>
|
||||
<Modal className='overflow-hidden border-none bg-black p-0' onClose={handleClose}>
|
||||
<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) && (
|
||||
<div className='absolute left-0 top-0 size-full'>
|
||||
<img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />
|
||||
|
||||
+7
-6
@@ -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<Sources>({
|
||||
mutationFn: () =>
|
||||
const { data } = useQuery<Sources>({
|
||||
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;
|
||||
};
|
||||
+4
-11
@@ -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<Props> = ({ torrent, backdrop, title, provider, playerEntryId, onPlay }) => {
|
||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||
const prefix = usePrefix();
|
||||
const cast = useCastMagnet();
|
||||
const streamUrl = useStreamUrl();
|
||||
@@ -52,8 +48,6 @@ const Actions: FC<Props> = ({ 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<Props> = ({ 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'
|
||||
>
|
||||
|
||||
@@ -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<Props> = ({
|
||||
title,
|
||||
torrents,
|
||||
backdrop,
|
||||
sort,
|
||||
sortable,
|
||||
provider,
|
||||
year,
|
||||
onChangeSort,
|
||||
onPlay,
|
||||
playerEntryId
|
||||
}) => {
|
||||
const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, provider, year, onChangeSort }) => {
|
||||
const colSpan = 5;
|
||||
|
||||
return (
|
||||
@@ -81,14 +68,7 @@ const TorrentsTable: FC<Props> = ({
|
||||
</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}
|
||||
onPlay={onPlay}
|
||||
playerEntryId={playerEntryId}
|
||||
/>
|
||||
<Actions title={title} backdrop={backdrop} torrent={torrent} provider={provider} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</Fragment>
|
||||
|
||||
@@ -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<HTMLDivElement>(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 (
|
||||
<>
|
||||
<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}>
|
||||
<form className='p-2' tabIndex={1} onSubmit={handleSearch}>
|
||||
<ButtonsGroup className='h-10'>
|
||||
<Input
|
||||
className='h-full'
|
||||
value={title}
|
||||
onChange={({ target }) => setTitle(target.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}
|
||||
>
|
||||
<Search size={16} />
|
||||
</Button>
|
||||
</ButtonsGroup>
|
||||
</form>
|
||||
<Tabs defaultValue={providers.yts.key} className='w-full rounded-none px-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{tabs.map(({ provider, query }) => (
|
||||
<TabsTrigger key={provider.key} value={provider.key} className='min-h-8'>
|
||||
{query.isLoading ? <Loader className='animate-spin' size={14} /> : provider.label}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ provider, query }) => {
|
||||
const isEmpty = checkIsEmpty(query);
|
||||
<Modal className='rounded-xl p-0' onClose={onResolve}>
|
||||
<form className='p-2' tabIndex={1} onSubmit={handleSearch}>
|
||||
<ButtonsGroup className='h-10'>
|
||||
<Input
|
||||
className='h-full'
|
||||
value={title}
|
||||
onChange={({ target }) => setTitle(target.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}
|
||||
>
|
||||
<Search size={16} />
|
||||
</Button>
|
||||
</ButtonsGroup>
|
||||
</form>
|
||||
<Tabs defaultValue={providers.yts.key} className='w-full rounded-none px-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{tabs.map(({ provider, query }) => (
|
||||
<TabsTrigger key={provider.key} value={provider.key} className='min-h-8'>
|
||||
{query.isLoading ? <Loader className='animate-spin' size={14} /> : provider.label}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ provider, query }) => {
|
||||
const isEmpty = checkIsEmpty(query);
|
||||
|
||||
return (
|
||||
<TabsContent className='pb-1' key={provider.key} value={provider.key}>
|
||||
<TorrentsTable
|
||||
year={year}
|
||||
title={title}
|
||||
backdrop={backdrop}
|
||||
sort={sort}
|
||||
sortable={provider.sortable}
|
||||
onChangeSort={setSort}
|
||||
provider={provider.key}
|
||||
torrents={query.data || []}
|
||||
playerEntryId={playerEntryId}
|
||||
onPlay={(options) => {
|
||||
if (!playerControlRef.current) return;
|
||||
return (
|
||||
<TabsContent className='pb-1' key={provider.key} value={provider.key}>
|
||||
<TorrentsTable
|
||||
year={year}
|
||||
title={title}
|
||||
backdrop={backdrop}
|
||||
sort={sort}
|
||||
sortable={provider.sortable}
|
||||
onChangeSort={setSort}
|
||||
provider={provider.key}
|
||||
torrents={query.data || []}
|
||||
/>
|
||||
|
||||
options.then((options) => playerControlRef.current.play(options));
|
||||
}}
|
||||
/>
|
||||
{(query.isLoading || query.isFetching) && (
|
||||
<div className='flex h-40 w-full items-center justify-center'>
|
||||
<Loader className='animate-spin' />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(query.isLoading || query.isFetching) && (
|
||||
<div className='flex h-40 w-full items-center justify-center'>
|
||||
<Loader className='animate-spin' />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isEmpty && (
|
||||
<div className='flex h-40 w-full items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
);
|
||||
})}
|
||||
</Tabs>
|
||||
</Modal>
|
||||
</>
|
||||
{isEmpty && (
|
||||
<div className='flex h-40 w-full items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
);
|
||||
})}
|
||||
</Tabs>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user