Spaces:
Runtime error
Runtime error
Update embed.js
Browse files
embed.js
CHANGED
@@ -1,60 +1,89 @@
|
|
1 |
-
const { firefox } = require('playwright'); // Ensure you have playwright installed
|
2 |
-
|
3 |
-
function serieMultiembed(imdbId) {
|
4 |
-
imdbId= imdbId.split(':');
|
5 |
-
return `https://multiembed.mov/?video_id=${imdbId[0]}&season=${imdbId[1]}&episode=${imdbId[2]}`;
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { firefox } = require('playwright'); // Ensure you have playwright installed
|
2 |
+
|
3 |
+
function serieMultiembed(imdbId) {
|
4 |
+
imdbId= imdbId.split(':');
|
5 |
+
return `https://multiembed.mov/?video_id=${imdbId[0]}&season=${imdbId[1]}&episode=${imdbId[2]}`;
|
6 |
+
}
|
7 |
+
|
8 |
+
|
9 |
+
async function movieshubembed(imdb){
|
10 |
+
var link = `https://watch.movieshubweb.com/embed/${imdb}`;
|
11 |
+
page.on('request', async (request) => {
|
12 |
+
console.log('>>', request.method(), request.url());
|
13 |
+
if (request.url().includes('.m3u8')) {
|
14 |
+
setTimeout(async () => await browser.close(), 5000);
|
15 |
+
resolve(request.url());
|
16 |
+
}
|
17 |
+
});
|
18 |
+
|
19 |
+
page.on('response', response =>
|
20 |
+
console.log('<<', response.status(), response.url())
|
21 |
+
);
|
22 |
+
|
23 |
+
try {
|
24 |
+
await page.goto(link);
|
25 |
+
await page.waitForLoadState('domcontentloaded');
|
26 |
+
await page.locator('button:text("Yes")').click();
|
27 |
+
|
28 |
+
await page.waitForSelector('#play');
|
29 |
+
await page.click('#play');
|
30 |
+
} catch (error) {
|
31 |
+
await browser.close();
|
32 |
+
reject(error);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
async function movieMultiembed(imdbId,link=null) {
|
37 |
+
const browser = await firefox.launch();
|
38 |
+
const page = await browser.newPage();
|
39 |
+
|
40 |
+
await page.setViewportSize({ width: 1200, height: 800 });
|
41 |
+
|
42 |
+
return new Promise(async (resolve, reject) => {
|
43 |
+
page.on('request', async (request) => {
|
44 |
+
console.log('>>', request.method(), request.url());
|
45 |
+
if (request.url().includes('.m3u8')) {
|
46 |
+
setTimeout(async () => await browser.close(), 5000);
|
47 |
+
resolve(request.url());
|
48 |
+
}
|
49 |
+
});
|
50 |
+
|
51 |
+
page.on('response', response =>
|
52 |
+
console.log('<<', response.status(), response.url())
|
53 |
+
);
|
54 |
+
|
55 |
+
try {
|
56 |
+
if(link){
|
57 |
+
await page.goto(link);
|
58 |
+
}else{
|
59 |
+
await page.goto(`https://multiembed.mov/?video_id=${imdbId}`);
|
60 |
+
}
|
61 |
+
await page.waitForSelector('#play');
|
62 |
+
await page.click('#play');
|
63 |
+
} catch (error) {
|
64 |
+
await browser.close();
|
65 |
+
reject(error);
|
66 |
+
}
|
67 |
+
});
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
function timeoutPromise(ms) {
|
72 |
+
return new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), ms));
|
73 |
+
}
|
74 |
+
|
75 |
+
async function movieMultiembedTimeout(movieId, timeout,link=null) {
|
76 |
+
try {
|
77 |
+
const result = await Promise.race([
|
78 |
+
movieshubembed(movieId,link),
|
79 |
+
// movieMultiembed(movieId,link),
|
80 |
+
timeoutPromise(timeout)
|
81 |
+
]);
|
82 |
+
return result;
|
83 |
+
} catch (error) {
|
84 |
+
console.error(error);
|
85 |
+
return null; // or handle the timeout error as needed
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
module.exports = { movieMultiembed,movieMultiembedTimeout,serieMultiembed};
|