-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdFreeTestMovie.tsx
More file actions
196 lines (185 loc) · 6.84 KB
/
Copy pathAdFreeTestMovie.tsx
File metadata and controls
196 lines (185 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { useParams } from 'react-router-dom';
import { useWatchDetails } from '../../hooks/useItemOrWatchDetail';
import WatchDescription from '../../components/WatchDescription';
import BackButton from '../../components/buttons/BackBtn';
import FullscreenBtn from '../../components/buttons/FullScreenBtn';
import ServerList from '../../components/lists/ServerList';
import { isIphoneSafari, isIPad } from '../../utils/helpers';
import serverData from '../../utils/data/servers.json';
import { useEffect, useState, useRef } from 'react';
import dayjs from 'dayjs';
import useDocumentTitle from '../../hooks/usePageTitles';
import { useStore } from '../../state/store';
const MovieAdFree = () => {
const { addToContinueWatchingMovie } = useStore();
const { movie_id } = useParams<{ movie_id: string }>();
const { data: movie } = useWatchDetails('movie', movie_id ?? '');
const { servers } = serverData;
const iframeRef = useRef<HTMLIFrameElement>(null);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
useDocumentTitle(
movie?.title
? `Watch ${movie?.title || 'Movie'} | BingeBox`
: 'Loading... | BingeBox',
);
const [isLoading, setIsLoading] = useState(false);
const [selectedServer, setSelectedServer] = useState(() => {
const lastSelectedServer = localStorage.getItem('lastSelectedServer');
return lastSelectedServer || servers[0].value;
});
useEffect(() => {
if (!movie) return;
// setTimeout(() => {
addToContinueWatchingMovie(
Number(movie_id),
'movie',
dayjs().unix(),
movie.title,
movie.backdrop_path,
movie.release_date,
movie.runtime,
);
// }, 180000);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [movie_id, movie]);
useEffect(() => {
let newURL = '';
switch (selectedServer) {
case 'vidsrc.xyz':
newURL = `https://bingebox-server-54dc60d03f7d.herokuapp.com/api/video/movie/${movie_id}`;
break;
case 'videasy.net':
newURL = `https://player.videasy.net/movie/${movie_id}`;
break;
case 'vidlink.pro':
newURL = `https://vidlink.pro/movie/${movie_id}`;
break;
case 'moviesapi.club':
newURL = `https://moviesapi.club/movie/${movie_id}`;
break;
case 'embed.su':
newURL = `https://embed.su/embed/movie/${movie_id}`;
break;
case 'nontongo.win':
newURL = `https://www.nontongo.win/embed/movie/${movie_id}`;
break;
case 'vidsrc.wtf':
newURL = `https://vidsrc.wtf/api/3/movie/?id=${movie_id}`;
break;
case 'vidsrc.wtf-ml':
newURL = `https://vidsrc.wtf/api/2/movie/?id=${movie_id}`;
break;
case '111movies.com':
newURL = ` https://111movies.com/movie/${movie_id}`;
break;
case 'vidfast.pro':
newURL = `https://vidfast.pro/movie/${movie_id}`;
break;
case 'superembed.stream':
newURL = ` https://multiembed.mov/directstream.php?video_id=${movie_id}&tmdb=1`;
break;
}
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
setIsLoading(true);
if (iframeRef.current) {
iframeRef.current.contentWindow?.location.replace('about:blank');
}
setTimeout(() => {
iframeRef.current?.contentWindow?.location.replace(newURL);
timeoutRef.current = setTimeout(() => {
setIsLoading(false);
}, 750);
}, 300);
localStorage.setItem('lastSelectedServer', selectedServer);
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
timeoutRef.current = null;
}
};
}, [selectedServer, movie_id]);
return (
<div className='min-h-screen pt-[60px]'>
<div className='flex flex-col lg:flex-row lg:gap-[24px] p-[16px] lg:p-[24px] lg:max-w-[2200px] lg:mx-auto'>
<div className='relative primary flex-1 w-full lg:max-w-[calc(100%-424px)]'>
<div className='flex items-center justify-between text-xl mb-[16px] rounded-lg bg-[#1f1f1f] py-[12px] px-[16px]'>
<div>
<BackButton color='text-white' />
</div>
{movie && (
<p
className='font-bold truncate text-ellipsis mx-6'
title={movie.title}
>
{movie.title || ''}
</p>
)}
{/* iphone safari doesn't support the FS api */}
<div
className={`${isIphoneSafari() || isIPad()} ? 'invisible' : ''
}`}
>
<FullscreenBtn elementId='iframe' />
</div>
</div>
<main>
<div className='relative pt-[56.25%] w-full overflow-hidden mb-[24px] rounded-lg bg-[#1f1f1f] min-h-[300px]'>
<iframe
ref={iframeRef}
id='iframe'
className='absolute top-0 left-0 w-full h-full bg-black'
width='100%'
height='100%'
src={`/api/video/movie/${movie_id}`}
allow='encrypted-media'
sandbox='allow-scripts allow-same-origin'
referrerPolicy='no-referrer'
allowFullScreen
></iframe>
{isLoading && (
<div className='absolute inset-0 flex items-center justify-center bg-black bg-opacity-70 z-10'>
<div className='text-white text-center'>
<div className='inline-block w-8 h-8 border-4 border-t-blue-500 border-r-transparent border-b-blue-500 border-l-transparent rounded-full animate-spin mb-2'></div>
<p>
Loading{' '}
{
servers.find(
(server) => server.value === selectedServer,
)?.name
}
...{' '}
</p>
</div>
</div>
)}
</div>
{/* description */}
<div className='rounded-lg bg-[#1f1f1f] border-[#2f2f2f] p-[24px] mb-[24px]'>
{movie && (
<WatchDescription
title={movie?.title}
rt={movie?.runtime}
date={movie?.release_date}
overview={movie?.overview || 'No summary available'}
/>
)}
</div>
</main>
</div>
<div className='secondary lg:w-[400px] lg:flex-shrink-0 '>
{/* right side with server choices and episodes for tv*/}
<div className='sidebar bg-[#1f1f1f] max-h-[800px] flex flex-col rounded-lg'>
<ServerList
serverData={servers}
selectedServer={selectedServer}
setSelectedServer={setSelectedServer}
/>
</div>
</div>
</div>
</div>
);
};
export default MovieAdFree;