Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
// HTML renderer
import { scrapeMovie, scrapeShow } from "https://esm.town/v/tempdev/primewire";
import {
primewireApiKey,
primewireBase,
} from "https://raw.githubusercontent.com/Ciarands/mw-providers/dev/src/providers/sources/primewire/common.ts";
interface Meta {
current_quality: string;
id: string;
imdb_id: string;
title: string;
tvdb_id?: null | string;
tvmaze_id?: null | string;
type: string;
year: number;
}
async function movieHandler(meta: Meta) {
const data = await scrapeMovie(meta.imdb_id);
let htmlData = "";
for (const item of data.embeds) {
htmlData += `<a href="https://cool-download.koyeb.app/watch?id=${
btoa(item.url)
}&extractor=${item.embedId}"><code>${item.embedId}</code></a><br>`;
}
return `
<head>
<title>${meta.title}</title>
</head>
<body>
<h1>${meta.title}</h1>
<h2>Imdb ${meta.imdb_id}</h2>
<h3>Movie</h3>
<h3>Year ${meta.year}</h3>
<pre>Quality ${meta.current_quality}</pre>
${htmlData}
</body>
`;
}
async function showHandler(meta: Meta, s, e) {
const data = await scrapeShow(meta.imdb_id, s, e);
let htmlData = "";
for (const item of data.embeds) {
htmlData += `<a href="https://cool-download.koyeb.app/watch?id=${
btoa(item.url)
}&extractor=${item.embedId}"><code>${item.embedId}</code></a><br>`;
}
return `
<head>
<title>${meta.title}</title>
</head>
<body>
<h1>${meta.title}</h1>
<h2>Imdb ${meta.imdb_id}</h2>
<h3>TV</h3>
<h3>Year ${meta.year}</h3>
<pre>Quality ${meta.current_quality}</pre>
${htmlData}
</body>
`;
}
async function getMeta(imdbId: string): Promise<Meta> {
const searchResult = await fetch(`${primewireBase}/api/v1/show?key=${primewireApiKey}&imdb_id=${imdbId}`);
return await searchResult.json() as Meta;
}
export async function handler(imdbId: string, season: number, episode: number) {
const meta: Meta = await getMeta(imdbId) as Meta;
switch (meta.type) {
case "tv":
return showHandler(meta, season, episode);
case "movie":
return movieHandler(meta);
}
}
September 10, 2024