Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-youtube-api

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-youtube-api - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

9

out/entities/Channel.js

@@ -54,7 +54,8 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
if (this.data.contentDetails) {
const videos = yield this.youtube.getPlaylist(this.data.contentDetails.relatedPlaylists.uploads);
this.videos = videos;
return videos;
if (!(this.data.contentDetails)) {
yield this.fetch();
}
const videos = yield this.youtube.getPlaylist(this.data.contentDetails.relatedPlaylists.uploads);
this.videos = videos;
return videos;
});

@@ -61,0 +62,0 @@ }

@@ -24,5 +24,5 @@ "use strict";

this.id = video.id;
this.length = video.contentDetails.duration;
this.minutes = parseInt(this.length.substring(this.length.indexOf('PT') + 2, this.length.indexOf('M')));
this.seconds = parseInt(this.length.substring(this.length.indexOf('M') + 1, this.length.length - 1));
this._length = video.contentDetails.duration;
this.minutes = parseInt(this._length.substring(this._length.indexOf('PT') + 2, this._length.indexOf('M')));
this.seconds = parseInt(this._length.substring(this._length.indexOf('M') + 1, this._length.length - 1));
}

@@ -29,0 +29,0 @@ else if (data.kind === 'youtube#playlistItem') {

@@ -53,8 +53,2 @@ import { youtube_v3 } from "googleapis"

/**
* Gets the 50 latest videos from a channel.
* @param id The ID of the channel.
*/
public getChannelVideos(id: string): Promise<Video[]>
/**
* Get a playlist object from the ID of a playlist.

@@ -79,6 +73,7 @@ * @param id The url of the playlist.

/**
* Get every single video in a playlist. Used mostly internally with `Playlist#getVideos`.
* Get `maxResults` videos in a playlist. Used mostly internally with `Playlist#getVideos`.
* @param playlistId The ID of the playlist.
* @param maxResults The maximum amount of videos to get from the playlist. If <= 0 or not included, returns all videos in the playlist.
*/
public getPlaylistItems(playlistId: string): Promise<Video[]>
public getPlaylistItems(playlistId: string, maxResults?: number): Promise<Video[]>
}

@@ -136,17 +131,8 @@

/**
* The length of the video. The tag value is an ISO 8601 duration in the format PT#M#S,
* in which the letters PT indicate that the value specifies a period of time, and the letters
* M and S refer to length in minutes and seconds, respectively. The # characters preceding the
* M and S letters are both integers that specify the number of minutes (or seconds) of the video.
* For example, a value of PT15M51S indicates that the video is 15 minutes and 51 seconds long.
* The minutes of the video.
*/
public length: string
/**
* The length of the video in minutes.
*/
public minutes: number
/**
* The length of the video in seconds.
* The seconds of the video.
*/

@@ -153,0 +139,0 @@ public seconds: number

@@ -17,3 +17,2 @@ "use strict";

const util_1 = require("./util");
const axios_1 = require("axios");
__export(require("./entities"));

@@ -40,3 +39,3 @@ const youtube = googleapis_1.google.youtube('v3');

if (maxResults < 1 || maxResults > 50) {
return Promise.reject('Max results must be greater than 0 and less or equal to 50.');
return Promise.reject('Max results must be greater than 0 and less than or equal to 50.');
}

