Node-RED Flow Youtube示例
大约 3 分钟
Node-RED Flow Youtube示例
Node-RED 是创建这些应用程序的理想软件解决方案。 它既可以作为独立程序使用,也可以作为Home Assistant和ioBroker的插件使用,使您可以进一步增强AWTRIX Light系统的功能。
这是一个演示,请按三角形展开。
将Youtube应用程序添加为NodeRED Flow的示例
[
{
"id": "2a59d30d07abe14f",
"type": "group",
"z": "54b42d8d.cda474",
"style": {
"stroke": "#999999",
"stroke-opacity": "1",
"fill": "none",
"fill-opacity": "1",
"label": true,
"label-position": "nw",
"color": "#a4a4a4"
},
"nodes": [
"f0f17299.3736c",
"dc7878f9.4756c8",
"f234aae371d72680",
"555bb8624b88c9c3",
"69c388146e28049d",
"a349ade5a57f7537"
],
"x": 34,
"y": 39,
"w": 892,
"h": 122
},
{
"id": "f0f17299.3736c",
"type": "inject",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "",
"props": [],
"repeat": "3600",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 120,
"wires": [
[
"a349ade5a57f7537"
]
]
},
{
"id": "dc7878f9.4756c8",
"type": "http request",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "query",
"url": "https://youtube.googleapis.com/youtube/v3/channels",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 430,
"y": 120,
"wires": [
[
"f234aae371d72680"
]
]
},
{
"id": "f234aae371d72680",
"type": "function",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "parser",
"func": "var json = msg.payload;\nvar subscriberCount = json.items[0].statistics.subscriberCount;\n\nmsg.payload = { \"text\": subscriberCount, \"icon\": 5029};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 590,
"y": 120,
"wires": [
[
"555bb8624b88c9c3"
]
]
},
{
"id": "555bb8624b88c9c3",
"type": "mqtt out",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "",
"topic": "ulanzi/custom/youtube",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "346df2a95aac5785",
"x": 800,
"y": 120,
"wires": []
},
{
"id": "69c388146e28049d",
"type": "comment",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "Youtube Follower",
"info": "Just enter your channelID and Youtube API key in the \"Data\" node and set your AWTRIX MQTT prefix.\nUses Icon 5029 (LM)",
"x": 140,
"y": 80,
"wires": []
},
{
"id": "a349ade5a57f7537",
"type": "function",
"z": "54b42d8d.cda474",
"g": "2a59d30d07abe14f",
"name": "Data",
"func": "msg.payload = { \"id\": \"UCpGLALzRO0uaasWTsm9M99w\", \"key\": \"XXX\", \"part\":\"statistics\"}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 120,
"wires": [
[
"dc7878f9.4756c8"
]
]
},
{
"id": "346df2a95aac5785",
"type": "mqtt-broker",
"name": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
Node-RED Flow检索并显示指定YouTube频道的订阅者计数。该Flow由以下节点组成:
- Inject: 这个Node定期(每小时)或手动触发Flow。
- Data (Function): 这个Node包含YouTube channel ID和YouTube API Key。将“XXX”替换为你的 YouTube API Key和 Youtube ID。The node constructs a payload containing the channel ID, API key, and required statistics and sends it to the "HTTP request" node. 该节点构造一个包含通道 ID、API 密钥和所需统计信息的有效负载,并将其发送到“HTTP 请求”节点。
- HTTP request: 这个Node向YouTube API发送 GET 请求以检索频道的统计信息。 The response is returned as a JavaScript object and passed to the "parser" node. 响应作为JavaScript对象返回并传递给“解析器”节点。
- parser (Function): This node extracts the subscriber count from the received channel statistics and constructs a payload containing the count and an icon (Icon 5029). The payload is sent to the "MQTT out" node. 此节点从接收到的信道统计信息中提取用户计数,并构造包含计数和图标(图标 5029)的有效负载。有效负载被发送到 “MQTT out” 节点。
- MQTT out: 该节点将负载发布到本地MQTT服务器上的MQTT主题“ulanzi/custom/youtube”。需要修改此节点中的主题来适配你的mqtt前缀。
- Comment (Youtube Follower): 此节点包含有关流的其他信息。它不会影响流的功能。
要使用此流程,请将“Data”节点中的“XXX”替换为您的 YouTube API 密钥,并确保“MQTT out”节点中的 MQTT 代理设置正确。
然后,该流程将检索指定 YouTube 频道的订阅者数量,并将其与图标一起显示在您的 AWTRIX 设备上。此流程使用 LM 中的图标 5029(只需从 awtrix Web 界面下载即可)。您可以将Flow中的图标改为您喜欢的图标。