Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ const main = module.exports = async(linkOrId, options, rt = 3) => {
};

// Parse videos
const rawVideoList = parsed.json.contents
const playlistVideoListRenderer = parsed.json.contents
.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
.sectionListRenderer.contents[0]
.itemSectionRenderer.contents[0]
.playlistVideoListRenderer.contents;
.playlistVideoListRenderer;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use optional chaining here but that requires node v14.5.0 or above, so I used the ternary operator to be compatible with node v8. I do recommend you bump node to v14.5.0 or above because v8 is EOL and v12 is going to EOL next year

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With optional chaining the updated code should look like this

const rawVideoList = parsed.json.contents
    .twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
    .sectionListRenderer.contents[0]
    .itemSectionRenderer.contents[0]
    .playlistVideoListRenderer?.contents;

if (rawVideoList === undefined) throw new Error('Playlist is empty');

Copy link
Copy Markdown
Author

@Hazmi35 Hazmi35 Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current changes, it would be like this with optional chaining

const playlistVideoListRenderer = parsed.json.contents
    .twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
    .sectionListRenderer.contents[0]
    .itemSectionRenderer.contents[0]
    .playlistVideoListRenderer?.contents ?? [];


const rawVideoList = playlistVideoListRenderer ? playlistVideoListRenderer.contents : [];

resp.items = rawVideoList.map(PARSE_ITEM).filter(a => a).filter((_, index) => index < opts.limit);

// Adjust tracker
Expand Down