@livecord/notify
Advanced tools
| const { YouTube } = require('../src/index'); | ||
| const youtube = new YouTube({ | ||
| channels: [ 'UCaZGQt419Ptsdk_lh2mz9lQ', 'UCna9_me1UQAu3zbxv-dIhCQ' ], // Array of channels (required) | ||
| postedVideos: [ "" ], // Array of videos that have been posted (optional) | ||
| interval: 1000 // check channels every 1000ms (1 second) (optional) (default: 60000 [60 seconds])]) | ||
| interval: 1000, // check channels every 1000ms (1 second) (optional) (default: 60000 [60 seconds])]) | ||
| useDatabase: true // use database to store videos (optional) (default: true) | ||
| }); | ||
@@ -7,0 +7,0 @@ |
+1
-1
| { | ||
| "name": "@livecord/notify", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "Notifier for Youtube and Twitch.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
+2
-1
@@ -60,3 +60,4 @@ # [@livecord/notify](https://npmjs.com/package/@livecord/notify) | ||
| channels: [ '' ], // Array of channel ids (required) | ||
| interval: 1000 // check channels every 1000ms (1 second) (optional) (default: 60000 [60 seconds])]) | ||
| interval: 1000, // check channels every 1000ms (1 second) (optional) (default: 60000 [60 seconds])]) | ||
| useDatabase: true // use database to store videos (optional) (default: true) | ||
| }); | ||
@@ -63,0 +64,0 @@ |
+21
-14
@@ -8,3 +8,3 @@ const EventEmitter = require('events'); | ||
| module.exports = class LivecordYoutube extends EventEmitter { | ||
| constructor({ postedVideos = [], channels, interval = 60000 }) { | ||
| constructor({ postedVideos = [], channels, interval = 60000, useDatabase = true }) { | ||
| super(); | ||
@@ -15,2 +15,3 @@ | ||
| if (interval && typeof interval !== 'number') throw new Error('LivecordYoutube: interval must be a number'); | ||
| if (useDatabase && typeof useDatabase !== 'boolean') throw new Error('LivecordYoutube: useDatabase must be a boolean'); | ||
| if (!channels) throw new Error('LivecordYoutube: You must provide a list of channels.'); | ||
@@ -31,5 +32,7 @@ if (!Array.isArray(channels)) throw new Error('LivecordYoutube: channels must be an array'); | ||
| this.ws.on('open', () => { | ||
| JSON.parse(fs.readFileSync('videos.json')).forEach(video => { | ||
| if(!this.postedVideos.includes(video)) this.postedVideos.push(video); | ||
| }); | ||
| if (useDatabase) { | ||
| JSON.parse(fs.readFileSync('videos.json')).forEach(video => { | ||
| if (!this.postedVideos.includes(video)) this.postedVideos.push(video); | ||
| }); | ||
| } | ||
| this.emit('ready', Date.now()); | ||
@@ -41,14 +44,18 @@ setInterval(() => { | ||
| let $ = data.items[0]; | ||
| if(postedVideos.includes($.id)) return; | ||
| if(!fs.existsSync('videos.json')) { | ||
| fs.writeFileSync('videos.json', JSON.stringify([$.id])); | ||
| if (useDatabase) { | ||
| if (postedVideos.includes($.id)) return; | ||
| if (!fs.existsSync('videos.json')) { | ||
| fs.writeFileSync('videos.json', JSON.stringify([$.id])); | ||
| } else { | ||
| fs.writeFileSync('videos.json', JSON.stringify([ | ||
| ...JSON.parse(fs.readFileSync('videos.json')), | ||
| $.id | ||
| ])); | ||
| } | ||
| this.postedVideos.push($.id); | ||
| return this.emit('upload', $); | ||
| } else { | ||
| fs.writeFileSync('videos.json', JSON.stringify([ | ||
| ...JSON.parse(fs.readFileSync('videos.json')), | ||
| $.id | ||
| ])); | ||
| return this.emit('upload', $); | ||
| } | ||
| this.postedVideos.push($.id); | ||
| return this.emit('upload', $); | ||
| }).catch(() => {}); | ||
| }).catch(() => { }); | ||
| }) | ||
@@ -55,0 +62,0 @@ }, interval || 60000); |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
10661
5.17%159
4.61%74
1.37%