2.1.0 • Published 6 months ago

yt-notifier v2.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

YouTube Notify

An npm package that run codes when a specified channel publishes a video.

Summary

  1. Installation.
  2. Use.
  3. Change Logs.
  4. Documentation.
  5. Extensions.

Installation

npm install yt-notifier
yarn add yt-notifier

Use

const { Notify } = require("yt-notifier");
const notify = new Notify({
  apiKey: "Your youtube ApiKey",
});

notify.on("ready", async () => {
  const id = await notify.getChannelId("https://www.youtube.com/@example"); // Youtube channel url

  // Create the listener
  await notify.createListener({ channelId: id });
});

// Event for when the video is published
notify.on("newVideo", (items) => {
  console.log(items);
});

Change Logs

v2.0.4: (last-release)

  • Added the files for the yarn page.
  • Fixed a problem with the listener.

Documentation

Inizialization

const { Notify } = require("yt-notifier");
const notify = new Notify({
  apiKey: "Your youtube ApiKey",
});

Functions

The functions that can be used with this package.

getChannelId()

Gets the channel id from url delete event.

Use

const channelId = await notify.getChannelId("https://www.youtube.com/@example");

Returns

channelId

createListener()

Creates a listener and active create, when the listener is create, and newVideo, when the specified channel upload a video, events.

Use

await notify.createListener({ channelId: id });

stopListener()

Stops a listener and active delete event.

Use

await notify.stopListener({ channelId: id });

Events

The events that can be actived.



This event is only active when instance is ready.

Use

notify.on('ready', (i) => {
  ...
});

Returns

currentInstance

Example

const { Notify } = require("yt-notifier");
const notify = new Notify({
  apiKey: "Your youtube ApiKey",
});

notify.on("ready", async (i) => {
  console.log(i);
});


This event is activated when a new listener is created.

Use

notify.on('create', (channelId, id) => {
  ...
});

Returns

channelId, currentInstance

Example

const { Notify } = require('yt-notifier');
const notify = new Notify({
   apiKey: "Your youtube ApiKey"
});

...

notify.on('create', (channelId, i) => {
  console.log(channelId);
});


This event is activated when a listener is deleted.

Use

notify.on('delete', (channelId, i) => {
  ...
});

Returns

channelId, currentInstance

Example

const { Notify } = require('yt-notifier');
const notify = new Notify({
   apiKey: "Your youtube ApiKey"
});

...

notify.on('delete', (channelId, i) => {
  console.log(channelId);
});


This event is activated when a cahnnel publish a new video.

Use

notify.on('newVideo', (items) => {
  ...
});

Returns

{
  id: '{videoId}',
  title: '{videoTitle}',
  description: '{videoDescription}',
  link: '<videoUrl>',
  releaed: '<releaseDate>',
  thumbnails: {
    default: '<thumbnailUrl>',
    medium: '<thumbnailUrl>',
    high: '<thumbnailUrl>',
    standard: '<thumbnailUrl>',
    maxres: '<thumbnailUrl>',
  },
  statistics: {
    viewCount: '<viewsNumber>',
    likeCount: '<likeCount>',
    favoriteCount: '<favoriteCount>',
    commentCount: '<commentsNumber>'
  },
  author: {
    link: '<channelUrl>',
    name: '<channelName>',
    description: '<channelDescription>',
    avatars: {
      default: '<avatarUrl>'
      medium: '<avatarUrl>',
      high: '<avatarUrl>',
    },
    statistics: {
      subscribers: '<subscribersCount>',
      videoCount: '<videoCount>',
      views: '<viewsNumber>',
    },
  },
}

Example

const { Notify } = require('yt-notifier');
const notify = new Notify({
   apiKey: "Your youtube ApiKey"
});

...

notify.on('newVideo', (items) => {
  console.log(items);
});

Extensions

Twitch

Use

