Readme

what is this?

这是一个用来检测主播是否直播,访问方法为:https://api.val.town/v1/run/nishui.biliStream?args=[xxx] 其中 args=[id] 中的 id 是直播房间号码

现在是多参数 ?args=[[xxx]]

因为不了解 js、TypeScript 语言,决定还是不使用传送过来的参数了,用自定义的列表 id 来每隔 15m 自动获取是否直播,最后打包总结果返回 email

Runs every 15 min
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
import { fetch } from "https://esm.town/v/std/fetch";
import { email } from "https://esm.town/v/std/email?v=9";
import { set } from "https://esm.town/v/std/set?v=11";
import { bilibili_data } from "https://esm.town/v/nishui/bilibili_data";
export const biliStream = async (
idArraysss: string[] = [],
): Promise<string> => {
try {
let result = "";
const requests = [];
// use ref stream = $me.bilibili_data.stream_data
// const { stream_data : stream } = $me.bilibili_data;
// ++@me.bilibili_data.hits;
let stream_data = bilibili_data.stream_data;
// console.email(idArray);
// console.email("idArray length:", idArray.length);
// if (idArray.length === 0 || idArray == undefined || idArray == null) {
// console.email("why?");
// idArray = Object.keys(stream_data);
// }
// console.email("before id");
const idArray = Object.keys(stream_data);
for (let i = 0; i < idArray.length; i++) {
const id = idArray[i];
const request = fetch(
`https://api.live.bilibili.com/room/v1/Room/room_init?id=${id}`,
).then((data) => data.json());
requests.push(request);
}
const responses = await Promise.all(requests);
// console.email("after response");
for (let i = 0; i < idArray.length; i++) {
const id = idArray[i];
const jsonData = responses[i];
if (jsonData["data"]["live_status"] === 1) {
if (stream_data[id]["status"] === 0) {
stream_data[id]["status"] = 1;
result += `<p>bili直播 ${stream_data[id]["name"]} 开始了 in ${id}</p>\n`;
}
}
else {
if (stream_data[id]["status"] === 1) {
stream_data[id]["status"] = 0;
result += `<p>bili下播 ${stream_data[id]["name"]} in ${id}</p>\n`;
}
}
}
await set("bilibili_data", bilibili_data);
if (result !== "") {
await email({ text: result });
return result;
}
}
catch (error) {
await email({ text: "Error:" + error });
return "ERROR";
}
};
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!
October 23, 2023