-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathstreams-by-game.mjs
69 lines (67 loc) · 1.43 KB
/
streams-by-game.mjs
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
import common from "../common-polling.mjs";
import twitch from "../../twitch.app.mjs";
export default {
...common,
name: "New Streams By Game",
key: "twitch-streams-by-game",
description: "Emit new event when a live stream starts from any stream matching the game and language specified.",
version: "0.0.3",
type: "source",
props: {
...common.props,
game: {
propDefinition: [
twitch,
"game",
],
},
language: {
propDefinition: [
twitch,
"language",
],
},
max: {
propDefinition: [
twitch,
"max",
],
},
},
methods: {
...common.methods,
getMeta({
id,
title: summary,
started_at: startedAt,
}) {
const ts = new Date(startedAt).getTime();
return {
id: `${id}${ts}`,
summary,
ts,
};
},
},
async run() {
const { data: gameData } = await this.twitch.getGames([
this.game,
]);
if (gameData.length == 0) {
console.log(`No game found with the name ${this.game}`);
return;
}
// get and emit streams for the specified game & language
const streams = await this.paginate(
this.twitch.getStreams.bind(this),
{
game_id: gameData[0].id,
language: this.language,
},
this.max,
);
for await (const stream of streams) {
this.$emit(stream, this.getMeta(stream));
}
},
};