mirror of
https://github.com/p-stream/providers.git
synced 2026-03-11 17:55:36 +00:00
fix browser cli
This commit is contained in:
parent
45673e74b0
commit
8504278157
2 changed files with 62 additions and 0 deletions
11
src/dev-cli/browser/index.html
Normal file
11
src/dev-cli/browser/index.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dev CLI Browser Mode</title>
|
||||
</head>
|
||||
<body>
|
||||
<script type="module" src="index.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
51
src/dev-cli/browser/index.ts
Normal file
51
src/dev-cli/browser/index.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { makeProviders, makeStandardFetcher, targets } from '../../../lib/index.js';
|
||||
|
||||
async function scrape(proxy: string, type: 'embed' | 'source', input: any) {
|
||||
// Set up proxy if provided
|
||||
let fetcher = makeStandardFetcher(fetch);
|
||||
if (proxy) {
|
||||
fetcher = makeStandardFetcher(async (url: string, options?: RequestInit) => {
|
||||
const response = await fetch(proxy, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
options,
|
||||
}),
|
||||
mode: 'no-cors',
|
||||
});
|
||||
const data = await response.json();
|
||||
return new Response(data.body, {
|
||||
status: data.status,
|
||||
statusText: data.statusText,
|
||||
headers: data.headers,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher,
|
||||
target: targets.ANY,
|
||||
});
|
||||
|
||||
if (type === 'embed') {
|
||||
return providers.runEmbedScraper({
|
||||
disableOpensubtitles: true,
|
||||
url: input.url,
|
||||
id: input.id,
|
||||
});
|
||||
}
|
||||
if (type === 'source') {
|
||||
return providers.runSourceScraper({
|
||||
disableOpensubtitles: true,
|
||||
media: input.media,
|
||||
id: input.id,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error('Invalid scrape type');
|
||||
}
|
||||
|
||||
(window as any).scrape = scrape;
|
||||
Loading…
Reference in a new issue