mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 14:38:07 +00:00
* feat: add core comments section classes * chore: update type declarations * chore: fix linter warnings * style: fix linter * chore: update tests * chore(tests): fix typo * chore(tests): fix typo x2 * fix(tests): `getReplies()` method is only present in `CommentThread` and not `Comment` * chore(tests): fix comment id path * chore(tests): remove outdated code * chore(tests): fix results path * chore: enforce code style * chore: update type declarations * docs: add examples and documentation * chore(docs): fix paths * chore(docs): fix more paths * chore(docs): fix `Comments.js` path * chore(docs): fix typo * chore(docs): mention example file * chore(examples): fix imports * chore(examples): fix typo
44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const Utils = require('../../../utils/Utils');
|
|
const Constants = require('../../../utils/Constants');
|
|
|
|
class VideoResultItem {
|
|
static parse(data) {
|
|
return data.map((item) => this.parseItem(item)).filter((item) => item);
|
|
}
|
|
|
|
static parseItem(item) {
|
|
const renderer = item.videoRenderer || item.compactVideoRenderer;
|
|
if (renderer) return {
|
|
id: renderer.videoId,
|
|
url: `https://youtu.be/${renderer.videoId}`,
|
|
title: renderer.title.runs[0].text,
|
|
description: renderer?.detailedMetadataSnippets ? renderer?.detailedMetadataSnippets[0].snippetText.runs.map((item) => item.text).join('') : 'N/A',
|
|
channel: {
|
|
id: renderer?.ownerText?.runs[0]?.navigationEndpoint?.browseEndpoint?.browseId,
|
|
name: renderer?.ownerText?.runs[0]?.text,
|
|
url: `${Constants.URLS.YT_BASE}${renderer?.ownerText?.runs[0].navigationEndpoint?.browseEndpoint?.canonicalBaseUrl}`
|
|
},
|
|
metadata: {
|
|
view_count: renderer?.viewCountText?.simpleText || 'N/A',
|
|
short_view_count_text: {
|
|
simple_text: renderer?.shortViewCountText?.simpleText || 'N/A',
|
|
accessibility_label: renderer?.shortViewCountText?.accessibility?.accessibilityData?.label || 'N/A'
|
|
},
|
|
thumbnails: renderer?.thumbnail.thumbnails,
|
|
duration: {
|
|
seconds: Utils.timeToSeconds(renderer?.lengthText?.simpleText || '0'),
|
|
simple_text: renderer?.lengthText?.simpleText || 'N/A',
|
|
accessibility_label: renderer?.lengthText?.accessibility?.accessibilityData?.label || 'N/A'
|
|
},
|
|
published: renderer?.publishedTimeText?.simpleText || 'N/A',
|
|
badges: renderer?.badges?.map((item) => item.metadataBadgeRenderer.label) || [],
|
|
owner_badges: renderer?.ownerBadges?.map((item) => item.metadataBadgeRenderer.tooltip) || []
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = VideoResultItem;
|