YouTube

Статистика, такая как просмотры, подписчики и видео

Текущий релиз
7.0.0
Разработчик
Matthias Kleine
Лицензия
MIT

Требования

  • Node.js 20.0 (или более поздняя версия)
  • js-controller 6.0.11 (или более поздняя версия)
  • Адаптер администратора 7.6.17 (или более поздняя версия)

Конфигурация

Чтобы получить API-ключ, вам нужно перейти по ссылке console.developers.google.com.

  1. Создайте новый проект.
  2. Создайте новый ключ API.
  3. Добавьте "YouTube Data API v3" в библиотеку.
  4. Используйте этот API-ключ в конфигурации экземпляра.
  5. Добавьте несколько каналов на вкладке «Каналы», используя идентификатор и пользовательское имя.

Записывайте всю статистику в InfluxDB

// 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

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

5.0.0 (2024-04-03)

NodeJS >= 18.x and js-controller >= 5 is required

  • (klein0r) Better way to get channel id by alias

License

The MIT License (MIT)

Copyright (c) 2025-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.