Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
fix: address reelPlayerHeaderRenderer when undefined (#189)
Browse files Browse the repository at this point in the history
* fix: address reelPlayerHeaderRenderer when undefined

* fix: pass lint checks

* fix: undefined error for some shorts

* add typings + test + simplify parseItems for shorts

---------

Co-authored-by: Tobias Kutscha <t.kutscha@yahoo.de>
  • Loading branch information
reply2za and TimeForANinja authored Apr 14, 2023
1 parent db760fd commit d03b4c2
Show file tree
Hide file tree
Showing 5 changed files with 8,132 additions and 11 deletions.
22 changes: 13 additions & 9 deletions lib/parseItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,27 +353,31 @@ const parseMovie = obj => {
};

const parseShort = obj => {
const playerHeader = obj.navigationEndpoint.reelWatchEndpoint.overlay
.reelPlayerOverlayRenderer.reelPlayerHeaderSupportedRenderers.reelPlayerHeaderRenderer;
const channelNavEndpoint = playerHeader.channelTitleText.runs[0].navigationEndpoint;
return {
const core = {
type: 'short',
title: UTIL.parseText(obj.headline, ''),
videoID: obj.videoId,
url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),
bestThumbnail: prepImg(obj.thumbnail.thumbnails)[0],
thumbnails: prepImg(obj.thumbnail.thumbnails),
views: UTIL.parseText(obj.viewCountText, ''),
published: UTIL.parseText(playerHeader.timestampText, ''),

channel: {
published: null,
channel: null,
};
const reelPlayerOverlayRenderer = obj.navigationEndpoint.reelWatchEndpoint.overlay.reelPlayerOverlayRenderer;
if (reelPlayerOverlayRenderer.reelPlayerHeaderSupportedRenderers) {
const playerHeader = reelPlayerOverlayRenderer.reelPlayerHeaderSupportedRenderers.reelPlayerHeaderRenderer;
const channelNavEndpoint = playerHeader.channelTitleText.runs[0].navigationEndpoint;
core.published = UTIL.parseText(playerHeader.timestampText, '');
core.channel = {
name: UTIL.parseText(playerHeader.channelTitleText, ''),
channelID: channelNavEndpoint.browseEndpoint.browseId,
url: new URL(channelNavEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),
bestAvatar: prepImg(playerHeader.channelThumbnail.thumbnails)[0] || null,
avatars: prepImg(playerHeader.channelThumbnail.thumbnails),
},
};
};
}
return core;
};

const parseShow = obj => {
Expand Down
2 changes: 1 addition & 1 deletion test/typeFiles/chipCloudRenderer_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@
}
}
}
}
}
Loading

0 comments on commit d03b4c2

Please sign in to comment.