ytdl-core
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -175,9 +175,16 @@ const utils = require('./utils'); | ||
* | ||
* @param {string} body | ||
* @return {number} | ||
* @param {string} info | ||
* @returns {number} | ||
*/ | ||
const getLikesRegex = /"label":"([\d,]+?) likes"/; | ||
exports.getLikes = body => { | ||
const likes = body.match(getLikesRegex); | ||
return likes ? parseInt(likes[1].replace(/,/g, '')) : null; | ||
exports.getLikes = info => { | ||
try { | ||
let contents = info.response.contents.twoColumnWatchNextResults.results.results.contents; | ||
let video = contents.find(r => r.videoPrimaryInfoRenderer); | ||
let buttons = video.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons; | ||
let like = buttons.find(b => b.toggleButtonRenderer && | ||
b.toggleButtonRenderer.defaultIcon.iconType === 'LIKE'); | ||
return parseInt(like.toggleButtonRenderer.defaultText.accessibility.accessibilityData.label.replace(/\D+/g, '')); | ||
} catch (err) { | ||
return null; | ||
} | ||
}; | ||
@@ -188,9 +195,16 @@ | ||
* | ||
* @param {string} body | ||
* @return {number} | ||
* @param {string} info | ||
* @returns {number} | ||
*/ | ||
const getDislikesRegex = /"label":"([\d,]+?) dislikes"/; | ||
exports.getDislikes = body => { | ||
const dislikes = body.match(getDislikesRegex); | ||
return dislikes ? parseInt(dislikes[1].replace(/,/g, '')) : null; | ||
exports.getDislikes = info => { | ||
try { | ||
let contents = info.response.contents.twoColumnWatchNextResults.results.results.contents; | ||
let video = contents.find(r => r.videoPrimaryInfoRenderer); | ||
let buttons = video.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons; | ||
let dislike = buttons.find(b => b.toggleButtonRenderer && | ||
b.toggleButtonRenderer.defaultIcon.iconType === 'DISLIKE'); | ||
return parseInt(dislike.toggleButtonRenderer.defaultText.accessibility.accessibilityData.label.replace(/\D+/g, '')); | ||
} catch (err) { | ||
return null; | ||
} | ||
}; |
@@ -34,3 +34,3 @@ const urllib = require('url'); | ||
exports.getBasicInfo = async(id, options) => { | ||
let [info, body] = await getJSONWatchPage(id, options); | ||
let info = await getJSONWatchPage(id, options); | ||
let player_response = | ||
@@ -78,4 +78,4 @@ (info.player && info.player.args && info.player.args.player_response) || | ||
media: extras.getMedia(info), | ||
likes: extras.getLikes(body), | ||
dislikes: extras.getDislikes(body), | ||
likes: extras.getLikes(info), | ||
dislikes: extras.getDislikes(info), | ||
age_restricted, | ||
@@ -121,5 +121,6 @@ | ||
const getHTML5player = body => { | ||
let html5playerRes = /<script\s+src="([^"]+)"(\s+type="text\/javascript")?\s+name="player_ias\/base"\s*>/ | ||
.exec(body); | ||
return html5playerRes ? html5playerRes[1] : null; | ||
let html5playerRes = | ||
/<script\s+src="([^"]+)"(?:\s+type="text\/javascript")?\s+name="player_ias\/base"\s*>|"jsUrl":"([^"]+)"/ | ||
.exec(body); | ||
return html5playerRes ? html5playerRes[1] || html5playerRes[2] : null; | ||
}; | ||
@@ -189,3 +190,3 @@ | ||
let info = parsedBody.reduce((part, curr) => Object.assign(curr, part), {}); | ||
return [info, body]; | ||
return info; | ||
}; | ||
@@ -192,0 +193,0 @@ |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"repository": { | ||
@@ -12,0 +12,0 @@ "type": "git", |
@@ -7,6 +7,15 @@ declare module 'ytdl-core' { | ||
type Filter = 'audioandvideo' | 'videoandaudio' | 'video' | 'videoonly' | 'audio' | 'audioonly' | ((format: videoFormat) => boolean); | ||
interface downloadOptions { | ||
interface getInfoOptions { | ||
lang?: string; | ||
requestOptions?: {}; | ||
} | ||
interface chooseFormatOptions { | ||
quality?: 'lowest' | 'highest' | 'highestaudio' | 'lowestaudio' | 'highestvideo' | 'lowestvideo' | string | number | string[] | number[]; | ||
filter?: Filter; | ||
format?: videoFormat; | ||
} | ||
interface downloadOptions extends getInfoOptions, chooseFormatOptions { | ||
range?: { | ||
@@ -18,5 +27,3 @@ start?: number; | ||
liveBuffer?: number; | ||
requestOptions?: {}; | ||
highWaterMark?: number; | ||
lang?: string; | ||
dlChunkSize?: number; | ||
@@ -353,6 +360,6 @@ } | ||
function getBasicInfo(url: string, options?: downloadOptions): Promise<videoInfo>; | ||
function getInfo(url: string, options?: downloadOptions): Promise<videoInfo>; | ||
function getBasicInfo(url: string, options?: getInfoOptions): Promise<videoInfo>; | ||
function getInfo(url: string, options?: getInfoOptions): Promise<videoInfo>; | ||
function downloadFromInfo(info: videoInfo, options?: downloadOptions): Readable; | ||
function chooseFormat(format: videoFormat | videoFormat[], options?: downloadOptions): videoFormat | never; | ||
function chooseFormat(format: videoFormat | videoFormat[], options?: chooseFormatOptions): videoFormat | never; | ||
function filterFormats(formats: videoFormat | videoFormat[], filter?: Filter): videoFormat[]; | ||
@@ -359,0 +366,0 @@ function validateID(string: string): boolean; |
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
79622
2153