-
Notifications
You must be signed in to change notification settings - Fork 105
/
gogo.anime.js
92 lines (85 loc) · 2.21 KB
/
gogo.anime.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
// ==MiruExtension==
// @name GoGoAnime
// @version v0.0.6
// @author OshekharO
// @lang en
// @license MIT
// @icon https://play-lh.googleusercontent.com/MaGEiAEhNHAJXcXKzqTNgxqRmhuKB1rCUgb15UrN_mWUNRnLpO5T1qja64oRasO7mn0
// @package gogo.anime
// @type bangumi
// @webSite https://public-miruro-consumet-api.vercel.app/anime/gogoanime
// ==/MiruExtension==
export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("gogoApi"),
},
});
}
async load() {
this.registerSetting({
title: "GoGo API",
key: "gogoApi",
type: "input",
description: "API URL",
defaultValue: "https://public-miruro-consumet-api.vercel.app/anime/gogoanime",
});
this.registerSetting({
title: "Preferred quality",
key: "prefQuality",
type: "input",
description: "Choose between 360p/480p/720p/1080p",
defaultValue: "480p",
});
}
async latest(page) {
const res = await this.req(`/top-airing?page=${page}`);
return res.results.map((item) => ({
title: item.title,
url: item.id,
cover: item.image,
}));
}
async detail(url) {
const res = await this.req(`/info/${url}`);
return {
title: res.title,
cover: res.image,
desc: res.description,
episodes: [
{
title: "Ep",
urls: res.episodes.map((item) => ({
name: `Episode ${item.number}`,
url: item.id,
})),
},
],
};
}
async search(kw, page) {
const res = await this.req(`/${kw}?page=${page}`);
return res.results.map((item) => ({
title: item.title,
url: item.id,
cover: item.image,
}));
}
async watch(url) {
const quality = await this.getSetting("prefQuality");
const res = await this.req(`/watch/${url}?server=gogocdn`);
const prefQuality = res.sources.find(source => source.quality === quality);
if (prefQuality) {
return {
type: "hls",
url: prefQuality.url,
};
} else {
return {
type: "hls",
url: res.sources.pop().url,
};
}
}
}