feat: return comment count in getDetails()

This commit is contained in:
luan.lrt4@gmail.com
2022-03-21 22:39:41 -03:00
parent 23ab8bca4d
commit de6283080b

View File

@@ -207,7 +207,10 @@ class Parser {
items
}
}
/**
* Video data is parsed dynamically, so if youtube decides to add something new we won't have to change anything here.
*/
#parseVideoInfo() {
const desktop_v = this.args.desktop_v;
@@ -215,7 +218,7 @@ class Parser {
this.data[2].playerResponse.playabilityStatus;
if (playability_status.status == 'ERROR')
throw new Error(`Could not retrieve details for this video: ${playability_status.status} - ${playability_status.reason}`);
throw new Error(`Could not retrieve video details: ${playability_status.status} - ${playability_status.reason}`);
const details = desktop_v && this.data.videoDetails ||
this.data[2].playerResponse.videoDetails;
@@ -225,7 +228,7 @@ class Parser {
const streaming_data = desktop_v && this.data.streamingData ||
this.data[2].playerResponse.streamingData;
const response = {
id: '',
title: '',
@@ -236,7 +239,8 @@ class Parser {
const mf_raw_data = Object.entries(microformat);
const dt_raw_data = Object.entries(details);
// Extracts most of the metadata
mf_raw_data.forEach((entry) => {
const key = Utils.camelToSnake(entry[0]);
if (Constants.METADATA_KEYS.includes(key)) {
@@ -248,7 +252,8 @@ class Parser {
response[key] = entry[1];
}
});
// Extracts extra details
dt_raw_data.forEach((entry) => {
const key = Utils.camelToSnake(entry[0]);
if (Constants.BLACKLISTED_KEYS.includes(key)) return;
@@ -262,19 +267,14 @@ class Parser {
(response[key] = entry[1]);
}
});
if (!desktop_v) {
const dislike_available = this.data[3].response.contents.singleColumnWatchNextResults.results.results.contents[1]
.slimVideoMetadataSectionRenderer.contents[1].slimVideoActionBarRenderer.buttons[1].slimMetadataToggleButtonRenderer
.button.toggleButtonRenderer.defaultText.accessibility && true || false;
response.metadata.likes = parseInt(this.data[3].response.contents.singleColumnWatchNextResults.results.results.contents[1]
response.metadata.likes = parseInt((this.data[3].response.contents.singleColumnWatchNextResults.results.results.contents[1]
.slimVideoMetadataSectionRenderer.contents[1].slimVideoActionBarRenderer.buttons[0].slimMetadataToggleButtonRenderer
.button.toggleButtonRenderer.defaultText.accessibility.accessibilityData.label.replace(/\D/g, ''));
response.metadata.dislikes = dislike_available && parseInt(this.data[3].response.contents.singleColumnWatchNextResults.results.results.contents[1]
.slimVideoMetadataSectionRenderer.contents[1].slimVideoActionBarRenderer.buttons[1].slimMetadataToggleButtonRenderer
.button.toggleButtonRenderer.defaultText.accessibility.accessibilityData.label.replace(/\D/g, '')) || 0;
.button.toggleButtonRenderer.defaultText.accessibility?.accessibilityData.label || '0').replace(/\D/g, ''));
response.metadata.comment_count = this.data[3].response.engagementPanels[1]?.engagementPanelSectionListRenderer.header
.engagementPanelTitleHeaderRenderer.contextualInfo.runs[0].text || 'N/A';
}
streaming_data.adaptiveFormats &&