const { Notify, TwitchExtension } = require("yt-notify");
const notify = new Notify({
  apiKey: "Your youtube ApiKey",
  extensions: {
    twitch: new TwitchExtension({
      clientId: "Twitch client id",
      token: "Twitch token id",
    }),
  },
});
const twitch = notify.twitch;

Function

createListener()

Creates a listener and active create, when the listener is create, and newVideo, when the specified channel upload a video, events.

Use
await twitch.createListener({ channel: channelName });

stopListener()

Stops a listener and active delete event.

Use
await twitch.stopListener({ channel: channelName });

Events

The events that can be actived with this extension.



This event is only active when instance is ready.

Use

twitch.on('ready', (i) => {
  ...
});

Returns

currentInstance

Example

const { Notify, TwitchExtension } = require("yt-notify");
const notify = new Notify({
  apiKey: "Your youtube ApiKey",
  extensions: {
    twitch: new TwitchExtension({
      clientId: "Twitch client id",
      token: "Twitch token id",
    }),
  },
});
const twitch = notify.twitch;

twitch.on("ready", async (i) => {
  console.log(i);
});


This event is activated when a new listener is created.

Use

twitch.on('create', (channelId, id) => {
  ...
});

Returns

{
   id: '<channelId>',
   login: '<channelUsername>',
   display_name: '<channelName>',
   broadcaster_type: '<brodcastType>',
   description: '<channelDescription>',
   profile_image_url: '<profileImage>',
   offline_image_url: '<offlineImage>',
   view_count: <viewCount>,
   created_at: '<creationTime>'
},
currentInstance

Example

const { Notify, TwitchExtension } = require("yt-notify");
const notify = new Notify({
   apiKey: "Your youtube ApiKey",
   extensions: {
      twitch: new TwitchExtension({
         clientId: "Twitch client id",
         token: "Twitch token id",
      })
   }
});
const twitch = notify.twitch;

...

twitch.on('create', (streamerInfo, i) => {
  console.log(streamerInfo);
});


This event is activated when a listener is deleted.

Use

twitch.on('delete', (streamerInfo, i) => {
  ...
});

Returns

{
   id: '<channelId>',
   login: '<channelUsername>',
   display_name: '<channelName>',
   broadcaster_type: '<brodcastType>',
   description: '<channelDescription>',
   profile_image_url: '<profileImage>',
   offline_image_url: '<offlineImage>',
   view_count: <viewCount>,
   created_at: '<creationTime>'
}
currentInstance

Example

const { Notify, TwitchExtension } = require("yt-notify");
const notify = new Notify({
   apiKey: "Your youtube ApiKey",
   extensions: {
      twitch: new TwitchExtension({
         clientId: "Twitch client id",
         token: "Twitch token id",
      })
   }
});
const twitch = notify.twitch;

...

twitch.on('delete', (streamerInfo, i) => {
  console.log(streamerInfo);
});


This event is activated when a streamer start a new live.

Use

twitch.on('isLive', (items) => {
  ...
});

Returns

{
  id: '<id>',
  user_id: '<userId>',
  user_login: '<username>',
  user_name: '<channelName>',
  game_id: '<gameId>',
  game_name: '<gameName>',
  type: '<type>',
  title: '<liveTitle>',
  viewer_count: <viewerCount>,
  started_at: '<startedTime>',
  language: '<lenguage>',
  thumbnail_url: '<thumbnailUrl>',
  tag_ids: <arrayOfTagsId>,
  tags: <arrayOfTags>,
  is_mature: false
}

Example

const { Notify, TwitchExtension } = require("yt-notify");
const notify = new Notify({
   apiKey: "Your youtube ApiKey",
   extensions: {
      twitch: new TwitchExtension({
         clientId: "Twitch client id",
         token: "Twitch token id",
      })
   }
});
const twitch = notify.twitch;

...

twitch.on('isLive', (items) => {
  console.log(items);
});

2.1.0

6 months ago

2.0.4

6 months ago

2.0.3

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago