mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-18 20:12:12 +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
35 lines
1.6 KiB
JavaScript
35 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const Constants = require('../../../utils/Constants');
|
|
|
|
class GridVideoItem {
|
|
static parse(data) {
|
|
return data.map((item) => this.parseItem(item)).filter((item) => item);
|
|
}
|
|
|
|
static parseItem(item) {
|
|
return {
|
|
id: item.gridVideoRenderer.videoId,
|
|
title: item?.gridVideoRenderer?.title?.runs?.map((run) => run.text).join(' '),
|
|
channel: {
|
|
id: item?.gridVideoRenderer?.shortBylineText?.runs[0]?.navigationEndpoint?.browseEndpoint?.browseId,
|
|
name: item?.gridVideoRenderer?.shortBylineText?.runs[0]?.text || 'N/A',
|
|
url: `${Constants.URLS.YT_BASE}${item?.gridVideoRenderer?.shortBylineText?.runs[0]?.navigationEndpoint?.browseEndpoint?.canonicalBaseUrl}`
|
|
},
|
|
metadata: {
|
|
view_count: item?.gridVideoRenderer?.viewCountText?.simpleText || 'N/A',
|
|
short_view_count_text: {
|
|
simple_text: item?.gridVideoRenderer?.shortViewCountText?.simpleText || 'N/A',
|
|
accessibility_label: item?.gridVideoRenderer?.shortViewCountText?.accessibility?.accessibilityData?.label || 'N/A'
|
|
},
|
|
thumbnail: item?.gridVideoRenderer?.thumbnail?.thumbnails.slice(-1)[0] || [],
|
|
moving_thumbnail: item?.gridVideoRenderer?.richThumbnail?.movingThumbnailRenderer?.movingThumbnailDetails?.thumbnails[0] || {},
|
|
published: item?.gridVideoRenderer?.publishedTimeText?.simpleText || 'N/A',
|
|
badges: item?.gridVideoRenderer?.badges?.map((badge) => badge.metadataBadgeRenderer.label) || [],
|
|
owner_badges: item?.gridVideoRenderer?.ownerBadges?.map((badge) => badge.metadataBadgeRenderer.tooltip) || []
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = GridVideoItem; |