Public
Script
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
import { load } from "npm:cheerio";
const NotFoundError = Error;
import { getLinks } from "https://esm.town/v/tempdev/blue";
import {
primewireApiKey,
primewireBase,
} from "https://raw.githubusercontent.com/Ciarands/mw-providers/dev/src/providers/sources/primewire/common.ts";
async function search(imdbId: string) {
const searchResult = await fetch(`${primewireBase}/api/v1/show?key=${primewireApiKey}&imdb_id=${imdbId}`);
return await searchResult.json().then((searchResult) => {
return searchResult.id;
});
}
async function getStreams(title: string) {
const titlePage = load(title);
const userData = titlePage("#user-data").attr("v");
if (!userData) throw new NotFoundError("No user data found");
const links = getLinks(userData);
const embeds = [];
if (!links) throw new NotFoundError("No links found");
for (const link in links) {
if (link.includes(link)) {
const element = titlePage(`.propper-link[link_version='${link}']`);
const sourceName = element.parent().parent().parent().find(".version-host").text().trim();
let embedId;
let quality = element.parent().find("span").text() ?? "AUTO";
switch (sourceName) {
case "dood.watch":
embedId = "doodstream";
break;
case "streamtape.com":
embedId = "streamtape";
break;
default:
embedId = null;
}
if (!embedId) continue;
embeds.push({
url: `${primewireBase}/links/go/${links[link]}`,
quality: quality,
embedId,
});
}
}
return embeds;
}
export async function scrapeMovie(imdbId) {
const searchResult = await search(imdbId);
const title = await fetch(`${primewireBase}/movie/${searchResult}`);
const titleResp = await title.text();
const embeds = await getStreams(titleResp);
return {
embeds,
};
}
export async function scrapeShow(imdbId, seasonId, episodeId) {
console.log(imdbId, seasonId, episodeId);
if (!imdbId) throw new Error("No imdbId provided");
const searchResult = await search(imdbId);
const _season = await fetch(`${primewireBase}/tv/${searchResult}`, {});
const season = await _season.text();
const seasonPage = load(season);
const episodeLink = seasonPage(`.show_season[data-id='${seasonId}'] > div > a`)
.toArray()
.find((link) => {
return link.attribs.href.includes(`-episode-${episodeId}`);
})?.attribs.href;
if (!episodeLink) throw new NotFoundError("No episode links found");
const _title = await fetch(`${primewireBase}/${episodeLink}`);
const title = await _title.text();
const embeds = await getStreams(title);
return {
embeds,
};
}
console.log(await scrapeShow("tt4574334", 1, 1));
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 10, 2024