-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathclient.js
121 lines (95 loc) · 3.62 KB
/
client.js
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
window.addEventListener("load", async () => {
console.log("Loaded");
const loading = document.getElementById("loading");
const loaded = document.getElementById("loaded");
const error = document.getElementById("error");
const video = document.getElementById("video");
const size = document.getElementById("size");
const resolution = document.getElementById("resolution");
const duration = document.getElementById("duration");
const errorMsg = document.getElementById("errorMsg");
const title = document.getElementById("title");
const downloadButton = document.getElementById("downloadButton");
const copyButton = document.getElementById("copyButton");
const reloadButton = document.getElementById("reloadButton");
reloadButton.addEventListener("click", () => {
window.location.reload();
});
const urlParams = new URLSearchParams(window.location.search);
const url = urlParams.get("url");
if (!url) showError("URL not found");
const getData = await getUrl(url);
if (!getData.success) {
showError(getData.error);
} else {
loading.classList.remove("flex");
loading.classList.add("hidden");
loaded.classList.remove("hidden");
loaded.classList.add("flex");
video.src = getData.playUrl;
video.poster = getData.poster;
size.innerText = getData.size;
title.innerText = getData.title;
video.addEventListener("loadedmetadata", () => {
resolution.innerText = video.videoWidth + "x" + video.videoHeight;
duration.innerText = video.duration + "s";
});
downloadButton.addEventListener("click", () => {
window.open(getData.url, "_blank");
});
copyButton.addEventListener("click", () => {
navigator.clipboard.writeText(getData.url);
alert("Copied to clipboard");
});
}
function showError(msg) {
loading.classList.add("hidden");
error.classList.remove("hidden");
error.classList.add("flex");
errorMsg.innerText = msg;
}
});
async function getUrl(url = "") {
try {
const parsedUrl = new URL(url);
const response = await fetch(parsedUrl.href);
const html = await response.text();
const urlRegex =
/document\.getElementById\('norobotlink'\)\.innerHTML = (.*);/;
const urlMatch = html.match(urlRegex);
if (!urlMatch) throw new Error("norobotlink url not found");
const tokenRegex = /token=([^&']+)/;
const tokenMatch = urlMatch[1].match(tokenRegex);
if (!tokenMatch) throw new Error("token not found");
// <div id="ideoooolink" style="display:none;">take all</div>
const fullUrlRegex =
/<div id="ideoooolink" style="display:none;">(.*)<[/]div>/;
const fullUrlMatch = html.match(fullUrlRegex);
if (!fullUrlMatch) throw new Error("ideoooolink url not found");
let finalUrl = fullUrlMatch[1].split(parsedUrl.hostname)[1];
finalUrl = `https://${parsedUrl.hostname}${finalUrl}&token=${tokenMatch[1]}`;
const sizeRegex = /<p class="subheading">(.*)<[/]p>/;
const sizeMatch = html.match(sizeRegex);
const titleRegex = /<meta name="og:title" content="(.*)">/;
const titleMatch = html.match(titleRegex);
const posterRegex = /<meta name="og:image" content="(.*)">/;
const posterMatch = html.match(posterRegex);
return {
success: true,
url: finalUrl + "&dl=1",
playUrl: finalUrl,
size: sizeMatch ? sizeMatch[1] : "Unknown",
title: titleMatch ? fixTitle(titleMatch[1]) : "Streamtape Extension",
poster: posterMatch ? posterMatch[1] : "",
};
} catch (error) {
return {
success: false,
error: error.message,
};
}
}
function fixTitle(str = "") {
let all = str.split(".");
return all[0];
}