-
Notifications
You must be signed in to change notification settings - Fork 102
/
invidious.io.js
72 lines (63 loc) · 1.6 KB
/
invidious.io.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
// ==MiruExtension==
// @name Invidious
// @version v0.0.2
// @author OshekharO
// @lang all
// @license MIT
// @icon https://invidious.io/apple-touch-icon.png
// @package invidious.io
// @type bangumi
// @webSite https://vid.puffyan.us/api/v1
// ==/MiruExtension==
export default class extends Extension {
async latest() {
const res = await this.request(`/trending?region=US`);
if (!Array.isArray(res)) {
// Handle the case when the response is not an array
return [];
}
return res.map((item) => ({
title: item.title || "",
url: item.videoId || "",
cover: item.videoThumbnails?.[0]?.url || "", // Use the first thumbnail's URL if available
}));
}
async search(kw) {
const res = await this.request(`/search?q=${kw}`);
return res.map((item) => ({
title: item.title || "",
url: item.videoId || "",
cover: item.videoThumbnails?.[0]?.url || "",
}));
}
async detail(url) {
const res = await this.request(`/videos/${url}`, {
headers: {
"Miru-Url": "https://vid.puffyan.us/api/v1",
},
});
return {
title: res.title,
cover: res.videoThumbnails?.[0]?.url,
desc: res.description,
episodes: [
{
title: "Watch",
urls: [
{
name: res.title,
url: res.videoId,
},
],
},
],
};
}
async watch(url) {
const res = await this.request(`/videos/${url}`);
return {
type: "hls",
url: res.formatStreams?.[1]?.url,
};
}
}