@@ -106,3 +105,3 @@ const { data: results } = yield youtube.search.list({

if (maxResults < 1 || maxResults > 50) {
return Promise.reject('Max results must be greater than 0 and less or equal to 50.');
return Promise.reject('Max results must be greater than 0 and less than or equal to 50.');
}

@@ -165,19 +164,2 @@ const { data: results } = yield youtube.search.list({

/**
* Gets the 50 latest videos from a channel.
* @param id The ID of the channel.
*/
getChannelVideos(id) {
return __awaiter(this, void 0, void 0, function* () {
let videos = [];
const { data: results } = yield axios_1.default.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${id}&order=date&key=${this.token}&maxResults=50`);
if (results.items.length === 0) {
return Promise.reject('Channel not found/has no videos.');
}
for (let i = 0; i < results.items.length; i++) {
videos.push(new entities_1.Video(this, results.items[i]));
}
return videos;
});
}
/**
* Get a playlist object from the ID of a playlist.

@@ -249,5 +231,4 @@ * @param id The url of the playlist.

* Get `maxResults` videos in a playlist. Used mostly internally with `Playlist#getVideos`.
* If <= 0 or not included, returns all videos in the playlist.
* @param playlistId The ID of the playlist.
* @param maxResults The maximum amount of videos to get from the playlist.
* @param maxResults The maximum amount of videos to get from the playlist. If <= 0 or not included, returns all videos in the playlist.
*/

@@ -254,0 +235,0 @@ getPlaylistItems(playlistId, maxResults = -1) {

{
"name": "better-youtube-api",
"version": "0.0.8",
"version": "0.0.9",
"description": "Better than simple ones.",

@@ -5,0 +5,0 @@ "main": "out/index.js",

# Better YouTube API
Want to access data from the YouTube Data v3 API? No problem! We've got ya covered.
# Examples
First of all, I recommend that you check out `out/index.d.ts` for all of the methods and what they return. Here are some basic methods:
Instantiate the object:
```js
const YouTube = require('better-youtube-api').YouTube
const youtube = new YouTube(apiKey)
```
Get a video by ID:
```js
const video = await youtube.getVideo('dQw4w9WgXcQ')
console.log(video)
```
Get a video by URL:
```js
const video = await youtube.getVideoByUrl('https://youtube.com/watch?v=dQw4w9WgXcQ')
console.log(video)
```
You can do the same thing with playlists and channels by replacing `Video` with either one.

@@ -122,9 +122,11 @@ import { YouTube } from '..'

public async getVideos () {
if ((this.data as youtube_v3.Schema$Channel).contentDetails) {
const videos = await this.youtube.getPlaylist((this.data as youtube_v3.Schema$Channel).contentDetails.relatedPlaylists.uploads)
this.videos = videos
if (!((this.data as youtube_v3.Schema$Channel).contentDetails)) {
await this.fetch()
}
return videos
}
const videos = await this.youtube.getPlaylist((this.data as youtube_v3.Schema$Channel).contentDetails.relatedPlaylists.uploads)
this.videos = videos
return videos
}
}

@@ -53,13 +53,6 @@ import { YouTube } from '..'

/**
* The length of the video. The tag value is an ISO 8601 duration in the format PT#M#S,
* in which the letters PT indicate that the value specifies a period of time, and the letters
* M and S refer to length in minutes and seconds, respectively. The # characters preceding the
* M and S letters are both integers that specify the number of minutes (or seconds) of the video.
* For example, a value of PT15M51S indicates that the video is 15 minutes and 51 seconds long.
*/
public length: string
private _length: string
/**
* The length of the video in minutes.
* The minutes of the video.
*/

@@ -69,3 +62,3 @@ public minutes: number

/**
* The length of the video in seconds.
* The seconds of the video.
*/

@@ -96,5 +89,5 @@ public seconds: number

this.id = video.id
this.length = video.contentDetails.duration
this.minutes = parseInt(this.length.substring(this.length.indexOf('PT') + 2, this.length.indexOf('M')))
this.seconds = parseInt(this.length.substring(this.length.indexOf('M') + 1, this.length.length - 1))
this._length = video.contentDetails.duration
this.minutes = parseInt(this._length.substring(this._length.indexOf('PT') + 2, this._length.indexOf('M')))
this.seconds = parseInt(this._length.substring(this._length.indexOf('M') + 1, this._length.length - 1))
} else if (data.kind === 'youtube#playlistItem') {

@@ -101,0 +94,0 @@ this.id = (data.snippet as youtube_v3.Schema$PlaylistItemSnippet).resourceId.videoId

@@ -30,3 +30,3 @@ import { google, youtube_v3 } from 'googleapis'

if (maxResults < 1 || maxResults > 50) {
return Promise.reject('Max results must be greater than 0 and less or equal to 50.')
return Promise.reject('Max results must be greater than 0 and less than or equal to 50.')
}

@@ -104,3 +104,3 @@

if (maxResults < 1 || maxResults > 50) {
return Promise.reject('Max results must be greater than 0 and less or equal to 50.')
return Promise.reject('Max results must be greater than 0 and less than or equal to 50.')
}

@@ -172,21 +172,2 @@

/**
* Gets the 50 latest videos from a channel.
* @param id The ID of the channel.
*/
public async getChannelVideos (id: string) {
let videos: Video[] = []
const { data: results } = await axios.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${id}&order=date&key=${this.token}&maxResults=50`)
if (results.items.length === 0) {
return Promise.reject('Channel not found/has no videos.')
}
for (let i = 0; i < results.items.length; i++) {
videos.push(new Video(this, results.items[i]))
}
return videos
}
/**
* Get a playlist object from the ID of a playlist.

@@ -266,5 +247,4 @@ * @param id The url of the playlist.

* Get `maxResults` videos in a playlist. Used mostly internally with `Playlist#getVideos`.
* If <= 0 or not included, returns all videos in the playlist.
* @param playlistId The ID of the playlist.
* @param maxResults The maximum amount of videos to get from the playlist.
* @param maxResults The maximum amount of videos to get from the playlist. If <= 0 or not included, returns all videos in the playlist.
*/

@@ -271,0 +251,0 @@ public async getPlaylistItems (playlistId: string, maxResults: number = -1) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc