ytdl-core
Advanced tools
Comparing version 4.1.6 to 4.1.7
@@ -31,2 +31,9 @@ const { setTimeout } = require('timers'); | ||
this.set(key, value); | ||
(async() => { | ||
try { | ||
await value; | ||
} catch (err) { | ||
this.delete(key); | ||
} | ||
})(); | ||
return value; | ||
@@ -33,0 +40,0 @@ } |
@@ -57,4 +57,4 @@ const urllib = require('url'); | ||
let info = await pipeline([id, options], validate, retryOptions, [ | ||
getWatchHTMLPage, | ||
getWatchJSONPage, | ||
getWatchHTMLPage, | ||
getVideoInfoPage, | ||
@@ -113,5 +113,5 @@ ]); | ||
const getHTMLWatchURL = (id, options) => `${VIDEO_URL + id}&hl=${options.lang || 'en'}`; | ||
const getHTMLWatchPageBody = (id, options) => { | ||
const url = getHTMLWatchURL(id, options); | ||
const getWatchHTMLURL = (id, options) => `${VIDEO_URL + id}&hl=${options.lang || 'en'}`; | ||
const getWatchHTMLPageBody = (id, options) => { | ||
const url = getWatchHTMLURL(id, options); | ||
return exports.watchPageCache.getOrSet(url, () => miniget(url, options.requestOptions).text()); | ||
@@ -121,2 +121,9 @@ }; | ||
const EMBED_URL = 'https://www.youtube.com/embed/'; | ||
const getEmbedPageBody = (id, options) => { | ||
const embedUrl = `${EMBED_URL + id}?hl=${options.lang || 'en'}`; | ||
return miniget(embedUrl, options.requestOptions).text(); | ||
}; | ||
const getHTML5player = body => { | ||
@@ -132,3 +139,3 @@ let html5playerRes = | ||
exports.cookieCache.getOrSet(key, async() => { | ||
let page = await getHTMLWatchPageBody(id, options); | ||
let page = await getWatchHTMLPageBody(id, options); | ||
let match = page.match(/(["'])ID_TOKEN\1[:,]\s?"([^"]+)"/); | ||
@@ -260,3 +267,3 @@ if (!match && throwIfNotFound) { | ||
const getWatchJSONURL = (id, options) => `${getHTMLWatchURL(id, options)}&pbj=1`; | ||
const getWatchJSONURL = (id, options) => `${getWatchHTMLURL(id, options)}&pbj=1`; | ||
const getWatchJSONPage = async(id, options) => { | ||
@@ -298,3 +305,3 @@ const reqOptions = Object.assign({ headers: {} }, options.requestOptions); | ||
const getWatchHTMLPage = async(id, options) => { | ||
let body = await getHTMLWatchPageBody(id, options); | ||
let body = await getWatchHTMLPageBody(id, options); | ||
let info = { page: 'watch' }; | ||
@@ -368,3 +375,4 @@ try { | ||
if (info.formats.length) { | ||
info.html5player = info.html5player || getHTML5player(await getHTMLWatchPageBody(id, options)); | ||
info.html5player = info.html5player || | ||
getHTML5player(await getWatchHTMLPageBody(id, options)) || getHTML5player(await getEmbedPageBody(id, options)); | ||
if (!info.html5player) { | ||
@@ -371,0 +379,0 @@ throw Error('Unable to find html5player file'); |
@@ -144,6 +144,7 @@ const miniget = require('miniget'); | ||
// Check for updates. | ||
const { version } = require('../package.json'); | ||
const package = require('../package.json'); | ||
exports.lastUpdateCheck = 0; | ||
exports.checkForUpdates = () => { | ||
if (!process.env.YTDL_NO_UPDATE && Date.now() - exports.lastUpdateCheck >= 1000 * 60 * 60 * 12) { | ||
if (!process.env.YTDL_NO_UPDATE && !package.version.startsWith('0.0.0-') && | ||
Date.now() - exports.lastUpdateCheck >= 1000 * 60 * 60 * 12) { | ||
exports.lastUpdateCheck = Date.now(); | ||
@@ -153,3 +154,3 @@ return miniget('https://api.github.com/repos/fent/node-ytdl-core/releases/latest', { | ||
}).text().then(response => { | ||
if (JSON.parse(response).tag_name !== `v${version}`) { | ||
if (JSON.parse(response).tag_name !== `v${package.version}`) { | ||
console.warn('\x1b[33mWARNING:\x1B[0m ytdl-core is out of date! Update with "npm install ytdl-core@latest".'); | ||
@@ -156,0 +157,0 @@ } |
{ | ||
"name": "ytdl-core", | ||
"description": "Youtube video downloader in pure javascript.", | ||
"description": "YouTube video downloader in pure javascript.", | ||
"keywords": [ | ||
@@ -9,3 +9,3 @@ "youtube", | ||
], | ||
"version": "4.1.6", | ||
"version": "4.1.7", | ||
"repository": { | ||
@@ -12,0 +12,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86856
2330