Anforderungen
- nodejs 20.0 (oder neuer)
- js-controller 6.0.11 (oder neuer)
- Admin Adapter 7.6.17 (oder neuer)
Konfiguration
Um einen API-Key zu erstellen, gehe zu console.developers.google.com.
- Erstelle ein neues Projekt
- Erstelle einen neuen API Schlüssel
- Füge "YouTube Data API v3" aus der Bibliothek hinzu
- Nutze diesen API-Key in den Instanz-Einstellungen
- Füge einen oder mehrere YouTube-Kanäle über das "Kanäle"-Tab im Admin hinzu
Statistiken aller Kanäle in InfluxDB speichern
// v0.3
const targetDb = 'influxdb.0';
const currentInstance = `javascript.${instance}`;
async function storeToDb(ts, prefix, subscriberCount, viewCount) {
await this.sendToAsync(targetDb, 'storeState', {
id: `youtube.0.${prefix}.subscribers`,
state: {
ts,
val: subscriberCount,
ack: true,
from: `system.adapter.${currentInstance}.${scriptName}`,
}
});
await this.sendToAsync(targetDb, 'storeState', {
id: `youtube.0.${prefix}.views`,
state: {
ts,
val: viewCount,
ack: true,
from: `system.adapter.${currentInstance}.${scriptName}`,
}
});
}
// Save all channels
on({ id: 'youtube.0.summary.json', change: 'any' }, async (obj) => {
try {
const youtubeJson = obj.state.val;
const channels = JSON.parse(youtubeJson);
const ts = Date.now();
for (const channel of channels) {
const alias = channel.customUrl.substr(1); // remove leading @
await storeToDb(ts, `channels.${alias}`, channel.subscriberCount, channel.viewCount);
}
} catch (err) {
console.error(err);
}
});
// Save channels by group
$('youtube.0.groups.*.json').on(async (obj) => {
try {
const group = obj.id.slice('youtube.0.groups.'.length, '.json'.length * -1);
const youtubeJson = obj.state.val;
const channels = JSON.parse(youtubeJson);
const ts = Date.now();
for (const channel of channels) {
const alias = channel.customUrl.substr(1); // remove leading @
await storeToDb(ts, `groups.${group}.${alias}`, channel.subscriberCount, channel.viewCount);
}
} catch (err) {
console.error(err);
}
});
Changelog
7.0.0 (2026-05-05)
- (copilot) Adapter requires node.js >= 22 now
- (@klein0r) admin 7.6.20 and js-controller 6.0.11 (or later) are required
6.1.0 (2025-12-11)
- (@klein0r) Update channel icons every week
- (@klein0r) admin 7.6.17 and js-controller 6.0.11 (or later) are required
- (@klein0r) Updated dependencies
6.0.0 (2025-03-16)
NodeJS >= 20.x and js-controller >= 6 is required
5.1.1 (2024-11-12)
- (@klein0r) Added video list (yesterday)
5.1.0 (2024-11-11)
- (klein0r) Added groups
- (klein0r) Added icons of channels to object list
License
The MIT License (MIT)
Copyright (c) 2026 Matthias Kleine info@haus-automatisierung.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.