simple-youtube-api
Advanced tools
Comparing version 4.0.0 to 5.0.0
{ | ||
"name": "simple-youtube-api", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "A module to simplify the YouTube API.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -35,3 +35,3 @@ const fetch = require('node-fetch'); | ||
return this.make(Constants.ENDPOINTS[type], qs).then(result => | ||
result.items.length ? result.items[0] : Promise.reject(new Error('resource not found')) | ||
result.items.length ? result.items[0] : Promise.reject(new Error(`resource ${result.kind} not found`)) | ||
); | ||
@@ -38,0 +38,0 @@ } |
@@ -53,3 +53,3 @@ const { parseURL } = require('../util'); | ||
* This channel's title | ||
* @type {string} | ||
* @type {?string} | ||
* @name Channel#title | ||
@@ -86,2 +86,7 @@ */ | ||
/** | ||
* Fetch the full representation of this channel. | ||
* @param {object} [options] Any extra query params | ||
* @returns {Channel} | ||
*/ | ||
fetch(options) { | ||
@@ -105,5 +110,3 @@ return this.youtube.request.getChannel(this.id, options).then(this._patch.bind(this)); | ||
static extractID(url) { | ||
const parsed = parseURL(url); | ||
if (!parsed || parsed.type !== 'channel') return null; | ||
return parsed.id; | ||
return parseURL(url).channel; | ||
} | ||
@@ -110,0 +113,0 @@ } |
@@ -43,3 +43,3 @@ const { parseURL } = require('../util'); | ||
* @type {string} | ||
* @name id | ||
* @name Playlist#id | ||
*/ | ||
@@ -83,2 +83,10 @@ | ||
if (data.status) { | ||
/** | ||
* The privacy status of this video. | ||
* @type {string} | ||
*/ | ||
this.privacy = data.status.privacyStatus; | ||
} | ||
/** | ||
@@ -99,2 +107,7 @@ * The channel this playlist is in | ||
/** | ||
* Fetch the full representation of this playlist. | ||
* @param {object} [options] Any extra query params | ||
* @returns {Playlist} | ||
*/ | ||
fetch(options) { | ||
@@ -124,5 +137,3 @@ return this.youtube.request.getPlaylist(this.id, options).then(this._patch.bind(this)); | ||
static extractID(url) { | ||
const parsed = parseURL(url); | ||
if (!parsed || parsed.type !== 'playlist') return null; | ||
return parsed.id; | ||
return parseURL(url).playlist; | ||
} | ||
@@ -129,0 +140,0 @@ } |
@@ -54,3 +54,3 @@ const duration = require('iso8601-duration'); | ||
* @type {string} | ||
* @name id | ||
* @name Video#id | ||
*/ | ||
@@ -131,4 +131,4 @@ | ||
/** | ||
* The maxiumum available resolution thumbnail URL. | ||
* @type {string} | ||
* The maxiumum available resolution thumbnail. | ||
* @type {object} | ||
*/ | ||
@@ -164,2 +164,7 @@ get maxRes() { | ||
/** | ||
* Fetch the full representation of this video. | ||
* @param {object} [options] Any extra query params | ||
* @returns {Video} | ||
*/ | ||
fetch(options) { | ||
@@ -175,5 +180,3 @@ return this.youtube.request.getVideo(this.id, options).then(this._patch.bind(this)); | ||
static extractID(url) { | ||
const parsed = parseURL(url); | ||
if (!parsed || parsed.type !== 'video') return null; | ||
return parsed.id; | ||
return parseURL(url).video; | ||
} | ||
@@ -180,0 +183,0 @@ } |
@@ -5,3 +5,3 @@ exports.PARTS = { | ||
Playlists: 'snippet', | ||
PlaylistItems: 'snippet,contentDetails', | ||
PlaylistItems: 'snippet,status', | ||
Channels: 'snippet' | ||
@@ -8,0 +8,0 @@ }; |
@@ -6,3 +6,3 @@ const { parse } = require('url'); | ||
* @param {string} url | ||
* @returns {?{type: string, id: string}} | ||
* @returns {{video: ?string, channel: ?string, playlist: ?string}} | ||
*/ | ||
@@ -17,29 +17,23 @@ exports.parseURL = (url) => { | ||
if (parsed.pathname === '/watch') { | ||
if (!idRegex.test(parsed.query.v)) return null; | ||
if (!idRegex.test(parsed.query.v)) return {}; | ||
return { | ||
type: 'video', | ||
id: parsed.query.v | ||
video: parsed.query.v, | ||
playlist: parsed.query.list || null, | ||
}; | ||
} else if (parsed.pathname === '/playlist') { | ||
if(!idRegex.test(parsed.query.list)) return null; | ||
return { | ||
type: 'playlist', | ||
id: parsed.query.list | ||
}; | ||
if(!idRegex.test(parsed.query.list)) return {}; | ||
return { playlist: parsed.query.list }; | ||
} else if (parsed.pathname.startsWith('/channel/')) { | ||
const id = parsed.pathname.replace('/channel/', ''); | ||
if (!idRegex.test(id)) return null; | ||
return { | ||
type: 'channel', | ||
id | ||
}; | ||
if (!idRegex.test(id)) return {}; | ||
return { channel: id }; | ||
} | ||
return null; | ||
return {}; | ||
} | ||
case 'youtu.be': | ||
return /\/^[a-zA-Z0-9-_]+$/.test(parsed.pathname) ? { type: 'video', id: parsed.pathname.slice(1) } : null; | ||
return { video: /^\/[a-zA-Z0-9-_]+$/.test(parsed.pathname) ? parsed.pathname.slice(1) : null }; | ||
default: | ||
return null; | ||
return {}; | ||
} | ||
}; |
@@ -13,12 +13,23 @@ /* globals describe, it, before */ | ||
assert.deepEqual(parsed, { | ||
type: 'video', | ||
id: 'zBBOfCRhEz4' | ||
video: 'zBBOfCRhEz4', | ||
playlist: null, | ||
channel: null, | ||
}); | ||
}); | ||
it('can parse a video and playlist URL', function() { | ||
const parsed = YouTube.util.parseURL('https://www.youtube.com/watch?v=MLB8tSA2GFA&list=PLe8jmEHFkvsbeJL2QNucGv00eO8PKbSUn'); | ||
assert.deepEqual(parsed, { | ||
video: 'MLB8tSA2GFA', | ||
playlist: 'PLe8jmEHFkvsbeJL2QNucGv00eO8PKbSUn', | ||
channel: null, | ||
}); | ||
}); | ||
it('can parse a playlist URL', function() { | ||
const parsed = YouTube.util.parseURL('https://www.youtube.com/playlist?list=PLe8jmEHFkvsbRwwi0ode5c9iMQ2dyJU3N'); | ||
assert.deepEqual(parsed, { | ||
type: 'playlist', | ||
id: 'PLe8jmEHFkvsbRwwi0ode5c9iMQ2dyJU3N' | ||
playlist: 'PLe8jmEHFkvsbRwwi0ode5c9iMQ2dyJU3N', | ||
video: null, | ||
channel: null, | ||
}); | ||
@@ -30,4 +41,5 @@ }); | ||
assert.deepEqual(parsed, { | ||
type: 'channel', | ||
id: 'UCJ6td3C9QlPO9O_J5dF4ZzA' | ||
channel:'UCJ6td3C9QlPO9O_J5dF4ZzA', | ||
video: null, | ||
playlist: null, | ||
}); | ||
@@ -122,2 +134,3 @@ }); | ||
it('fetches each full video', function() { | ||
this.timeout(5000); | ||
return Promise.all(playlist.videos.map(v => { | ||
@@ -124,0 +137,0 @@ if (v.full) return assert.fail('full video already loaded'); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39180
988
1