simple-youtube-api
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "simple-youtube-api", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A module to simplify the YouTube API.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,3 @@ # Simple YouTube API | ||
## Usage | ||
- [Documentation](https://Hyper-Coder.github.io/simple-youtube-api/2.0.0/) | ||
- [Documentation](https://Hyper-Coder.github.io/simple-youtube-api/2.1.0/) | ||
- [Examples](https://github.com/Hyper-Coder/simple-youtube-api/tree/master/examples) |
@@ -0,1 +1,3 @@ | ||
const parseURL = require('url').parse; | ||
/** Represents a YouTube channel */ | ||
@@ -35,4 +37,16 @@ class Channel { | ||
} | ||
/** | ||
* Get a channel ID from a string (URL or ID) | ||
* @param {string} url The string to get the ID from | ||
* @returns {?string} | ||
*/ | ||
static extractID(url) { | ||
const parsed = parseURL(url, true); | ||
const s = parsed.pathname.split('/'); | ||
const id = s[s.length - 1]; | ||
return id || null; | ||
} | ||
} | ||
module.exports = Channel; |
@@ -0,1 +1,2 @@ | ||
const parseURL = require('url').parse; | ||
const Constants = require('../Constants'); | ||
@@ -74,4 +75,19 @@ const Video = require('./Video'); | ||
} | ||
/** | ||
* Get a playlist ID from a string (URL or ID) | ||
* @param {string} url The string to get the ID from | ||
* @returns {?string} | ||
*/ | ||
static extractID(url) { | ||
const parsed = parseURL(url, true); | ||
let id = parsed.query.list; | ||
if (!id) { | ||
const s = parsed.pathname.split('/'); | ||
id = s[s.length - 1]; | ||
} | ||
return id || null; | ||
} | ||
} | ||
module.exports = Playlist; |
@@ -0,1 +1,2 @@ | ||
const parseURL = require('url').parse; | ||
const duration = require('iso8601-duration'); | ||
@@ -73,2 +74,10 @@ const Channel = require('./Channel'); | ||
get url() { | ||
return `https://www.youtube.com/watch?v=${this.id}`; | ||
} | ||
/** | ||
* The short URL to this video | ||
* @type {string} | ||
*/ | ||
get shortURL() { | ||
return `https://youtu.be/${this.id}`; | ||
@@ -84,4 +93,19 @@ } | ||
} | ||
/** | ||
* Get a video ID from a string (URL or ID) | ||
* @param {string} url The string to get the ID from | ||
* @returns {?string} | ||
*/ | ||
static extractID(url) { | ||
const parsed = parseURL(url, true); | ||
let id = parsed.query.v; | ||
if (parsed.hostname === 'youtu.be' || !id) { | ||
const s = parsed.pathname.split('/'); | ||
id = s[s.length - 1]; | ||
} | ||
return id || null; | ||
} | ||
} | ||
module.exports = Video; |
const request = require('request'); | ||
const parseURL = require('url').parse; | ||
const Constants = require('./Constants'); | ||
@@ -53,8 +52,3 @@ const Encode = require('./util/Encode'); | ||
getVideo(url) { | ||
const parsed = parseURL(url, true); | ||
let id = parsed.query.v; | ||
if (parsed.hostname === 'youtu.be' || !id) { | ||
const s = parsed.pathname.split('/'); | ||
id = s[s.length - 1]; | ||
} | ||
const id = Video.extractID(url); | ||
if (!id) return Promise.reject(new Error(`No video ID found in URL: ${url}`)); | ||
@@ -97,8 +91,3 @@ return this.getVideoByID(id); | ||
getPlaylist(url) { | ||
const parsed = parseURL(url, true); | ||
let id = parsed.query.list; | ||
if (!id) { | ||
const s = parsed.pathname.split('/'); | ||
id = s[s.length - 1]; | ||
} | ||
const id = Playlist.extractID(url); | ||
if (!id) return Promise.reject(new Error(`No playlist ID found in URL: ${url}`)); | ||
@@ -141,5 +130,3 @@ return this.getPlaylistByID(id); | ||
getChannel(url) { | ||
const parsed = parseURL(url, true); | ||
const s = parsed.pathname.split('/'); | ||
let id = s[s.length - 1]; | ||
const id = Channel.extractID(url); | ||
if (!id) return Promise.reject(new Error(`No channel ID found in URL: ${url}`)); | ||
@@ -146,0 +133,0 @@ return this.getChannelByID(id); |
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
20344
534
0